Skip to content

Commit 3b15114

Browse files
authored
Support running aspect in Bazel Sandbox (#824)
1 parent 4c64db8 commit 3b15114

3 files changed

Lines changed: 6 additions & 22 deletions

File tree

‎docs/getting-started.md‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,6 @@ The `--bazel-scip-java-binary` argument is required due to implementation
309309
details, scip-java runs an [aspect](https://bazel.build/extending/aspects) that
310310
requires the absolute path to the `scip-java` binary.
311311

312-
> The current solution for automatic indexing step is not yet 100% hermetic and,
313-
> therefore, relies on `--spawn_strategy=local` under the hood. Depending on
314-
> your use-case, this might be OK or not. If there is demand for it, it's should
315-
> be possible to make the indexing fully hermetic and compatible with Bazel's
316-
> sandbox with some extra work.
317-
318312
#### Manual - `select`
319313

320314
It's possible to index Bazel codebases by integrating scip-java directly into

‎scip-java/src/main/kotlin/org/scip_code/scip_java/buildtools/BazelBuildTool.kt‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,9 @@ class BazelBuildTool(index: IndexCommand) : BuildTool("Bazel", index) {
6565
bazelExecutable,
6666
"build",
6767
"--noshow_progress",
68-
// The local strategy is required for now because we write
69-
// SCIP and SCIP files to the provided targetroot directory.
70-
"--spawn_strategy=local",
7168
"--aspects",
7269
"$aspectLabel%scip_java_aspect",
7370
"--output_groups=scip",
74-
"--define=sourceroot=${index.workingDirectory}",
7571
"--define=java_home=$javaHome",
7672
"--define=scip_java_binary=$scipJavaBinary",
7773
"--verbose_failures",

‎scip-java/src/main/resources/scip-java/scip_java.bzl‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ many *.scip (https://github.com/scip-code/scip) files.
1313
These files encode information about which symbols are referenced from which
1414
locations in your source code.
1515
16-
This aspect only works on Linux when using the `local` spawn strategy because
17-
the `run_shell` action writes SCIP files to the provided
18-
--targetroot argument. It should be possible to avoid this requirement
19-
in the future if there's a strong desire to make the aspect work with the
20-
default (sandboxed) spawn strategy.
21-
2216
Use the command below to merge all of these SCIP files into a single index:
2317
2418
find bazel-bin/ -type f -name '*.scip' | xargs cat > index.scip
@@ -33,7 +27,7 @@ Use `src code-intel upload` to upload the unified SCIP file to Sourcegraph:
3327
3428
Example command to run this aspect directly:
3529
36-
bazel build //... --spawn_strategy=local --aspects path/to/scip_java.bzl%scip_java_aspect --output_groups=scip --define=sourceroot=$(pwd) --define=scip_java_binary=$(which scip-java) --define=java_home=$JAVA_HOME
30+
bazel build //... --aspects path/to/scip_java.bzl%scip_java_aspect --output_groups=scip --define=scip_java_binary=$(which scip-java) --define=java_home=$JAVA_HOME
3731
3832
To learn more about aspects: https://bazel.build/extending/aspects
3933
"""
@@ -136,12 +130,12 @@ def _scip_java(target, ctx):
136130
deps = [javac_action.inputs, annotations.processor_classpath]
137131

138132
ctx.actions.run_shell(
139-
# Prefix bazel-out paths with $PWD (the execroot) so they don't depend
140-
# on the workspace-level bazel-out convenience symlink, which doesn't
141-
# exist on a cold build.
142-
command = "\"{}\" index --no-cleanup --aggregate.allow-empty-index --cwd \"{}\" --targetroot \"$PWD/{}\" --scip-config \"$PWD/{}\" --output \"$PWD/{}\"".format(
133+
# The action runs in the execroot (sandboxed or not), so bazel-out
134+
# paths resolve directly. Prefix them with $PWD to make them absolute,
135+
# which keeps them unambiguous regardless of how scip-java resolves
136+
# relative paths.
137+
command = "\"{}\" index --no-cleanup --aggregate.allow-empty-index --targetroot \"$PWD/{}\" --scip-config \"$PWD/{}\" --output \"$PWD/{}\"".format(
143138
ctx.var["scip_java_binary"],
144-
ctx.var["sourceroot"],
145139
targetroot.path,
146140
build_config_path.path,
147141
scip_output.path,

0 commit comments

Comments
 (0)