Skip to content

Commit

Permalink
Jar licensing (digital-asset#17299)
Browse files Browse the repository at this point in the history
* Add _distribute.jar target with correct license
Use it everywhere

* Fixes from review

* Change NOTICES to NOTICES.txt for consistency
  • Loading branch information
samuel-williams-da authored Aug 22, 2023
1 parent 73c4f71 commit 9179b2e
Show file tree
Hide file tree
Showing 30 changed files with 135 additions and 84 deletions.
7 changes: 5 additions & 2 deletions BAZEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ da_scala_binary(
runtime_deps = [
"@maven//:ch_qos_logback_logback_classic",
],
tags = ["ee-jar-license"],
deps = [
":script-runner-lib",
"//release:ee-license",
],
)
```
Expand Down Expand Up @@ -924,7 +924,10 @@ JAR suitable for deployment for all your Java and Scala targets. For example,
if you defined a Scala executable target called `foo`, then Bazel will generate
the target `foo_deploy.jar` next to the regular `foo.jar` target. Building the
`foo_deploy.jar` target will generate a self-contained fat JAR suitable to be
passed to `java -jar`.
passed to `java -jar`. When using `da_scala_binary`, we also generate a
`foo_distribute.jar` which takes the deployment jar and fixes the notices and
licenses. It will check for the `ee-jar-license` tag to decide whether to use
the default apache license, or our Enterprise Edition license.
### Scaladoc
Expand Down
1 change: 1 addition & 0 deletions bazel_tools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ exports_files(
"haskell-win-sys-includes.patch",
"haskell-drop-fake-static.patch",
"pom_template.xml",
"distribute_jar_cleanup.sh",
],
visibility = ["//:__subpackages__"],
)
Expand Down
27 changes: 27 additions & 0 deletions bazel_tools/distribute_jar_cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
# Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0


SRC=$1
OUT=$2
NOTICES=$3
LICENSE=$4
LICENSE_EE=$5
IS_EE=$6

cp $SRC $OUT
chmod +w $OUT
zip -dq $OUT "/LICENSE*" "/META-INF/LICENSE*" "/NOTICE*" "/META-INF/NOTICE*"

# both licenses have the wrong file name/directory, so we copy to a temp dir
TMP_LICENSE_DIR=$(mktemp -d)
cp $NOTICES $TMP_LICENSE_DIR/NOTICES.txt
if [[ "$IS_EE" -eq 1 ]]; then
cp $LICENSE_EE $TMP_LICENSE_DIR/LICENSE.txt
else
cp $LICENSE $TMP_LICENSE_DIR/LICENSE.txt
fi
zip -ujq $OUT $TMP_LICENSE_DIR/LICENSE.txt $TMP_LICENSE_DIR/NOTICES.txt
rm -rf $TMP_LICENSE_DIR

26 changes: 26 additions & 0 deletions bazel_tools/scala.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,11 @@ def da_scala_binary(name, initial_heap_size = default_initial_heap_size, max_hea
arguments = _set_jvm_flags(arguments, initial_heap_size = initial_heap_size, max_heap_size = max_heap_size)
_wrap_rule(scala_binary, name, **arguments)

is_ee = 0

if "tags" in arguments:
if "ee-jar-license" in arguments["tags"]:
is_ee = 1
for tag in arguments["tags"]:
if tag.startswith("maven_coordinates="):
pom_file(
Expand All @@ -676,6 +680,28 @@ def da_scala_binary(name, initial_heap_size = default_initial_heap_size, max_hea
)
break

native.genrule(
name = name + "_distribute",
srcs = [":" + name + "_deploy.jar"],
tools = [
"//bazel_tools:distribute_jar_cleanup.sh",
"//:NOTICES",
"//:LICENSE",
"//release:ee-license.txt",
],
outs = [name + "_distribute.jar"],
cmd = """
$(location //bazel_tools:distribute_jar_cleanup.sh)\
$(location :{name}_deploy.jar)\
$(location :{name}_distribute.jar)\
$(location //:NOTICES)\
$(location //:LICENSE)\
$(location //release:ee-license.txt)\
{is_ee}
""".format(name = name, is_ee = is_ee),
visibility = arguments.get("visibility"),
)

def da_scala_test(initial_heap_size = default_initial_heap_size, max_heap_size = default_max_heap_size, **kwargs):
"""
Define a Scala executable that runs the unit tests in the given source files.
Expand Down
32 changes: 16 additions & 16 deletions ci/copy-unix-release-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,34 @@ if [[ "$NAME" == "linux" ]]; then

JSON_API=http-json-$RELEASE_TAG.jar
JSON_API_EE=http-json-$RELEASE_TAG-ee.jar
bazel build //ledger-service/http-json:http-json-binary_deploy.jar
cp bazel-bin/ledger-service/http-json/http-json-binary_deploy.jar $OUTPUT_DIR/github/$JSON_API
bazel build //ledger-service/http-json:http-json-binary-ee_deploy.jar
cp bazel-bin/ledger-service/http-json/http-json-binary-ee_deploy.jar $OUTPUT_DIR/artifactory/$JSON_API_EE
bazel build //ledger-service/http-json:http-json-binary_distribute.jar
cp bazel-bin/ledger-service/http-json/http-json-binary_distribute.jar $OUTPUT_DIR/github/$JSON_API
bazel build //ledger-service/http-json:http-json-binary-ee_distribute.jar
cp bazel-bin/ledger-service/http-json/http-json-binary-ee_distribute.jar $OUTPUT_DIR/artifactory/$JSON_API_EE

TRIGGER_SERVICE=trigger-service-$RELEASE_TAG.jar
TRIGGER_SERVICE_EE=trigger-service-$RELEASE_TAG-ee.jar
bazel build //triggers/service:trigger-service-binary-ce_deploy.jar
cp bazel-bin/triggers/service/trigger-service-binary-ce_deploy.jar $OUTPUT_DIR/github/$TRIGGER_SERVICE
bazel build //triggers/service:trigger-service-binary-ee_deploy.jar
cp bazel-bin/triggers/service/trigger-service-binary-ee_deploy.jar $OUTPUT_DIR/artifactory/$TRIGGER_SERVICE_EE
bazel build //triggers/service:trigger-service-binary-ce_distribute.jar
cp bazel-bin/triggers/service/trigger-service-binary-ce_distribute.jar $OUTPUT_DIR/github/$TRIGGER_SERVICE
bazel build //triggers/service:trigger-service-binary-ee_distribute.jar
cp bazel-bin/triggers/service/trigger-service-binary-ee_distribute.jar $OUTPUT_DIR/artifactory/$TRIGGER_SERVICE_EE

OAUTH2_MIDDLEWARE=oauth2-middleware-$RELEASE_TAG.jar
bazel build //triggers/service/auth:oauth2-middleware-binary_deploy.jar
cp bazel-bin/triggers/service/auth/oauth2-middleware-binary_deploy.jar $OUTPUT_DIR/github/$OAUTH2_MIDDLEWARE
bazel build //triggers/service/auth:oauth2-middleware-binary_distribute.jar
cp bazel-bin/triggers/service/auth/oauth2-middleware-binary_distribute.jar $OUTPUT_DIR/github/$OAUTH2_MIDDLEWARE


TRIGGER=daml-trigger-runner-$RELEASE_TAG.jar
bazel build //triggers/runner:trigger-runner_deploy.jar
cp bazel-bin/triggers/runner/trigger-runner_deploy.jar $OUTPUT_DIR/artifactory/$TRIGGER
bazel build //triggers/runner:trigger-runner_distribute.jar
cp bazel-bin/triggers/runner/trigger-runner_distribute.jar $OUTPUT_DIR/artifactory/$TRIGGER

SCRIPT=daml-script-$RELEASE_TAG.jar
bazel build //daml-script/runner:daml-script-binary_deploy.jar
cp bazel-bin/daml-script/runner/daml-script-binary_deploy.jar $OUTPUT_DIR/artifactory/$SCRIPT
bazel build //daml-script/runner:daml-script-binary_distribute.jar
cp bazel-bin/daml-script/runner/daml-script-binary_distribute.jar $OUTPUT_DIR/artifactory/$SCRIPT

NON_REPUDIATION=non-repudiation-$RELEASE_TAG-ee.jar
bazel build //runtime-components/non-repudiation-app:non-repudiation-app_deploy.jar
cp bazel-bin/runtime-components/non-repudiation-app/non-repudiation-app_deploy.jar $OUTPUT_DIR/artifactory/$NON_REPUDIATION
bazel build //runtime-components/non-repudiation-app:non-repudiation-app_distribute.jar
cp bazel-bin/runtime-components/non-repudiation-app/non-repudiation-app_distribute.jar $OUTPUT_DIR/artifactory/$NON_REPUDIATION

NON_REPUDIATION_CORE_JAR=non-repudiation-core-$RELEASE_TAG.jar
NON_REPUDIATION_CORE_POM=non-repudiation-core-$RELEASE_TAG.pom
Expand Down
2 changes: 1 addition & 1 deletion compatibility/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ daml_sdk_head(
daml_ledger_tarball = "@head_sdk//:daml-ledger-0.0.0.tgz",
daml_react_tarball = "@head_sdk//:daml-react-0.0.0.tgz",
daml_types_tarball = "@head_sdk//:daml-types-0.0.0.tgz",
ledger_api_test_tool = "@head_sdk//:ledger-api-test-tool_deploy.jar",
ledger_api_test_tool = "@head_sdk//:ledger-api-test-tool_distribute.jar",
os_name = os_name,
sdk_tarball = "@head_sdk//:sdk-release-tarball-ce.tar.gz",
)
Expand Down
4 changes: 2 additions & 2 deletions compatibility/build-release-artifacts-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ bazel fetch @nodejs_dev_env//...
bazel build `
`-`-experimental_execution_log_file ${ARTIFACT_DIRS}/build_execution_windows.log `
//release:sdk-release-tarball `
//ledger-test-tool/tool:ledger-api-test-tool_deploy.jar
//ledger-test-tool/tool:ledger-api-test-tool_distribute.jar

git clean -fxd -e 'daml-*.tgz' compatibility/head_sdk

cp -Force bazel-bin\release\sdk-release-tarball-ce.tar.gz compatibility/head_sdk
cp -Force bazel-bin\ledger-test-tool\tool\ledger-api-test-tool_deploy.jar compatibility/head_sdk
cp -Force bazel-bin\ledger-test-tool\tool\ledger-api-test-tool_distribute.jar compatibility/head_sdk
cp -Force templates\create-daml-app-test-resources\messaging.patch compatibility/head_sdk
4 changes: 2 additions & 2 deletions compatibility/build-release-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ git clean -fxd -e 'daml-*.tgz' $HEAD_TARGET_DIR

bazel build \
//release:sdk-release-tarball \
//ledger-test-tool/tool:ledger-api-test-tool_deploy.jar
//ledger-test-tool/tool:ledger-api-test-tool_distribute.jar

cp -f bazel-bin/release/sdk-release-tarball-ce.tar.gz "$HEAD_TARGET_DIR"
cp -f bazel-bin/ledger-test-tool/tool/ledger-api-test-tool_deploy.jar "$HEAD_TARGET_DIR"
cp -f bazel-bin/ledger-test-tool/tool/ledger-api-test-tool_distribute.jar "$HEAD_TARGET_DIR"
cp -f templates/create-daml-app-test-resources/messaging.patch "$HEAD_TARGET_DIR"
2 changes: 1 addition & 1 deletion compiler/repl-service/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ load(

genrule(
name = "repl_service_jar",
srcs = [":repl-service-raw_deploy.jar"],
srcs = [":repl-service-raw_distribute.jar"],
outs = ["repl-service.jar"],
cmd = "cp $< $@",
visibility = ["//visibility:public"],
Expand Down
2 changes: 1 addition & 1 deletion compiler/scenario-service/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ load("//bazel_tools:scala.bzl", "da_scala_binary", "lf_scalacopts_stricter")

genrule(
name = "scenario_service_jar",
srcs = [":scenario-service-raw_deploy.jar"],
srcs = [":scenario-service-raw_distribute.jar"],
outs = ["scenario-service.jar"],
cmd = "cp $< $@",
visibility = ["//visibility:public"],
Expand Down
9 changes: 5 additions & 4 deletions daml-assistant/daml-sdk/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ da_scala_binary(
resources = glob(["src/main/resources/**/*"]),
scala_deps = scala_deps,
scala_runtime_deps = scala_runtime_deps,
tags = ["ee-jar-license"],
# Navigator resources trigger this incorrectly
unused_dependency_checker_mode = "off",
visibility = ["//visibility:public"],
Expand All @@ -65,12 +66,12 @@ sh_test(
srcs = ["validate.sh"],
args = [
"$(location @local_jdk//:bin/java.exe)" if is_windows else "$(location @local_jdk//:bin/java)",
"$(location :sdk_deploy.jar)",
"$(location :sdk_ee_deploy.jar)",
"$(location :sdk_distribute.jar)",
"$(location :sdk_ee_distribute.jar)",
],
data = [
":sdk_deploy.jar",
":sdk_ee_deploy.jar",
":sdk_distribute.jar",
":sdk_ee_distribute.jar",
"@local_jdk//:bin/java.exe" if is_windows else "@local_jdk//:bin/java",
],
deps = [
Expand Down
1 change: 1 addition & 0 deletions daml-ghcide
Submodule daml-ghcide added at 89d20f
2 changes: 1 addition & 1 deletion daml-script/runner/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ da_scala_binary(
"@maven//:com_typesafe_akka_akka_slf4j",
],
scalacopts = lf_scalacopts_stricter,
tags = ["ee-jar-license"],
visibility = ["//visibility:public"],
runtime_deps = [
"@maven//:ch_qos_logback_logback_classic",
],
deps = [
":script-runner-lib",
"//release:ee-license",
],
)

Expand Down
2 changes: 1 addition & 1 deletion language-support/codegen-main/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ da_scala_binary(

jar_jar(
name = "shaded_binary",
input_jar = "//language-support/codegen-main:codegen-main_deploy.jar",
input_jar = "//language-support/codegen-main:codegen-main_distribute.jar",
rules = "shade_rule",
tags = ["maven_coordinates=com.daml:codegen-jvm-main:__VERSION__"],
visibility = ["//visibility:public"],
Expand Down
2 changes: 1 addition & 1 deletion language-support/java/codegen/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ dar_to_java(

jar_jar(
name = "shaded_binary",
input_jar = "//language-support/java/codegen:codegen_deploy.jar",
input_jar = "//language-support/java/codegen:codegen_distribute.jar",
rules = "shade_rule",
tags = ["maven_coordinates=com.daml:codegen-java:__VERSION__"],
visibility = ["//visibility:public"],
Expand Down
4 changes: 2 additions & 2 deletions language-support/ts/codegen/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ sh_test(
"$(location //:yarn)",
"$(location //:daml2js)",
"$(location //canton:canton_deploy.jar)",
"$(location //ledger-service/http-json:http-json-binary_deploy.jar)",
"$(location //ledger-service/http-json:http-json-binary_distribute.jar)",
"$(location :build-and-lint.dar)",
"$(location ts/package.json)",
"$(location //language-support/ts/daml-types:npm_package)",
Expand All @@ -104,7 +104,7 @@ sh_test(
"//:java",
"//:yarn",
"//:daml2js",
"//ledger-service/http-json:http-json-binary_deploy.jar",
"//ledger-service/http-json:http-json-binary_distribute.jar",
":build-and-lint.dar",
":hidden.dar",
"//test-common:model-tests-default.dar",
Expand Down
2 changes: 1 addition & 1 deletion ledger-service/http-json/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ json_deps = {
"//ledger-service/http-json-cli:ee",
"//ledger-service/http-json-ledger-client:ee",
"@maven//:com_oracle_database_jdbc_ojdbc8",
"//release:ee-license",
],
}

Expand Down Expand Up @@ -178,6 +177,7 @@ da_scala_binary(
scala_deps = json_scala_deps,
scalacopts = hj_scalacopts,
tags = [
"ee-jar-license",
"maven_coordinates=com.daml:http-json-deploy:__VERSION__",
"no_scala_version_suffix",
],
Expand Down
4 changes: 2 additions & 2 deletions ledger-test-tool/tool/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ sh_test(
srcs = ["src/test/test-extract.sh"],
args = [
"$(location @local_jdk//:bin/java.exe)" if is_windows else "$(location @local_jdk//:bin/java)",
"$(location :ledger-api-test-tool_deploy.jar)",
"$(location :ledger-api-test-tool_distribute.jar)",
],
data = [
":ledger-api-test-tool_deploy.jar",
":ledger-api-test-tool_distribute.jar",
"@local_jdk//:bin/java.exe" if is_windows else "@local_jdk//:bin/java",
],
deps = [
Expand Down
6 changes: 3 additions & 3 deletions navigator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ To build a "fat" JAR of the Navigator that includes the pre-compiled front-end
assets, run:

```bash
bazel build //navigator/backend:navigator-binary_deploy.jar
bazel build //navigator/backend:navigator-binary_distribute.jar
```

This produces a "fat" JAR `bazel-bin/navigator/backend/navigator-binary_deploy.jar` which can be run with:
This produces a "fat" JAR `bazel-bin/navigator/backend/navigator-binary_distribute.jar` which can be run with:

```bash
java -jar bazel-bin/navigator/backend/navigator-binary_deploy.jar
java -jar bazel-bin/navigator/backend/navigator-binary_distribute.jar
```

Notable things in the Navigator build:
Expand Down
6 changes: 3 additions & 3 deletions navigator/backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ We can build and run a basic the backend using the following commands:

```bash
# Build a distribution archive ("fat jar"):
bazel build //navigator/backend:navigator-binary_deploy.jar
bazel build //navigator/backend:navigator-binary_distribute.jar

# Run without arguments to show usage:
java -jar bazel-bin/navigator/backend/navigator-binary_deploy.jar --help
java -jar bazel-bin/navigator/backend/navigator-binary_distribute.jar --help

# Create a dummy configuration file
cat << EOF > navigator.conf
Expand All @@ -34,7 +34,7 @@ users {
EOF

# Start the web server
java -jar bazel-bin/navigator/backend/navigator-binary_deploy.jar server -c navigator.conf
java -jar bazel-bin/navigator/backend/navigator-binary_distribute.jar server -c navigator.conf
```

If you start the server and the configuration file doesn't exist, the server will
Expand Down
16 changes: 1 addition & 15 deletions release/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,7 @@ load("util.bzl", "protos_zip", "sdk_tarball")
load("@build_environment//:configuration.bzl", "sdk_version")
load("@os_info//:os_info.bzl", "is_windows")

genrule(
name = "LICENSE",
srcs = [":ee-license.txt"],
outs = ["LICENSE.txt"],
cmd = """
cp $(location :ee-license.txt) $@
""",
)

java_library(
name = "ee-license",
resource_strip_prefix = "release/",
resources = [":LICENSE.txt"],
visibility = ["//visibility:public"],
)
exports_files(["ee-license.txt"])

da_haskell_binary(
name = "release",
Expand Down
10 changes: 5 additions & 5 deletions release/artifacts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
- target: //language-support/codegen-main:shaded_binary
type: jar-jarjar
- target: //language-support/scala/codegen:codegen-main
type: jar-deploy
type: jar-distribute
- target: //language-support/java/bindings:bindings-java
type: jar-lib
- target: //language-support/java/bindings-rxjava:bindings-rxjava
Expand Down Expand Up @@ -116,13 +116,13 @@
- target: //ledger-test-tool/suites:suites-1.dev
type: jar-scala
- target: //ledger-test-tool/tool:ledger-api-test-tool
type: jar-deploy
type: jar-distribute
- target: //ledger-test-tool/tool:tool-1.14
type: jar-deploy
type: jar-distribute
- target: //ledger-test-tool/tool:tool-1.15
type: jar-deploy
type: jar-distribute
- target: //ledger-test-tool/tool:tool-1.dev
type: jar-deploy
type: jar-distribute
- target: //ledger/participant-local-store:participant-local-store
type: jar-scala
- target: //test-common:dar-files-1.14-lib
Expand Down
Loading

0 comments on commit 9179b2e

Please sign in to comment.