dev-env: Add a symlink, dev-env/jdk, to the current JDK. (#7745)

* dev-env: Add a symlink, `dev-env/jdk`, to the current JDK.

This makes configuring IntelliJ IDEA to use the correct JDK much easier.

CHANGELOG_BEGIN
CHANGELOG_END

* dev-env: Document setting up the JDK in IntelliJ IDEA.
This commit is contained in:
Samir Talwar 2020-10-20 13:03:23 +02:00 committed by GitHub
parent dd01dbc5a4
commit 92020aa868
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 10 deletions

1
.gitignore vendored
View File

@ -12,6 +12,7 @@ target
.daml/
# dev-env
/dev-env/jdk
/dev-env/var/
# Bazel

View File

@ -244,7 +244,7 @@ file whenever you like, so don't worry too much.
The first import of the project might fail due to a resolution error of the
`bazel` binary. In order to solve this, configure the Bazel plugin settings
with the location of the `bazel` binary,
by setting _Preferences_ -> _Bazel Settings_ -> _Bazel binary location_
by setting _Preferences_ _Bazel Settings_ _Bazel binary location_
to `./dev-env/bin/bazel`.
Now, re-trigger a sync of the workspace (IntelliJ Action:
@ -252,6 +252,22 @@ _Sync project with BUILD files_). This process will take a while.
[intellij_project_view]: https://ij.bazel.build/docs/project-views.html
### Configuring the JDK in IntelliJ
DAML downloads the version of the JDK it uses from Nix. A symlink will be
created by the dev-env utilities (make sure you've set these up) in
_dev-env/jdk_.
TO configure IntelliJ to use this JDK:
1. Open the _Project Structure_ window.
2. Under _Platform Settings_, select _SDKs_.
3. Press the _plus_ button and select "Add JDK".
4. Choose the _dev-env/jdk_ directory.
5. Name it "DAML JDK" or something similar.
6. Open _Project Settings__Project_.
7. Select the DAML JDK from the _Project SDK_ list.
### Overview over Bazel IntelliJ Integration
The IntelliJ interface should largely look the same as under SBT. However, the

View File

@ -2,4 +2,7 @@
DADE_CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$DADE_CURRENT_SCRIPT_DIR/../lib/dade-common"
linkTool java out "${DADE_DEVENV_DIR}/jdk"
exec "${DADE_DEVENV_DIR}/lib/dade-dump-profile"

View File

@ -85,12 +85,20 @@ dadeGetOutput() {
# relalized into. This is necessary, since Nix's --add-root produces a
# unpredictable symlink name.
# force: if set to 1, forces re-initialization of the tool.
# target: the output location (defaults to "$DADE_GC_ROOTS/$attribute").
buildTool() {
local attr=$1
local attribute=$1
local outputName=$2
local force=$3
shift 3
local target="$DADE_GC_ROOTS/$attr"
if [[ $# -gt 0 ]]; then
local target=$1
local customTarget=1
shift 1
else
local target="$DADE_GC_ROOTS/$attribute"
local customTarget=0
fi
local hashfile="${target}.hash"
local hash="nope"
local currentHash="$(dadeBaseHash)"
@ -105,30 +113,41 @@ buildTool() {
if [[ ! -e "$DADE_BUILD_RESULT" || "$force" -eq 1 || "$hash" != "$currentHash" ]]; then
set -e
test "$force" -eq 1 && forced=" (forced)"
errcho "Building tools.${attr}${forced}..."
errcho "Building tools.${attribute}${forced}..."
# Allow to fail, so we can capture outpath and to capture the exit code too.
set +e
outpath=$(nix-build "${DADE_BASE_ROOT}/nix/default.nix" -A tools.$attr -Q -o "${target}")
outpath=$(nix-build "${DADE_BASE_ROOT}/nix/default.nix" -A "tools.${attribute}" -Q -o "${target}")
local dade_build_exit_code=$?
set -e
if [[ "$dade_build_exit_code" != "0" ]]; then
errcho "Build of tools.$attr has failed!"
errcho "Build of tools.$attribute has failed!"
exit 1
fi
errcho "Built tools.$attr in $outpath and linked to $DADE_BUILD_RESULT"
printf "$currentHash" >| "$hashfile"
errcho "Built tools.$attribute in $outpath and linked to $DADE_BUILD_RESULT"
if [[ $customTarget -eq 0 ]]; then
printf "$currentHash" >| "$hashfile"
fi
set +e
fi
}
# execTool <attribute> <outputName> <binary>
execTool() {
local attr=$1
local attribute=$1
local outputName=$2
local binary=$3
shift 3
[[ $PATH =~ (^|.*:)$DADE_DEVENV_DIR/bin($|:.*) ]] || \
eval "$(${DADE_DEVENV_DIR}/bin/dade assist)"
buildTool $attr $outputName 0
buildTool $attribute $outputName 0
exec "$(readlink "$DADE_BUILD_RESULT")/bin/$binary" "$@"
}
# linkTool <attribute> <outputName> <target>
linkTool() {
local attribute=$1
local outputName=$2
local target=$3
shift 3
buildTool $attribute $outputName 1 $target
}