diff --git a/.envrc b/.envrc new file mode 120000 index 000000000..3bdffd575 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +tools/environment/setup.bash \ No newline at end of file diff --git a/.tool-versions b/.tool-versions index 0f96391a9..14b9f982c 100644 --- a/.tool-versions +++ b/.tool-versions @@ -20,15 +20,10 @@ protoc 25.3 # PS #1: Nota bene, we intentionally *do NOT* have e.g. # "java temurin-21.0.2+13.0.LTS" (or "java openjdk-21") here, -# due to https://github.com/enola-dev/enola/issues/520! -# (And such a Java also wouldn't be used by Bazel, -# because of toolchains:remotejdk_21 -# in tools/java_toolchain/BUILD. -# Only ./enola launcher script.) +# originally due to https://github.com/enola-dev/enola/issues/520, +# but nowadays because tools/environment/setup.bash uses Bazel's JDK. # PS #2: We're similarly intentionally do NOT have e.g. # "golang 1.21.7" here, # due to https://github.com/enola-dev/enola/issues/532. -# FYI Go is required to install Bazelisk, if required -# (and perhaps for Go development later); and it's used -# by Bazel, due to go_sdk.host() in MODULE.bazel. +# tools/environment/setup.bash takes care of Go as well. diff --git a/.vscode/settings.json b/.vscode/settings.json index 6eb590f54..305c04934 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -168,6 +168,7 @@ "site": false, "tools": false, "web": false, - "BUILT": false + "BUILT": false, + ".envrc": false } } diff --git a/docs/dev/setup.md b/docs/dev/setup.md index 17eccae77..c68273c09 100644 --- a/docs/dev/setup.md +++ b/docs/dev/setup.md @@ -55,37 +55,36 @@ _This may be out of date (please help to update it) - it's just so much easier t If you do still want to try, here's how to manually install what the development environment container comes built-in with: -1. Install Java Development Kit (JDK), [same version as in `.bazelrc`](../../.bazelrc). - There are different Java (like Linux) "distributions" (all based on OpenJDK). - The easiest way to install one of them is typically to use your OS' package manager: - - sudo apt-get install openjdk-21-jdk openjdk-21-doc openjdk-21-source - - An alternative is to use e.g. [the SDKMAN!](https://sdkman.io) - If you work on several projects using different Java versions, - then we recommend using something like - [jEnv (with `.java-version`)](https://www.jenv.be), or - [asdf (with `.tool-versions`)](https://asdf-vm.com), or - [direnv (with `.envrc`)](https://direnv.net). +1. You do _NOT_ need to install a Java Development Kit (JDK), anymore. + The [version downloaded by Bazel via `.bazelrc`](../../.bazelrc) is now used by all scripts. 1. Install C/C++ etc. (it's required by the [Proto rule for Bazel](https://github.com/bazelbuild/rules_proto)), e.g. do: sudo apt-get install build-essential -1. Install [Python venv](https://docs.python.org/3/library/venv.html) +1. [Install Python venv](https://docs.python.org/3/library/venv.html) (it's used by the presubmit and docs site generation), e.g. with: sudo apt-get install python3-venv -1. Install [Bazelisk](https://github.com/bazelbuild/bazelisk) (NOT Bazel), - on a (recent enough...) Debian/Ubuntu [with Go](https://go.dev/doc/install) - e.g. like this (or some more manual equivalent): +1. You do _NOT_ need to install [Bazelisk](https://github.com/bazelbuild/bazelisk) (NOT Bazel), + that, and other tools, will be automagically installed by script. You do however Go for those tools, + and to build Enola's Go code. + +1. [Install Go](https://go.dev/doc/install) e.g. like this on a (recent enough...) Debian/Ubuntu (or some more manual equivalent): sudo apt update sudo apt install golang-go -You should now be able to proceed as above (but without requiring _Docker)._ +1. Now run `. .envrc` (or `source .envrc`, but NOT `./envrc`). + You could automated this with [direnv](https://direnv.net) (also [for Nix](https://github.com/direnv/direnv/wiki/Nix), and [other alternatives](https://direnv.net/#related-projects)). + +You should now be able to proceed as above (but without requiring _Docker),_ try specifically: + +* `./enola` + +* `./test.bash` ## Further Reading diff --git a/enola b/enola index 9a27aba9f..929469c4c 100755 --- a/enola +++ b/enola @@ -24,28 +24,19 @@ set -euo pipefail CWD=$(pwd) ROOT="$(realpath "$(dirname "$0")")" -if [ -x "$(command -v gbazelisk)" ]; then - BZL=gbazelisk -elif [ -x "$(command -v bazelisk)" ]; then - BZL=bazelisk -else - # Also in test.bash - echo "bazelisk is not installed, please run e.g. 'go install github.com/bazelbuild/bazelisk@latest' " - echo "or an equivalent from https://github.com/bazelbuild/bazelisk#installation or see docs/dev/setup.md" - exit 255 -fi - -source "$ROOT"/tools/bazel-java-tool-chain/bazel-java-tool-chain.bash -JAVA=$(java_binary) +source "$ROOT"/tools/environment/setup.bash cd "$ROOT" LOG=$(mktemp) +# NB: Similar build & launch also in tools/distro/build.sh & tools/distro/execjar-header.bash if "$BZL" build --color=yes //cli:enola_deploy.jar >"$LOG" 2>&1 ; then rm "$LOG" - # TODO Integrate this with (use) tools/distro/build.sh instead of launching it like this - cd "$CWD" && $JAVA --enable-preview -jar "$ROOT"/bazel-bin/cli/enola_deploy.jar "$@" + # TODO Integrate this with (use) tools/distro/build.sh instead of launching it directly like this? (But slower.) + cd "$CWD" && "$bazel_java_home"/bin/java --enable-preview -jar "$ROOT"/bazel-bin/cli/enola_deploy.jar "$@" else cat "$LOG" && echo >&2 && echo >&2 rm "$LOG" cd "$CWD" fi + +# PS: Alternatively, you can also launch it simply via "bazelisk run //cli:enola -- --version" etc. diff --git a/test.bash b/test.bash index a7cf39ef7..0e4a57695 100755 --- a/test.bash +++ b/test.bash @@ -20,19 +20,9 @@ set -euo pipefail # This script builds the project *WITHOUT* requiring containers. # It can be used *IN* a container though; and is so, by the ./build script. -# Similar also in the ./enola script: -GO_BIN_PATH=$(go env GOPATH)/bin -BZL=$GO_BIN_PATH/bazelisk -if ! [ -x "$(command -v "$BZL")" ]; then - if [ -x "$(command -v go)" ]; then - tools/go/install.bash +ROOT="$(realpath "$(dirname "$0")")" - else - echo "Please install Go from https://go.dev/doc/install and re-run this script!" - echo "See also https://docs.enola.dev/dev/setup/" - exit 255 - fi -fi +source tools/environment/setup.bash # https://github.com/bazelbuild/bazel/issues/4257 echo $ Bazel testing... diff --git a/tools/bazel-java-tool-chain/bazel-java-tool-chain.bash b/tools/bazel-java-tool-chain/bazel-java-tool-chain.bash index 2c60c3fc6..44fc0f723 100644 --- a/tools/bazel-java-tool-chain/bazel-java-tool-chain.bash +++ b/tools/bazel-java-tool-chain/bazel-java-tool-chain.bash @@ -32,7 +32,7 @@ function cleanup { # * https://github.com/salesforce/bazel-eclipse/blob/888bcd333ac7bd4166fdb411562b74c2b54514d5/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/BaseProvisioningStrategy.java#L945-L960 # * https://stackoverflow.com/questions/78057833/how-to-query-bazel-for-the-absolute-jave-home-like-path-to-the-remote-jdk-of -function java_binary { +function bazel_java_home { local current_java_runtime ROOT="$(realpath "$(dirname "${BASH_SOURCE[0]}"/)")" @@ -58,5 +58,5 @@ function java_binary { rm "$LOG" fi - echo "$output_base/$current_java_runtime/bin/java" + echo "$output_base/$current_java_runtime" } diff --git a/tools/bazel-java-tool-chain/test.bash b/tools/bazel-java-tool-chain/test.bash index 2ff36fa13..ae159273d 100755 --- a/tools/bazel-java-tool-chain/test.bash +++ b/tools/bazel-java-tool-chain/test.bash @@ -24,6 +24,6 @@ cd /tmp # shellcheck disable=SC1091 source "$ROOT"/bazel-java-tool-chain.bash -java_binary +bazel_java_home cd "$CWD" diff --git a/tools/distro/build.bash b/tools/distro/build.bash index 06756ddfb..4d00a19ab 100755 --- a/tools/distro/build.bash +++ b/tools/distro/build.bash @@ -21,10 +21,12 @@ mkdir -p site/download/latest/ set -euox pipefail # Build the end-user distributed executable fat über JAR -# NB: "bazelisk build //..." does *NOT* build "//cli:enola_deploy.jar", for some reason +# NB: "bazelisk build //..." does *NOT* build "//cli:enola_deploy.jar" (for some reason) bazelisk build //cli:enola_deploy.jar cp tools/distro/execjar-header.bash site/download/latest/enola cat bazel-bin/cli/enola_deploy.jar >>site/download/latest/enola +# Let's briefly test it: +site/download/latest/enola --version # Build the Container Image # NB: This must work both on Docker (which turns it into docker buildx build) and Podman! diff --git a/tools/environment/setup.bash b/tools/environment/setup.bash new file mode 100644 index 000000000..8f00264d4 --- /dev/null +++ b/tools/environment/setup.bash @@ -0,0 +1,57 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright 2023-2024 The Enola Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This script sets environment variables which are useful for Enola developpers. +# Note that the Bazel build tool does not required these. The goal of this is +# however to give developpers the same environment in their respective shell. +# This also helps to launch IDEs, such as VSC, and make them use the same +# (versions of the) tools which run under Bazel for building & testing. + +# As explained on https://docs.enola.dev/dev/setup/, +# Developers must run this script via ". .envrc" (NOT ./.envrc). +# Other scripts do so likewise (via source, same as "."). +# Ergo, no +x no this one. + +# Set-Up Go +# Go is required to install Bazelisk (the way we install it), by Bazel, +# due to go_sdk.host() in MODULE.bazel, for Go development in Enola. +if ! [ -x "$(command -v go)" ]; then + echo "Please install Go from https://go.dev/doc/install and re-run this script!" + echo "See also https://docs.enola.dev/dev/setup/" + exit 255 +fi + +if [ -x "$(command -v gbazelisk)" ]; then + BZL=gbazelisk +elif [ -x "$(command -v bazelisk)" ]; then + BZL=bazelisk +else + source tools/go/install.bash +fi + +# Set-Up Java +# This makes us use the exact same JDK as used by Bazel. +# (Which is the toolchains:remotejdk_21 in tools/java_toolchain/BUILD.) +source "$ROOT"/tools/bazel-java-tool-chain/bazel-java-tool-chain.bash +bazel_java_home=$(bazel_java_home) + +# This breaks ./enola, see https://github.com/enola-dev/enola/issues/574 +#JAVA_HOME=$bazel_java_home +#export JAVA_HOME +#PATH=$bazel_java_home/bin:$PATH +#export PATH + +# TODO Write a setup.fish script... can it invoke this one?