mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 01:07:18 +03:00
df7bff6288
* Bazel: 0.24.0 -> 0.27.0 * Update rules_haskell for Bazel 0.27 compatibility * Update bazel-deps and bazel-watcher * Windows escape JVM flags * load commands at top of .bzl file Bazel 0.27 no longer allows load commands that are not at the beginning of the file. * Update Bazel rules * subpackage boundary * native is not defined in BUILD files * yarn: @bazel/hide-bazel-files Seems to be required since latest rules_nodejs version. Otherwise, yarn fails with errors about existing BUILD or BUILD.bazel files. * grpc-java plugin visibility * Update fat_cc_library * Nix Python3 toolchain * Iteration over depset * dev_env_package: Create symlinks one level deeper To prevent symlinking the BUILD file as well. The nested BUILD file confuses Bazel as of 0.27 and rules_nodejs cannot find the node executable anymore. * Update rules_nodejs * Add managed_directories for node_modules * hie-bios: Extract bazel-genfiles from bazel info Bazel 0.27 changed the genfiles location which breaks the hie-core test on macOS. * update cc_wrapper to Bazel 0.27 * bazel info -> bazel info bazel-genfiles * Fix typo in BUILD Co-Authored-By: Stefano Baghino <43749967+stefanobaghino-da@users.noreply.github.com>
106 lines
3.5 KiB
Python
106 lines
3.5 KiB
Python
# Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
"""Packaging of Linux, macOS and Windows binaries into tarballs"""
|
|
|
|
load("@os_info//:os_info.bzl", "is_windows")
|
|
|
|
def _package_app_impl(ctx):
|
|
files = depset(ctx.attr.binary.files)
|
|
runfiles = ctx.attr.binary.default_runfiles.files
|
|
datafiles = ctx.attr.binary[DefaultInfo].data_runfiles.files
|
|
|
|
args = ctx.actions.args()
|
|
inputs = depset([], transitive = [files, runfiles, datafiles] + [r.files for r in ctx.attr.resources])
|
|
tools = [ctx.executable.tar, ctx.executable.gzip] if is_windows else [ctx.executable.patchelf, ctx.executable.tar, ctx.executable.gzip]
|
|
ctx.actions.run_shell(
|
|
outputs = [ctx.outputs.out],
|
|
tools = [ctx.executable.package_app] + tools,
|
|
inputs = inputs.to_list(),
|
|
arguments = [args],
|
|
progress_message = "Packaging " + ctx.attr.name,
|
|
command = """
|
|
set -eu
|
|
export PATH=$PATH:{path}
|
|
{package_app} \
|
|
"$PWD/{binary}" \
|
|
"$PWD/{output}" \
|
|
{resources}
|
|
""".format(
|
|
path = ":".join(["$PWD/`dirname {tool}`".format(tool = tool.path) for tool in tools]),
|
|
output = ctx.outputs.out.path,
|
|
name = ctx.attr.name,
|
|
package_app = ctx.executable.package_app.path,
|
|
binary = ctx.executable.binary.path,
|
|
resources = " ".join([
|
|
_get_resource_path(r)
|
|
for r in ctx.attr.resources
|
|
]),
|
|
),
|
|
)
|
|
|
|
def _get_resource_path(r):
|
|
"""Get the path to use for a resource.
|
|
If the resource has a single file, it'll be copied to
|
|
the resource root directory. With multiple files the
|
|
relative directory structure is preserved.
|
|
|
|
This mirrors how rules that produce directories work
|
|
in Buck.
|
|
"""
|
|
files = r.files.to_list()
|
|
if len(files) > 1:
|
|
first_file = files[0].path
|
|
prefix_end = first_file.index(r.label.package)
|
|
|
|
# e.g. package foo/bar,
|
|
# first file at bazel-out/k8-fastbuild/bleh/foo/bar/baz/quux
|
|
# return path as bazel-out/k8-fastbuild/bleh/foo/bar.
|
|
return first_file[0:(prefix_end + len(r.label.package))]
|
|
else:
|
|
return files[0].path
|
|
|
|
package_app = rule(
|
|
implementation = _package_app_impl,
|
|
attrs = dict({
|
|
"binary": attr.label(
|
|
cfg = "target",
|
|
executable = True,
|
|
allow_files = True,
|
|
),
|
|
"resources": attr.label_list(
|
|
allow_files = True,
|
|
),
|
|
"patchelf": attr.label(
|
|
default = None if is_windows else Label("@patchelf_nix//:bin/patchelf"),
|
|
cfg = "host",
|
|
executable = True,
|
|
allow_files = True,
|
|
),
|
|
"tar": attr.label(
|
|
default = Label("@tar_dev_env//:tar"),
|
|
cfg = "host",
|
|
executable = True,
|
|
allow_files = True,
|
|
),
|
|
"gzip": attr.label(
|
|
default = Label("@gzip_dev_env//:gzip"),
|
|
cfg = "host",
|
|
executable = True,
|
|
allow_files = True,
|
|
),
|
|
"package_app": attr.label(
|
|
default = Label("//bazel_tools/packaging:package-app.sh"),
|
|
cfg = "host",
|
|
executable = True,
|
|
allow_files = True,
|
|
),
|
|
}),
|
|
outputs = {
|
|
"out": "%{name}.tar.gz",
|
|
},
|
|
)
|
|
"""Package a binary along with its dynamic library dependencies and data dependencies
|
|
into a tarball. The data dependencies are placed in 'resources' directory.
|
|
"""
|