2021-01-01 21:49:51 +03:00
|
|
|
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
2019-04-04 11:33:38 +03:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2020-03-19 02:06:55 +03:00
|
|
|
load("@build_environment//:configuration.bzl", "ghc_version", "sdk_version")
|
2020-07-23 10:46:04 +03:00
|
|
|
load("//bazel_tools/sh:sh.bzl", "sh_inline_test")
|
2021-11-22 19:20:17 +03:00
|
|
|
load("//daml-lf/language:daml-lf.bzl", "COMPILER_LF_VERSIONS")
|
2020-03-19 02:06:55 +03:00
|
|
|
|
|
|
|
_damlc = attr.label(
|
2021-03-17 12:31:37 +03:00
|
|
|
default = Label("//compiler/damlc:damlc-compile-only"),
|
2020-03-19 02:06:55 +03:00
|
|
|
executable = True,
|
|
|
|
cfg = "host",
|
|
|
|
doc = "The DAML compiler.",
|
|
|
|
)
|
|
|
|
|
|
|
|
_zipper = attr.label(
|
|
|
|
allow_single_file = True,
|
|
|
|
default = Label("@bazel_tools//tools/zip:zipper"),
|
|
|
|
executable = True,
|
|
|
|
cfg = "host",
|
|
|
|
)
|
2019-04-04 11:33:38 +03:00
|
|
|
|
2020-03-19 02:06:55 +03:00
|
|
|
def _daml_configure_impl(ctx):
|
|
|
|
project_name = ctx.attr.project_name
|
|
|
|
project_version = ctx.attr.project_version
|
|
|
|
daml_yaml = ctx.outputs.daml_yaml
|
|
|
|
target = ctx.attr.target
|
2021-11-03 16:22:57 +03:00
|
|
|
opts = ["--target={}".format(target)] if target else []
|
2020-03-19 02:06:55 +03:00
|
|
|
ctx.actions.write(
|
|
|
|
output = daml_yaml,
|
|
|
|
content = """
|
|
|
|
sdk-version: {sdk}
|
|
|
|
name: {name}
|
|
|
|
version: {version}
|
|
|
|
source: .
|
|
|
|
dependencies: []
|
2021-03-04 21:08:59 +03:00
|
|
|
build-options: [{opts} ]
|
2020-03-19 02:06:55 +03:00
|
|
|
""".format(
|
|
|
|
sdk = sdk_version,
|
|
|
|
name = project_name,
|
|
|
|
version = project_version,
|
2021-03-04 21:08:59 +03:00
|
|
|
opts = ", ".join(opts),
|
2020-03-19 02:06:55 +03:00
|
|
|
),
|
2019-04-04 11:33:38 +03:00
|
|
|
)
|
|
|
|
|
2020-03-19 02:06:55 +03:00
|
|
|
_daml_configure = rule(
|
|
|
|
implementation = _daml_configure_impl,
|
|
|
|
attrs = {
|
|
|
|
"project_name": attr.string(
|
|
|
|
mandatory = True,
|
|
|
|
doc = "Name of the DAML project.",
|
|
|
|
),
|
|
|
|
"project_version": attr.string(
|
|
|
|
mandatory = True,
|
|
|
|
doc = "Version of the DAML project.",
|
|
|
|
),
|
|
|
|
"daml_yaml": attr.output(
|
|
|
|
mandatory = True,
|
|
|
|
doc = "The generated daml.yaml config file.",
|
|
|
|
),
|
|
|
|
"target": attr.string(
|
|
|
|
doc = "DAML-LF version to output.",
|
|
|
|
),
|
|
|
|
},
|
|
|
|
)
|
2019-04-12 14:10:16 +03:00
|
|
|
|
2020-03-19 02:06:55 +03:00
|
|
|
def file_of_target(k):
|
|
|
|
[file] = k.files.to_list()
|
|
|
|
return file
|
|
|
|
|
|
|
|
def make_cp_command(src, dest):
|
|
|
|
return "mkdir -p $(dirname {dest}); cp -f {src} {dest}".format(
|
|
|
|
src = src,
|
|
|
|
dest = dest,
|
|
|
|
)
|
|
|
|
|
|
|
|
def _daml_build_impl(ctx):
|
|
|
|
name = ctx.label.name
|
|
|
|
daml_yaml = ctx.file.daml_yaml
|
|
|
|
srcs = ctx.files.srcs
|
|
|
|
dar_dict = ctx.attr.dar_dict
|
2021-11-22 19:20:17 +03:00
|
|
|
damlc = ctx.executable.damlc
|
2020-03-19 02:06:55 +03:00
|
|
|
input_dars = [file_of_target(k) for k in dar_dict.keys()]
|
|
|
|
output_dar = ctx.outputs.dar
|
2020-04-07 23:17:55 +03:00
|
|
|
posix = ctx.toolchains["@rules_sh//sh/posix:toolchain_type"]
|
2021-08-17 19:59:12 +03:00
|
|
|
ghc_opts = ctx.attr.ghc_options
|
2020-03-19 02:06:55 +03:00
|
|
|
ctx.actions.run_shell(
|
|
|
|
tools = [damlc],
|
|
|
|
inputs = [daml_yaml] + srcs + input_dars,
|
|
|
|
outputs = [output_dar],
|
|
|
|
progress_message = "Building DAML project %s" % name,
|
|
|
|
command = """
|
|
|
|
set -eou pipefail
|
|
|
|
tmpdir=$(mktemp -d)
|
|
|
|
trap "rm -rf $tmpdir" EXIT
|
|
|
|
cp -f {config} $tmpdir/daml.yaml
|
2020-04-07 23:17:55 +03:00
|
|
|
# Having to produce all the daml.yaml files via a genrule is annoying
|
|
|
|
# so we allow hardcoded version numbers and patch them here.
|
|
|
|
{sed} -i 's/^sdk-version:.*$/sdk-version: {sdk_version}/' $tmpdir/daml.yaml
|
2020-03-19 02:06:55 +03:00
|
|
|
{cp_srcs}
|
|
|
|
{cp_dars}
|
2021-03-04 21:08:59 +03:00
|
|
|
{damlc} build --project-root $tmpdir {ghc_opts} -o $PWD/{output_dar}
|
2020-03-19 02:06:55 +03:00
|
|
|
""".format(
|
|
|
|
config = daml_yaml.path,
|
|
|
|
cp_srcs = "\n".join([
|
|
|
|
make_cp_command(
|
|
|
|
src = src.path,
|
|
|
|
dest = "$tmpdir/" + src.path,
|
|
|
|
)
|
|
|
|
for src in srcs
|
|
|
|
]),
|
|
|
|
cp_dars = "\n".join([
|
|
|
|
make_cp_command(
|
|
|
|
src = file_of_target(k).path,
|
|
|
|
dest = "$tmpdir/" + v,
|
|
|
|
)
|
|
|
|
for k, v in dar_dict.items()
|
|
|
|
]),
|
2020-04-07 23:17:55 +03:00
|
|
|
sed = posix.commands["sed"],
|
2020-03-19 02:06:55 +03:00
|
|
|
damlc = damlc.path,
|
|
|
|
output_dar = output_dar.path,
|
2020-04-07 23:17:55 +03:00
|
|
|
sdk_version = sdk_version,
|
2021-03-04 21:08:59 +03:00
|
|
|
ghc_opts = " ".join(ghc_opts),
|
2020-03-19 02:06:55 +03:00
|
|
|
),
|
2019-04-04 11:33:38 +03:00
|
|
|
)
|
2020-03-19 02:06:55 +03:00
|
|
|
|
|
|
|
_daml_build = rule(
|
|
|
|
implementation = _daml_build_impl,
|
2019-04-04 11:33:38 +03:00
|
|
|
attrs = {
|
2020-03-19 02:06:55 +03:00
|
|
|
"daml_yaml": attr.label(
|
|
|
|
allow_single_file = True,
|
2019-04-04 11:33:38 +03:00
|
|
|
mandatory = True,
|
2020-03-19 02:06:55 +03:00
|
|
|
doc = "The daml.yaml config file.",
|
2019-04-04 11:33:38 +03:00
|
|
|
),
|
|
|
|
"srcs": attr.label_list(
|
|
|
|
allow_files = [".daml"],
|
2020-03-19 02:06:55 +03:00
|
|
|
mandatory = True,
|
|
|
|
doc = "DAML files in this DAML project.",
|
|
|
|
),
|
|
|
|
"dar_dict": attr.label_keyed_string_dict(
|
|
|
|
mandatory = True,
|
2020-04-07 15:36:40 +03:00
|
|
|
allow_files = True,
|
2020-03-19 02:06:55 +03:00
|
|
|
doc = "Other DAML projects referenced by this DAML project.",
|
|
|
|
),
|
|
|
|
"dar": attr.output(
|
|
|
|
mandatory = True,
|
|
|
|
doc = "The generated DAR file.",
|
|
|
|
),
|
2021-08-17 19:59:12 +03:00
|
|
|
"ghc_options": attr.string_list(
|
|
|
|
doc = "Options passed to GHC.",
|
2021-11-03 16:22:57 +03:00
|
|
|
default = ["--ghc-option=-Werror", "--ghc-option=-Wwarn", "--log-level=WARNING"],
|
2021-08-17 19:59:12 +03:00
|
|
|
),
|
2021-11-22 19:20:17 +03:00
|
|
|
"damlc": _damlc,
|
2020-03-19 02:06:55 +03:00
|
|
|
},
|
2020-04-07 23:17:55 +03:00
|
|
|
toolchains = ["@rules_sh//sh/posix:toolchain_type"],
|
2020-03-19 02:06:55 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
def _extract_main_dalf_impl(ctx):
|
|
|
|
project_name = ctx.attr.project_name
|
|
|
|
project_version = ctx.attr.project_version
|
|
|
|
input_dar = ctx.file.dar
|
|
|
|
output_dalf = ctx.outputs.dalf
|
|
|
|
zipper = ctx.file._zipper
|
|
|
|
posix = ctx.toolchains["@rules_sh//sh/posix:toolchain_type"]
|
|
|
|
ctx.actions.run_shell(
|
|
|
|
tools = [zipper],
|
|
|
|
inputs = [input_dar],
|
|
|
|
outputs = [output_dalf],
|
|
|
|
progress_message = "Extract DALF from DAR (%s)" % project_name,
|
|
|
|
command = """
|
2021-11-03 16:22:57 +03:00
|
|
|
set -eou pipefail
|
2020-04-30 16:09:04 +03:00
|
|
|
TMPDIR=$(mktemp -d)
|
|
|
|
trap "rm -rf $TMPDIR" EXIT
|
|
|
|
# While zipper has a -d option, it insists on it
|
|
|
|
# being a relative path so we don't use it.
|
|
|
|
ZIPPER=$PWD/{zipper}
|
|
|
|
DAR=$PWD/{input_dar}
|
|
|
|
(cd $TMPDIR && $ZIPPER x $DAR)
|
|
|
|
main_dalf=$({find} $TMPDIR/ -name '{project_name}-{project_version}-[a-z0-9]*.dalf')
|
|
|
|
cp $main_dalf {output_dalf}
|
2020-03-19 02:06:55 +03:00
|
|
|
""".format(
|
|
|
|
zipper = zipper.path,
|
|
|
|
find = posix.commands["find"],
|
|
|
|
project_name = project_name,
|
|
|
|
project_version = project_version,
|
|
|
|
input_dar = input_dar.path,
|
|
|
|
output_dalf = output_dalf.path,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
_extract_main_dalf = rule(
|
|
|
|
implementation = _extract_main_dalf_impl,
|
|
|
|
attrs = {
|
|
|
|
"project_name": attr.string(
|
|
|
|
mandatory = True,
|
|
|
|
doc = "Name of the DAML project.",
|
|
|
|
),
|
|
|
|
"project_version": attr.string(
|
|
|
|
mandatory = True,
|
|
|
|
doc = "Version of the DAML project.",
|
|
|
|
),
|
|
|
|
"dar": attr.label(
|
|
|
|
allow_single_file = [".dar"],
|
|
|
|
mandatory = True,
|
|
|
|
doc = "The DAR from which the DALF will be extracted.",
|
2019-04-04 11:33:38 +03:00
|
|
|
),
|
2020-03-19 02:06:55 +03:00
|
|
|
"dalf": attr.output(
|
|
|
|
mandatory = True,
|
|
|
|
doc = "The extracted DALF.",
|
2019-04-04 11:33:38 +03:00
|
|
|
),
|
2020-03-19 02:06:55 +03:00
|
|
|
"_zipper": _zipper,
|
2019-04-04 11:33:38 +03:00
|
|
|
},
|
2020-03-19 02:06:55 +03:00
|
|
|
toolchains = ["@rules_sh//sh/posix:toolchain_type"],
|
2019-04-04 11:33:38 +03:00
|
|
|
)
|
|
|
|
|
2020-07-23 10:46:04 +03:00
|
|
|
def _daml_validate_test(
|
|
|
|
name,
|
|
|
|
dar,
|
|
|
|
**kwargs):
|
2021-03-17 12:31:37 +03:00
|
|
|
damlc = "//compiler/damlc:damlc-compile-only"
|
2020-07-23 10:46:04 +03:00
|
|
|
sh_inline_test(
|
|
|
|
name = name,
|
|
|
|
data = [damlc, dar],
|
|
|
|
cmd = """\
|
|
|
|
DAMLC=$$(canonicalize_rlocation $(rootpath {damlc}))
|
2020-03-19 02:06:55 +03:00
|
|
|
|
2020-07-23 10:46:04 +03:00
|
|
|
$$DAMLC validate-dar $$(canonicalize_rlocation $(rootpath {dar}))
|
|
|
|
""".format(
|
|
|
|
damlc = damlc,
|
|
|
|
dar = dar,
|
2020-03-19 02:06:55 +03:00
|
|
|
),
|
2020-07-23 10:46:04 +03:00
|
|
|
**kwargs
|
|
|
|
)
|
2020-03-19 02:06:55 +03:00
|
|
|
|
2021-11-30 19:24:08 +03:00
|
|
|
def _inspect_dar_impl(ctx):
|
|
|
|
dar = ctx.file.dar
|
|
|
|
damlc = ctx.executable.damlc
|
|
|
|
pp = ctx.outputs.pp
|
|
|
|
ctx.actions.run(
|
|
|
|
executable = damlc,
|
|
|
|
inputs = [dar],
|
|
|
|
outputs = [pp],
|
|
|
|
arguments = ["inspect", dar.path, "-o", pp.path],
|
2020-05-21 14:06:51 +03:00
|
|
|
)
|
|
|
|
|
2021-11-30 19:24:08 +03:00
|
|
|
_inspect_dar = rule(
|
|
|
|
implementation = _inspect_dar_impl,
|
|
|
|
attrs = {
|
|
|
|
"dar": attr.label(
|
|
|
|
allow_single_file = True,
|
|
|
|
mandatory = True,
|
|
|
|
),
|
|
|
|
"damlc": _damlc,
|
|
|
|
"pp": attr.output(mandatory = True),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2020-03-19 02:06:55 +03:00
|
|
|
_default_project_version = "1.0.0"
|
|
|
|
|
2021-11-03 16:22:57 +03:00
|
|
|
default_damlc_opts = ["--ghc-option=-Werror", "--ghc-option=-Wwarn", "--log-level=WARNING"]
|
|
|
|
|
2021-11-22 19:20:17 +03:00
|
|
|
def damlc_for_target(target):
|
|
|
|
if not target or target in COMPILER_LF_VERSIONS:
|
|
|
|
return "//compiler/damlc:damlc-compile-only"
|
|
|
|
else:
|
|
|
|
return "@damlc_legacy//:damlc_legacy"
|
|
|
|
|
2020-03-19 02:06:55 +03:00
|
|
|
def daml_compile(
|
|
|
|
name,
|
|
|
|
srcs,
|
|
|
|
version = _default_project_version,
|
|
|
|
target = None,
|
2021-02-22 13:41:19 +03:00
|
|
|
project_name = None,
|
2021-11-03 16:22:57 +03:00
|
|
|
ghc_options = default_damlc_opts,
|
2020-03-19 02:06:55 +03:00
|
|
|
**kwargs):
|
|
|
|
"Build a DAML project, with a generated daml.yaml."
|
|
|
|
if len(srcs) == 0:
|
|
|
|
fail("daml_compile: Expected `srcs' to be non-empty.")
|
|
|
|
daml_yaml = name + ".yaml"
|
|
|
|
_daml_configure(
|
|
|
|
name = name + ".configure",
|
2021-02-22 13:41:19 +03:00
|
|
|
project_name = project_name or name,
|
2020-03-19 02:06:55 +03:00
|
|
|
project_version = version,
|
|
|
|
daml_yaml = daml_yaml,
|
|
|
|
target = target,
|
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
_daml_build(
|
|
|
|
name = name + ".build",
|
|
|
|
daml_yaml = daml_yaml,
|
|
|
|
srcs = srcs,
|
|
|
|
dar_dict = {},
|
|
|
|
dar = name + ".dar",
|
2021-11-03 16:22:57 +03:00
|
|
|
ghc_options = ghc_options,
|
2021-11-22 19:20:17 +03:00
|
|
|
damlc = damlc_for_target(target),
|
2020-03-19 02:06:55 +03:00
|
|
|
**kwargs
|
|
|
|
)
|
2020-05-21 14:06:51 +03:00
|
|
|
_inspect_dar(
|
2021-11-30 19:24:08 +03:00
|
|
|
name = "{}-inspect".format(name),
|
|
|
|
dar = "{}.dar".format(name),
|
|
|
|
pp = "{}.dar.pp".format(name),
|
|
|
|
damlc = damlc_for_target(target),
|
2020-05-21 14:06:51 +03:00
|
|
|
)
|
2020-03-19 02:06:55 +03:00
|
|
|
|
|
|
|
def daml_compile_with_dalf(
|
|
|
|
name,
|
|
|
|
version = _default_project_version,
|
|
|
|
**kwargs):
|
|
|
|
"Build a DAML project, with a generated daml.yaml, and extract the main DALF."
|
|
|
|
daml_compile(
|
|
|
|
name = name,
|
|
|
|
version = version,
|
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
_extract_main_dalf(
|
|
|
|
name = name + ".extract",
|
|
|
|
project_name = name,
|
|
|
|
project_version = version,
|
|
|
|
dar = name + ".dar",
|
|
|
|
dalf = name + ".dalf",
|
|
|
|
)
|
|
|
|
|
|
|
|
def daml_build_test(
|
|
|
|
name,
|
|
|
|
project_dir,
|
|
|
|
daml_config_basename = "daml.yaml",
|
|
|
|
daml_subdir_basename = "daml",
|
2020-09-29 19:34:21 +03:00
|
|
|
daml_yaml = None,
|
2020-03-19 02:06:55 +03:00
|
|
|
dar_dict = {},
|
2021-11-03 16:22:57 +03:00
|
|
|
ghc_options = default_damlc_opts,
|
2020-03-19 02:06:55 +03:00
|
|
|
**kwargs):
|
|
|
|
"Build a DAML project and validate the resulting .dar file."
|
2020-09-29 19:34:21 +03:00
|
|
|
if not daml_yaml:
|
|
|
|
daml_yaml = project_dir + "/" + daml_config_basename
|
2020-03-19 02:06:55 +03:00
|
|
|
srcs = native.glob([project_dir + "/" + daml_subdir_basename + "/**/*.daml"])
|
|
|
|
_daml_build(
|
|
|
|
name = name,
|
|
|
|
daml_yaml = daml_yaml,
|
|
|
|
srcs = srcs,
|
|
|
|
dar_dict = dar_dict,
|
|
|
|
dar = name + ".dar",
|
2021-11-03 16:22:57 +03:00
|
|
|
ghc_options = ghc_options,
|
2020-03-19 02:06:55 +03:00
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
_daml_validate_test(
|
|
|
|
name = name + ".test",
|
|
|
|
dar = name + ".dar",
|
|
|
|
)
|
|
|
|
|
2020-07-23 10:46:04 +03:00
|
|
|
def daml_test(
|
|
|
|
name,
|
|
|
|
srcs = [],
|
2020-08-28 19:19:45 +03:00
|
|
|
deps = [],
|
2020-09-29 19:34:21 +03:00
|
|
|
data_deps = [],
|
2021-03-17 12:31:37 +03:00
|
|
|
damlc = "//compiler/damlc:damlc",
|
2020-11-18 22:51:15 +03:00
|
|
|
target = None,
|
2020-07-23 10:46:04 +03:00
|
|
|
**kwargs):
|
|
|
|
sh_inline_test(
|
|
|
|
name = name,
|
2020-09-29 19:34:21 +03:00
|
|
|
data = [damlc] + srcs + deps + data_deps,
|
2020-07-23 10:46:04 +03:00
|
|
|
cmd = """\
|
2021-11-03 16:22:57 +03:00
|
|
|
set -eou pipefail
|
2020-08-28 19:19:45 +03:00
|
|
|
tmpdir=$$(mktemp -d)
|
|
|
|
trap "rm -rf $$tmpdir" EXIT
|
2020-07-23 10:46:04 +03:00
|
|
|
DAMLC=$$(canonicalize_rlocation $(rootpath {damlc}))
|
|
|
|
rlocations () {{ for i in $$@; do echo $$(canonicalize_rlocation $$i); done; }}
|
2020-08-28 19:19:45 +03:00
|
|
|
DEPS=($$(rlocations {deps}))
|
2020-09-29 19:34:21 +03:00
|
|
|
DATA_DEPS=($$(rlocations {data_deps}))
|
|
|
|
JOINED_DATA_DEPS="$$(printf ',"%s"' $${{DATA_DEPS[@]}})"
|
|
|
|
echo "$$JOINED_DATA_DEPS"
|
2020-08-28 19:19:45 +03:00
|
|
|
cat << EOF > $$tmpdir/daml.yaml
|
2020-11-18 22:51:15 +03:00
|
|
|
build-options: [{target}]
|
2020-08-28 19:19:45 +03:00
|
|
|
sdk-version: {sdk_version}
|
|
|
|
name: test
|
|
|
|
version: 0.0.1
|
|
|
|
source: .
|
|
|
|
dependencies: [daml-stdlib, daml-prim $$([ $${{#DEPS[@]}} -gt 0 ] && printf ',"%s"' $${{DEPS[@]}})]
|
2020-09-29 19:34:21 +03:00
|
|
|
data-dependencies: [$$([ $${{#DATA_DEPS[@]}} -gt 0 ] && printf '%s' $${{JOINED_DATA_DEPS:1}})]
|
2020-08-28 19:19:45 +03:00
|
|
|
EOF
|
2020-09-29 19:34:21 +03:00
|
|
|
cat $$tmpdir/daml.yaml
|
2020-08-28 19:19:45 +03:00
|
|
|
{cp_srcs}
|
|
|
|
cd $$tmpdir
|
|
|
|
$$DAMLC test --files {files}
|
2020-07-23 10:46:04 +03:00
|
|
|
""".format(
|
|
|
|
damlc = damlc,
|
|
|
|
files = " ".join(["$(rootpaths %s)" % src for src in srcs]),
|
2020-08-28 19:19:45 +03:00
|
|
|
sdk_version = sdk_version,
|
|
|
|
deps = " ".join(["$(rootpaths %s)" % dep for dep in deps]),
|
2020-09-29 19:34:21 +03:00
|
|
|
data_deps = " ".join(["$(rootpaths %s)" % dep for dep in data_deps]),
|
2020-08-28 19:19:45 +03:00
|
|
|
cp_srcs = "\n".join([
|
|
|
|
"mkdir -p $$(dirname {dest}); cp -f {src} {dest}".format(
|
|
|
|
src = "$$(canonicalize_rlocation $(rootpath {}))".format(src),
|
|
|
|
dest = "$$tmpdir/$(rootpath {})".format(src),
|
|
|
|
)
|
|
|
|
for src in srcs
|
|
|
|
]),
|
2020-11-18 22:51:15 +03:00
|
|
|
target = "--target=" + target if (target) else "",
|
2020-07-23 10:46:04 +03:00
|
|
|
),
|
|
|
|
**kwargs
|
2019-06-28 13:55:31 +03:00
|
|
|
)
|
2019-04-04 11:33:38 +03:00
|
|
|
|
2020-07-23 10:46:04 +03:00
|
|
|
def daml_doc_test(
|
|
|
|
name,
|
|
|
|
package_name,
|
|
|
|
srcs = [],
|
|
|
|
ignored_srcs = [],
|
|
|
|
flags = [],
|
|
|
|
cpp = "@stackage-exe//hpp",
|
2021-03-17 12:31:37 +03:00
|
|
|
damlc = "//compiler/damlc:damlc",
|
2020-07-23 10:46:04 +03:00
|
|
|
**kwargs):
|
|
|
|
sh_inline_test(
|
|
|
|
name = name,
|
|
|
|
data = [cpp, damlc] + srcs,
|
|
|
|
cmd = """\
|
2021-03-24 14:56:37 +03:00
|
|
|
set -eou pipefail
|
2020-07-23 10:46:04 +03:00
|
|
|
CPP=$$(canonicalize_rlocation $(rootpath {cpp}))
|
|
|
|
DAMLC=$$(canonicalize_rlocation $(rootpath {damlc}))
|
|
|
|
FILES=($$(
|
|
|
|
for file in {files}; do
|
2021-03-24 14:56:37 +03:00
|
|
|
IGNORED=false
|
2020-07-23 10:46:04 +03:00
|
|
|
for pattern in {ignored}; do
|
|
|
|
if [[ $$file = *$$pattern ]]; then
|
2021-03-24 14:56:37 +03:00
|
|
|
IGNORED=true
|
2020-07-23 10:46:04 +03:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
done
|
2021-03-24 14:56:37 +03:00
|
|
|
if [[ $$IGNORED == "false" ]]; then
|
|
|
|
echo $$(canonicalize_rlocation $$file)
|
|
|
|
fi
|
2020-07-23 10:46:04 +03:00
|
|
|
done
|
|
|
|
))
|
2019-04-04 11:33:38 +03:00
|
|
|
|
2020-07-23 10:46:04 +03:00
|
|
|
$$DAMLC doctest {flags} --cpp $$CPP --package-name {package_name}-{version} "$${{FILES[@]}}"
|
|
|
|
""".format(
|
|
|
|
cpp = cpp,
|
|
|
|
damlc = damlc,
|
|
|
|
package_name = package_name,
|
|
|
|
flags = " ".join(flags),
|
|
|
|
version = ghc_version,
|
|
|
|
files = " ".join(["$(rootpaths %s)" % src for src in srcs]),
|
|
|
|
ignored = " ".join(ignored_srcs),
|
2019-04-12 14:10:16 +03:00
|
|
|
),
|
2020-07-23 10:46:04 +03:00
|
|
|
**kwargs
|
2019-07-16 16:51:01 +03:00
|
|
|
)
|