diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a47c1642f..000000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,9 +0,0 @@ -### Test plan - - diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 4190c8870..000000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,12 +0,0 @@ -version: 2 -updates: - - - package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "monthly" - - - package-ecosystem: "docker" - directory: "/" - schedule: - interval: "weekly" diff --git a/.github/labeler.yml b/.github/labeler.yml deleted file mode 100644 index 99ccbb704..000000000 --- a/.github/labeler.yml +++ /dev/null @@ -1,4 +0,0 @@ -team/graph: - - '/.*/' -graph/scip-java: - - '/.*/' diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml deleted file mode 100644 index a336f9b34..000000000 --- a/.github/release-drafter.yml +++ /dev/null @@ -1,4 +0,0 @@ -template: | - ## Pull Requests - - $CHANGES diff --git a/renovate.json b/.github/renovate.json similarity index 71% rename from renovate.json rename to .github/renovate.json index ab445a56a..ae9a1a811 100644 --- a/renovate.json +++ b/.github/renovate.json @@ -1,7 +1,7 @@ { "$schema": "http://json.schemastore.org/renovate", "extends": [ - "github>sourcegraph/renovate-config" + "config:recommended" ], "semanticCommits": false } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 47785166b..0a50b2317 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,21 +18,14 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-java@v4 + - uses: DeterminateSystems/nix-installer-action@v22 with: - distribution: "temurin" - cache: "sbt" - java-version: ${{ matrix.java }} + summarize: false - - uses: sbt/setup-sbt@v1 - - - name: Setup Gradle 8.10 - uses: gradle/actions/setup-gradle@v4 - with: - gradle-version: '8.10' + - uses: DeterminateSystems/magic-nix-cache-action@v13 - name: Main project tests - run: sbt test + run: nix develop .#jdk${{ matrix.java }} --command sbt test docker_test: runs-on: ${{ matrix.os }} @@ -42,18 +35,16 @@ jobs: matrix: os: [ubuntu-latest] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: actions/setup-java@v3 + - uses: DeterminateSystems/nix-installer-action@v22 with: - distribution: "temurin" - cache: "sbt" - java-version: 17 + summarize: false - - uses: sbt/setup-sbt@v1 + - uses: DeterminateSystems/magic-nix-cache-action@v13 - name: Build Dockerised CLI - run: DOCKER_BUILDKIT=0 sbt cli/docker + run: nix develop --command bash -c "DOCKER_BUILDKIT=0 sbt cli/docker" - name: Test repos shell: bash @@ -61,11 +52,11 @@ jobs: set -eu check_repo() { REPO=$1 - mkdir -p .repos/$REPO - git clone https://github.com/$REPO.git .repos/$REPO && cd .repos/$REPO && git submodule update --init + mkdir -p ".repos/$REPO" + git clone "https://github.com/$REPO.git" ".repos/$REPO" && cd ".repos/$REPO" && git submodule update --init - docker run -v $PWD/.repos/$REPO:/sources -w /sources sourcegraph/scip-java:latest scip-java index - file .repos/$REPO/index.scip || (echo "$REPO SCIP index doesn't exist!"; exit 1) + docker run -v "$PWD/.repos/$REPO:/sources" -w /sources sourcegraph/scip-java:latest scip-java index + file ".repos/$REPO/index.scip" || (echo "$REPO SCIP index doesn't exist!"; exit 1) } sudo apt install parallel @@ -76,14 +67,20 @@ jobs: bazel: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - run: yarn global add @bazel/bazelisk - - run: bazel build //... --//semanticdb-javac:enabled=true - - run: bazel run scip-semanticdb:bazel -- --sourceroot "$PWD" + - uses: actions/checkout@v4 + + - uses: DeterminateSystems/nix-installer-action@v22 + with: + summarize: false + + - uses: DeterminateSystems/magic-nix-cache-action@v13 + + - run: nix develop --command bazelisk build //... --//semanticdb-javac:enabled=true + - run: nix develop --command bazelisk run scip-semanticdb:bazel -- --sourceroot "$PWD" - run: du -h index.scip - - run: bazel build //... --@scip_java//semanticdb-javac:enabled=true + - run: nix develop "$GITHUB_WORKSPACE" --command bazelisk build //... --@scip_java//semanticdb-javac:enabled=true working-directory: examples/bazel-example - - run: bazel run @scip_java//scip-semanticdb:bazel -- --sourceroot "$PWD" + - run: nix develop "$GITHUB_WORKSPACE" --command bazelisk run @scip_java//scip-semanticdb:bazel -- --sourceroot "$PWD" working-directory: examples/bazel-example - run: du -h index.scip working-directory: examples/bazel-example @@ -91,26 +88,27 @@ jobs: bazel_aspect: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - run: yarn global add @bazel/bazelisk + - uses: actions/checkout@v4 - - uses: actions/setup-java@v3 + - uses: DeterminateSystems/nix-installer-action@v22 with: - distribution: "temurin" - cache: "sbt" - java-version: 17 + summarize: false - - uses: sbt/setup-sbt@v1 + - uses: DeterminateSystems/magic-nix-cache-action@v13 - - run: sbt build - - run: echo "$PWD/out/bin" >> $GITHUB_PATH + - run: nix develop --command sbt build + - run: echo "$PWD/out/bin" >> "$GITHUB_PATH" - name: Auto-index scip-java codebase run: | - scip-java index --build-tool=bazel --bazel-scip-java-binary=$(which scip-java) + # shellcheck disable=SC2016 + nix develop --command bash -c \ + 'scip-java index --build-tool=bazel --bazel-scip-java-binary=$(which scip-java)' - run: du -h index.scip - name: Auto-index example/bazel-workspace run: | - scip-java index --build-tool=bazel --bazel-scip-java-binary=$(which scip-java) + # shellcheck disable=SC2016 + nix develop "$GITHUB_WORKSPACE" --command bash -c \ + 'scip-java index --build-tool=bazel --bazel-scip-java-binary=$(which scip-java)' working-directory: examples/bazel-example - run: du -h index.scip working-directory: examples/bazel-example @@ -121,19 +119,17 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-java@v4 + - uses: DeterminateSystems/nix-installer-action@v22 with: - distribution: "temurin" - cache: "sbt" - java-version: 11 + summarize: false - - uses: sbt/setup-sbt@v1 + - uses: DeterminateSystems/magic-nix-cache-action@v13 - name: semanticdb-kotlinc tests - run: sbt semanticdbKotlinc/test + run: nix develop --command sbt semanticdbKotlinc/test - name: Kotlin snapshots - run: sbt semanticdbKotlincMinimized/kotlincSnapshots + run: nix develop --command sbt semanticdbKotlincMinimized/kotlincSnapshots - name: Check snapshot drift run: | @@ -143,20 +139,18 @@ jobs: check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: actions/setup-java@v3 + - uses: DeterminateSystems/nix-installer-action@v22 with: - distribution: "temurin" - java-version: 11 - cache: "sbt" + summarize: false - - uses: sbt/setup-sbt@v1 + - uses: DeterminateSystems/magic-nix-cache-action@v13 - - run: sbt --client checkAll + - run: nix develop --command sbt --client checkAll - name: Run sample benchmarks - run: sbt --client 'bench/Jmh/run -i 1 -f1 -t1 -foe true' + run: nix develop --command sbt --client 'bench/Jmh/run -i 1 -f1 -t1 -foe true' maven: @@ -169,30 +163,29 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-java@v4 + - uses: DeterminateSystems/nix-installer-action@v22 with: - distribution: "temurin" - cache: "sbt" - java-version: ${{ matrix.java }} + summarize: false - - uses: sbt/setup-sbt@v1 + - uses: DeterminateSystems/magic-nix-cache-action@v13 - run: | - sbt build publishM2 publishLocal dumpScipJavaVersion - echo "SCIP_JAVA_VERSION=$(cat VERSION)" >> $GITHUB_ENV - echo "SCIP_JAVA_CLI=$PWD/out/bin/scip-java" >> $GITHUB_ENV + nix develop .#jdk${{ matrix.java }} --command sbt build publishM2 publishLocal dumpScipJavaVersion + echo "SCIP_JAVA_VERSION=$(cat VERSION)" >> "$GITHUB_ENV" + echo "SCIP_JAVA_CLI=$PWD/out/bin/scip-java" >> "$GITHUB_ENV" - run: | - mvn clean verify -DskipTests -Dscip-java.version=$SCIP_JAVA_VERSION sourcegraph:sourcegraphDependencies + nix develop "$GITHUB_WORKSPACE#jdk${{ matrix.java }}" --command \ + mvn clean verify -DskipTests "-Dscip-java.version=$SCIP_JAVA_VERSION" sourcegraph:sourcegraphDependencies working-directory: examples/maven-example - - run: $SCIP_JAVA_CLI index-semanticdb target/semanticdb-targetroot + - run: nix develop "$GITHUB_WORKSPACE#jdk${{ matrix.java }}" --command "$SCIP_JAVA_CLI" index-semanticdb target/semanticdb-targetroot working-directory: examples/maven-example - run: | set -e grep org.hamcrest target/semanticdb-targetroot/*dependencies.txt - grep $PWD/src/main/java target/semanticdb-targetroot/*dependencies.txt + grep "$PWD/src/main/java" target/semanticdb-targetroot/*dependencies.txt working-directory: examples/maven-example - run: du -h index.scip diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml deleted file mode 100644 index c2f027b1b..000000000 --- a/.github/workflows/labeler.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: "Issue Labeler" -on: - issues: - types: [opened, edited] - -permissions: - issues: write - contents: read - -jobs: - triage: - runs-on: ubuntu-latest - steps: - - uses: github/issue-labeler@v3.4 - with: - configuration-path: .github/labeler.yml - enable-versioned-regex: 0 - repo-token: ${{ github.token }} diff --git a/.github/workflows/mdoc.yml b/.github/workflows/mdoc.yml index 7d77e2571..4497d0381 100644 --- a/.github/workflows/mdoc.yml +++ b/.github/workflows/mdoc.yml @@ -7,15 +7,13 @@ jobs: publish: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-java@v3 + - uses: DeterminateSystems/nix-installer-action@v22 with: - distribution: 'temurin' - java-version: 11 - cache: 'sbt' - - uses: sbt/setup-sbt@v1 - - run: sbt docs/docusaurusPublishGhpages + summarize: false + - uses: DeterminateSystems/magic-nix-cache-action@v13 + - run: nix develop --command sbt docs/docusaurusPublishGhpages env: GIT_DEPLOY_KEY: ${{ secrets.GIT_DEPLOY_KEY }} diff --git a/.github/workflows/release-cli.yml b/.github/workflows/release-cli.yml index 0fdefe251..4e6c6bb4a 100644 --- a/.github/workflows/release-cli.yml +++ b/.github/workflows/release-cli.yml @@ -13,18 +13,19 @@ permissions: jobs: publish: runs-on: ubuntu-latest + defaults: + run: + shell: nix develop --command bash -e {0} steps: - - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: 11 + - uses: actions/checkout@v4 - - uses: coursier/setup-action@v3 + - uses: DeterminateSystems/nix-installer-action@v22 with: - apps: '' + summarize: false + + - uses: DeterminateSystems/magic-nix-cache-action@v13 - name: Build standalone launcher - shell: bash env: OUT_DIR: ${{ runner.temp }}/release-cli TAG: ${{ inputs.tag }} @@ -67,7 +68,6 @@ jobs: - name: Check for GitHub release id: release - shell: bash env: GH_TOKEN: ${{ github.token }} TAG: ${{ inputs.tag }} @@ -83,7 +83,6 @@ jobs: - name: Upload release assets if: steps.release.outputs.exists == 'true' - shell: bash env: OUT_DIR: ${{ runner.temp }}/release-cli GH_TOKEN: ${{ github.token }} diff --git a/.github/workflows/release-docker.yml b/.github/workflows/release-docker.yml index 49549ac3c..ed93824e3 100644 --- a/.github/workflows/release-docker.yml +++ b/.github/workflows/release-docker.yml @@ -8,19 +8,17 @@ jobs: publish: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-java@v3 + - uses: DeterminateSystems/nix-installer-action@v22 with: - distribution: 'temurin' - java-version: 11 - cache: 'sbt' - - uses: sbt/setup-sbt@v1 - - uses: docker/setup-buildx-action@v1 + summarize: false + - uses: DeterminateSystems/magic-nix-cache-action@v13 + - uses: docker/setup-buildx-action@v3 - name: Login to DockerHub - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - - run: DOCKER_BUILDKIT=0 sbt cli/dockerBuildAndPush + - run: nix develop --command bash -c "DOCKER_BUILDKIT=0 sbt cli/dockerBuildAndPush" diff --git a/.github/workflows/release-maven.yml b/.github/workflows/release-maven.yml index ee92b48b3..e3f38ff45 100644 --- a/.github/workflows/release-maven.yml +++ b/.github/workflows/release-maven.yml @@ -8,17 +8,15 @@ jobs: publish: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-java@v3 + - uses: DeterminateSystems/nix-installer-action@v22 with: - distribution: 'temurin' - java-version: 11 - cache: 'sbt' - - uses: sbt/setup-sbt@v1 + summarize: false + - uses: DeterminateSystems/magic-nix-cache-action@v13 - name: Publish ${{ github.ref }} - run: sbt ci-release + run: nix develop --command sbt ci-release env: PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} PGP_SECRET: ${{ secrets.PGP_SECRET }} diff --git a/.gitignore b/.gitignore index 38e260ab0..19eaa7a6e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,10 @@ *.class *.log +# nix +result +result-* + # sbt specific .cache .history diff --git a/.tool-versions b/.tool-versions deleted file mode 100644 index 68e582a99..000000000 --- a/.tool-versions +++ /dev/null @@ -1 +0,0 @@ -golang 1.17.5 diff --git a/bin/coursier b/bin/coursier deleted file mode 100755 index ce88feeb0..000000000 Binary files a/bin/coursier and /dev/null differ diff --git a/bin/docker-setup.sh b/bin/docker-setup.sh index 3953a3983..b472e11b4 100755 --- a/bin/docker-setup.sh +++ b/bin/docker-setup.sh @@ -1,8 +1,9 @@ #!/usr/bin/env bash set -eux -curl -fLo /usr/local/bin/coursier https://github.com/coursier/coursier/releases/download/v2.1.5/coursier -chmod +x /usr/local/bin/coursier -coursier setup --yes --apps coursier,sbt +curl -fLo /usr/local/bin/cs https://github.com/coursier/coursier/releases/download/v2.1.5/coursier +chmod +x /usr/local/bin/cs +ln -sf /usr/local/bin/cs /usr/local/bin/coursier +cs setup --yes --apps cs,coursier,sbt curl -fLo maven.zip https://archive.apache.org/dist/maven/maven-3/3.9.1/binaries/apache-maven-3.9.1-bin.zip unzip -d /opt/maven maven.zip diff --git a/bin/packagehub.sh b/bin/packagehub.sh index 93896e93f..4da72d50d 100755 --- a/bin/packagehub.sh +++ b/bin/packagehub.sh @@ -1,2 +1,2 @@ #!/usr/bin/env bash -/packagehub --host 0.0.0.0 --port $PORT --src /src --coursier /coursier --postgres.username=$DB_USER --postgres.password=$DB_PASS --postgres.url=$DB_URL +/packagehub --host 0.0.0.0 --port "$PORT" --src /src --coursier /coursier --postgres.username="$DB_USER" --postgres.password="$DB_PASS" --postgres.url="$DB_URL" diff --git a/bin/scip-java-docker-script.sh b/bin/scip-java-docker-script.sh index 1b7806159..68a611c2f 100755 --- a/bin/scip-java-docker-script.sh +++ b/bin/scip-java-docker-script.sh @@ -12,12 +12,10 @@ if test -f "$FILE"; then fi fi -JVM_VERSIONS=$(echo $JVM_VERSION | tr "," "\n") +JVM_VERSIONS=$(echo "$JVM_VERSION" | tr "," "\n") LAST_CODE="-1" -ARGS=$@ - for JVM_VERSION in $JVM_VERSIONS do if [ "$LAST_CODE" != "0" ]; then diff --git a/docs/contributing.md b/docs/contributing.md index 8a6e77b23..c89f50c8c 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -9,6 +9,21 @@ This page documents tips and tricks for contributing to the ## System dependencies +The recommended way to get a working development environment is via +[Nix](https://nixos.org/download) and the provided [flake](https://github.com/sourcegraph/scip-java/blob/main/flake.nix): + +```sh +nix develop # default shell (JDK 11) +nix develop .#jdk17 # JDK 17 +nix develop .#jdk21 # JDK 21 +``` + +This drops you into a shell with `sbt`, `cs` (coursier), `maven`, `gradle`, +`bazelisk`, `scalafmt`, `nodejs`, `yarn`, `git`, `jq`, etc. all pinned to the +versions used in CI. + +If you'd rather install tools manually, you'll need at least: + - `java`: any version should work - `git`: any version should work - `gradle`: `brew install gradle`, or see @@ -38,7 +53,7 @@ These are the main components of the project. | Command | Where | Description | | ------------------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------- | -| `./sbt` | terminal | Start interactive sbt shell with Java 11. Takes a while to load on the first run. | +| `sbt` | terminal | Start interactive sbt shell with Java 11 (run from `nix develop`). Takes a while to load on the first run. | | `unit/test` | sbt | Run fast unit tests. | | `~unit/test` | sbt | Start watch mode to run tests on file save, good for local edit-and-test workflows. | | `buildTools/test` | sbt | Run slow build tool tests (Gradle, Maven). | diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..86c022cd9 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1778737229, + "narHash": "sha256-6xWoytx8jFW4PF1GjRm/i/53trbpKGfz6zjzQGBr4cI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d7a713c0b7e47c908258e71cba7a2d77cc8d71d5", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-25.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..1f0d2584b --- /dev/null +++ b/flake.nix @@ -0,0 +1,83 @@ +{ + inputs = { + flake-utils = { + url = "github:numtide/flake-utils"; + }; + nixpkgs = { + url = "github:NixOS/nixpkgs/nixos-25.11"; + }; + }; + + outputs = + { + self, + flake-utils, + nixpkgs, + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { inherit system; }; + mkDevShell = + jdk: + pkgs.mkShellNoCC { + buildInputs = with pkgs; [ + bazelisk + (coursier.override ({ jre = jdk; })) + git + (gradle.override ({ java = jdk; })) + jdk + jq + (maven.override ({ jdk_headless = jdk; })) + (mill.override ({ jre = jdk; })) + nixfmt + nodejs + (sbt.override ({ jre = jdk; })) + scalafmt + yarn + ]; + }; + in + { + checks = { + actionlint = pkgs.runCommand "check-actionlint" { } '' + ${pkgs.actionlint}/bin/actionlint ${./.github/workflows}/*.yml + touch $out + ''; + nixfmt = pkgs.runCommand "check-nixfmt" { } '' + ${pkgs.nixfmt}/bin/nixfmt --check ${./flake.nix} + touch $out + ''; + renovate = pkgs.runCommand "check-renovate" { } '' + LOG_LEVEL=warn ${pkgs.renovate}/bin/renovate-config-validator \ + ${./.github/renovate.json} + touch $out + ''; + scalafmt = + pkgs.runCommand "check-scalafmt" + { + buildInputs = [ pkgs.git ]; + } + '' + cp -r ${./.}/. . + chmod -R u+w . + git init -q + git add -A + ${pkgs.scalafmt}/bin/scalafmt --check --non-interactive + touch $out + ''; + shellcheck = pkgs.runCommand "check-shellcheck" { } '' + ${pkgs.shellcheck}/bin/shellcheck ${./bin}/*.sh + touch $out + ''; + }; + + devShells = { + default = mkDevShell pkgs.jdk11; + jdk11 = mkDevShell pkgs.jdk11; + jdk17 = mkDevShell pkgs.jdk17; + jdk21 = mkDevShell pkgs.jdk21; + }; + } + ); +} diff --git a/project/JavaToolchainPlugin.scala b/project/JavaToolchainPlugin.scala index 142685440..50fa93e40 100644 --- a/project/JavaToolchainPlugin.scala +++ b/project/JavaToolchainPlugin.scala @@ -2,7 +2,6 @@ import sbt.{Compile, Def, File, _} import sbt.Keys._ import sbt.plugins.JvmPlugin -import java.nio.file.Paths import java.util import java.util.Collections import scala.util.Properties @@ -46,13 +45,10 @@ object JavaToolchainPlugin extends AutoPlugin { javaHomeCache.computeIfAbsent( version, (v: String) => { - val coursier = Paths.get("bin", "coursier") val index = jvmIndex .toList .flatMap(index => "--jvm-index" :: index :: Nil) - val arguments = - List("java", "-jar", coursier.toString, "java-home", "--jvm", v) ++ - index + val arguments = List("cs", "java-home", "--jvm", v) ++ index new File(Process(arguments).!!.trim) } diff --git a/sbt b/sbt deleted file mode 100755 index 5ec6cf0c5..000000000 --- a/sbt +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env sh -set -eu -./bin/coursier launch --jvm 11 sbt diff --git a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/BazelBuildTool.scala b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/BazelBuildTool.scala index c88ed4cd7..90e1b5039 100644 --- a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/BazelBuildTool.scala +++ b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/BazelBuildTool.scala @@ -5,6 +5,7 @@ import java.nio.file.FileSystems import java.nio.file.FileVisitResult import java.nio.file.Files import java.nio.file.Path +import java.nio.file.Paths import java.nio.file.SimpleFileVisitor import java.nio.file.StandardOpenOption import java.nio.file.attribute.BasicFileAttributes @@ -31,6 +32,18 @@ class BazelBuildTool(index: IndexCommand) extends BuildTool("Bazel", index) { else index.buildCommand + // Prefer `bazelisk` over `bazel` when both are available: bazelisk respects + // the project's `.bazelversion`, while `bazel` may be a pinned system version. + private def bazelExecutable: String = { + val pathDirs = + sys.env.getOrElse("PATH", "").split(java.io.File.pathSeparator).toList + List("bazelisk", "bazel") + .find { name => + pathDirs.exists(dir => Files.isExecutable(Paths.get(dir, name))) + } + .getOrElse("bazel") + } + override def generateScip(): Int = { val aspectLabel = this.generateAspectFile().getOrElse("") if (aspectLabel.isEmpty) { @@ -60,7 +73,7 @@ class BazelBuildTool(index: IndexCommand) extends BuildTool("Bazel", index) { val buildCommand = List( - "bazel", + bazelExecutable, "build", "--noshow_progress", // The local strategy is required for now because we write SemanticDB and SCIP files