Skip to content

Commit

Permalink
language: put sdk versions into package.json (digital-asset#4122)
Browse files Browse the repository at this point in the history
* language: put sdk versions into package.json

The typescript library versions of our support libraries are now given
by the sdk version.

CHANGELOG_BEGIN
CHANGELOG_END

* removed local field

* better placeholders

* consistent SDK_VERSION

* sed sdkversion in test script
  • Loading branch information
Robin Krom authored Jan 21, 2020
1 parent 4cc1427 commit ad93252
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 5 deletions.
4 changes: 4 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ load("//bazel_tools:os_info.bzl", "os_info")

os_info(name = "os_info")

load("//bazel_tools:sdk_version.bzl", "sdk_version")

sdk_version(name = "sdk_version")

dadew(name = "dadew")

load("@os_info//:os_info.bzl", "is_linux", "is_windows")
Expand Down
27 changes: 27 additions & 0 deletions bazel_tools/sdk_version.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2020 The DAML Authors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

_sdk_version_bzl_template = """
sdk_version = "{SDK_VERSION}"
"""

def _sdk_version_impl(repository_ctx):
version = repository_ctx.read(repository_ctx.attr.version).strip()
sdk_version_substitutions = {
"SDK_VERSION": version,
}
repository_ctx.file(
"sdk_version.bzl",
_sdk_version_bzl_template.format(**sdk_version_substitutions),
False,
)
repository_ctx.file(
"BUILD",
"",
False,
)

sdk_version = repository_rule(
implementation = _sdk_version_impl,
attrs = {"version": attr.label(default = "//:VERSION")},
)
3 changes: 3 additions & 0 deletions language-support/ts/codegen/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

load("//rules_daml:daml.bzl", "daml_compile")
load("@sdk_version//:sdk_version.bzl", "sdk_version")

# This rule builds a dar from the daml sources under the 'daml'
# directory. It is referenced from the 'build-and-lint' test that
Expand Down Expand Up @@ -37,6 +38,7 @@ sh_test(
"$(location ts/package.json)",
"$(location //language-support/ts/daml-json-types:npm_package)",
"$(location //language-support/ts/daml-ledger-fetch:npm_package)",
sdk_version,
],
data = [
"//:java",
Expand All @@ -47,6 +49,7 @@ sh_test(
":daml2ts-test.dar",
"//language-support/ts/daml-json-types:npm_package",
"//language-support/ts/daml-ledger-fetch:npm_package",
"//:VERSION",
] + glob(
["ts/**"],
exclude = [
Expand Down
2 changes: 2 additions & 0 deletions language-support/ts/codegen/tests/build-and-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ PACKAGE_JSON=$(rlocation "$TEST_WORKSPACE/$7")
TS_DIR=$(dirname $PACKAGE_JSON)
DAML_JSON_TYPES=$(rlocation "$TEST_WORKSPACE/$8")
DAML_LEDGER_FETCH=$(rlocation "$TEST_WORKSPACE/$9")
VERSION="${10}"

TMP_DIR=$(mktemp -d)
TMP_DAML_JSON_TYPES=$TMP_DIR/daml-json-types
Expand All @@ -45,6 +46,7 @@ cp -rL $DAML_LEDGER_FETCH/* $TMP_DAML_LEDGER_FETCH
cd $TMP_DIR

$DAML2TS -o generated/src/daml --main-package-name daml-tests $DAR
sed -i "s/0.0.0-SDK_VERSION/${VERSION}/" generated/package.json
$YARN install --frozen-lockfile
$YARN workspaces run build
cd generated
Expand Down
4 changes: 2 additions & 2 deletions language-support/ts/codegen/tests/ts/generated/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"description": "Generated by daml2ts",
"license": "Apache-2.0",
"dependencies": {
"@digitalasset/daml-json-types": "0.0.1",
"@digitalasset/daml-ledger-fetch": "0.0.1"
"@digitalasset/daml-json-types": "0.0.0-SDK_VERSION",
"@digitalasset/daml-ledger-fetch": "0.0.0-SDK_VERSION"
},
"scripts": {
"build": "tsc --build",
Expand Down
2 changes: 2 additions & 0 deletions language-support/ts/daml-json-types/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ load("@npm_bazel_typescript//:index.bzl", "ts_library")
load("@os_info//:os_info.bzl", "is_windows")
load("//language-support/ts:eslint.bzl", "eslint_test")
load("//language-support/ts:jest.bzl", "jest_test")
load("@sdk_version//:sdk_version.bzl", "sdk_version")

ts_library(
name = "daml-json-types",
Expand Down Expand Up @@ -51,6 +52,7 @@ pkg_npm(
":package.json",
":tsconfig.json",
],
substitutions = {"0.0.0-SDK_VERSION": sdk_version},
visibility = ["//visibility:public"],
deps = [
"daml-json-types",
Expand Down
2 changes: 1 addition & 1 deletion language-support/ts/daml-json-types/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@digitalasset/daml-json-types",
"version": "0.0.1",
"version": "0.0.0-SDK_VERSION",
"description": "Types used by the DAML JSON API.",
"main": "index.js",
"types": "index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions language-support/ts/daml-ledger-fetch/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
load("@npm_bazel_typescript//:index.bzl", "ts_library")
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
load("//language-support/ts:eslint.bzl", "eslint_test")
load("@sdk_version//:sdk_version.bzl", "sdk_version")

ts_library(
name = "daml-ledger-fetch",
Expand Down Expand Up @@ -44,6 +45,7 @@ pkg_npm(
":package.json",
":tsconfig.json",
],
substitutions = {"0.0.0-SDK_VERSION": sdk_version},
visibility = ["//visibility:public"],
deps = [
"daml-ledger-fetch",
Expand Down
4 changes: 2 additions & 2 deletions language-support/ts/daml-ledger-fetch/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"private": true,
"name": "@digitalasset/daml-ledger-fetch",
"version": "0.0.1",
"version": "0.0.0-SDK_VERSION",
"description": "Wrappers around DAML's JSON API.",
"main": "index.js",
"types": "index.d.ts",
"license": "Apache-2.0",
"dependencies": {
"@digitalasset/daml-json-types": "0.0.1",
"@digitalasset/daml-json-types": "0.0.0-SDK_VERSION",
"@mojotech/json-type-validation": "^3.1.0",
"cross-fetch": "^3.0.4"
},
Expand Down

0 comments on commit ad93252

Please sign in to comment.