daml/bazel_tools/build_environment.bzl
Gary Verhaegen f025dc3065
daml-sdk-head: add optional sha information (#7717)
daml-sdk-head: add optional sha information

This PR add an option, `--sha`, to `daml-sdk-head` so that it produces a
more accurate version number including the current git sha.

The main consequence is that calling `daml-sdk-head --sha` take
significantly longer than calling `daml-sdk-head`, because it needs to
recompile everything that depends on the version number.

> ## Wait, but why??

I started this work in support of an internal project that needed to
test against unreleased, and possibly unmerged, daml versions. However,
after further discussion I believe there is a better option for their
use-case. I've decided to still open this PR because the work was done
and there is no downside to it. It may still be useful if one wanted to
be able to maintain more than one non-released local version of daml.

CHANGELOG_BEGIN
CHANGELOG_END
2020-10-16 16:40:58 +02:00

43 lines
1.3 KiB
Python

# Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
def _impl(ctx):
# Generates an empty BUILD file, because we do not need to build anything.
ctx.file(
"BUILD",
content = "",
executable = False,
)
# Generates a simple Bazel file that just sets a bunch of Bazel variables,
# so they can be used in our main Bazel BUILD files.
semver = ctx.os.environ.get("DAML_SDK_RELEASE_VERSION", default = "0.0.0")
if semver.find("-") > 0:
ghc = ".".join([segment for segment in semver.replace("-", ".").split(".") if segment.isdigit()])
else:
ghc = semver
ctx.file(
"configuration.bzl",
content =
"""
npm_version = "{NPM_VERSION}"
mvn_version = "{MVN_VERSION}"
ghc_version = "{GHC_VERSION}"
sdk_version = "{SDK_VERSION}"
""".format(
SDK_VERSION = semver,
NPM_VERSION = semver,
MVN_VERSION = semver,
GHC_VERSION = ghc,
),
executable = False,
)
build_environment = repository_rule(
# Tell Bazel that this rule will produce different results if any of the
# env vars in the list has changed.
environ = ["DAML_SDK_RELEASE_VERSION"],
implementation = _impl,
attrs = {},
)