Skip to content

Commit 86a2a26

Browse files
committed
Minimize diff in ScipTaskListener
1 parent 2a5e12d commit 86a2a26

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

‎scip-javac/src/main/java/org/scip_code/scip_java/javac/ScipTaskListener.java‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,12 @@ public static Path absolutePathFromUri(ScipJavacOptions options, JavaFileObject
179179
// Infers the `-sourceroot:` flag from the provided file.
180180
private void inferBazelSourceroot(JavaFileObject file) {
181181
if (options.uriScheme != UriScheme.BAZEL || options.sourceroot != null) return;
182-
options.sourceroot =
183-
inferBazelSourceroot(absolutePathFromUri(options, file), Paths.get(file.toUri()));
184-
}
185-
186-
// absolutePath is the "human-readable" original path, e.g. /home/repo/com/example/Hello.java.
187-
// uriPath is the sandbox/temporary file path, e.g. /private/var/tmp/com/example/Hello.java.
188-
// Infer sourceroot by iterating the names of both files in reverse order and stopping at
189-
// the first entry where the two paths differ.
190-
private static Path inferBazelSourceroot(Path absolutePath, Path uriPath) {
182+
Path absolutePath = absolutePathFromUri(options, file);
183+
Path uriPath = Paths.get(file.toUri());
184+
// absolutePath is the "human-readable" original path, e.g. /home/repo/com/example/Hello.java.
185+
// uriPath is the sandbox/temporary file path, e.g. /private/var/tmp/com/example/Hello.java.
186+
// Infer sourceroot by iterating the names of both files in reverse order and stopping at
187+
// the first entry where the two paths differ.
191188
int relativePathDepth = 0;
192189
int uriPathDepth = uriPath.getNameCount();
193190
int absolutePathDepth = absolutePath.getNameCount();
@@ -201,11 +198,13 @@ private static Path inferBazelSourceroot(Path absolutePath, Path uriPath) {
201198
// Every name of absolutePath is a suffix of uriPath (for example, when both paths are
202199
// identical because the file object's toString() didn't match a known Bazel pattern).
203200
// There is no prefix left to use as the sourceroot, so fall back to the filesystem root.
204-
return absolutePath.getRoot();
201+
options.sourceroot = absolutePath.getRoot();
202+
return;
205203
}
206-
return absolutePath
207-
.getRoot()
208-
.resolve(absolutePath.subpath(0, absolutePathDepth - relativePathDepth));
204+
options.sourceroot =
205+
absolutePath
206+
.getRoot()
207+
.resolve(absolutePath.subpath(0, absolutePathDepth - relativePathDepth));
209208
}
210209

211210
private Result<Path, String> scipShardOutputPath(TaskEvent e) {

0 commit comments

Comments
 (0)