Skip to content

Commit

Permalink
dev-env: Add a symlink, dev-env/jdk, to the current JDK. (digital-a…
Browse files Browse the repository at this point in the history
…sset#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.
  • Loading branch information
SamirTalwar authored Oct 20, 2020
1 parent dd01dbc commit 92020aa
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ target
.daml/

# dev-env
/dev-env/jdk
/dev-env/var/

# Bazel
Expand Down
18 changes: 17 additions & 1 deletion BAZEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,30 @@ 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:
_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
Expand Down
3 changes: 3 additions & 0 deletions dev-env/bin/dade-assist
Original file line number Diff line number Diff line change
Expand Up @@ -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"
37 changes: 28 additions & 9 deletions dev-env/lib/dade-common
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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
}

0 comments on commit 92020aa

Please sign in to comment.