Skip to content

Commit

Permalink
No longer require sha256sum cli tool to be present on the host
Browse files Browse the repository at this point in the history
in the `erlang_build` rule

Relates to #226
  • Loading branch information
pjk25 committed Aug 29, 2023
1 parent 975a83f commit 3bca649
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
26 changes: 19 additions & 7 deletions private/erlang_build.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
load(
"@bazel_tools//tools/build_defs/hash:hash.bzl",
"sha256",
"tools",
)
load(
"@bazel_skylib//rules:common_settings.bzl",
"BuildSettingInfo",
Expand Down Expand Up @@ -67,34 +72,38 @@ def _erlang_build_impl(ctx):
command = """set -euo pipefail
curl -L "{archive_url}" -o {archive_path}
if [ -n "{sha256}" ]; then
echo "{sha256} {archive_path}" | sha256sum --check --strict -
fi
""".format(
archive_url = ctx.attr.url,
archive_path = downloaded_archive.path,
sha256 = ctx.attr.sha256,
),
mnemonic = "OTP",
progress_message = "Downloading {}".format(ctx.attr.url),
)

sha256file = sha256(ctx, downloaded_archive)

# zipper = ctx.executable._zipper

strip_prefix = ctx.attr.strip_prefix
if strip_prefix != "":
strip_prefix += "\\/"

ctx.actions.run_shell(
inputs = [downloaded_archive],
inputs = [downloaded_archive, sha256file],
outputs = [
build_dir_tar,
build_log,
release_dir_tar,
],
command = """set -euo pipefail
if [ -n "{sha256}" ]; then
if [ "{sha256}" != "$(cat "{sha256file}")" ]; then
echo "ERROR: Checksum mismatch. $(basename "{archive_path}") $(cat "{sha256file}") != {sha256}"
exit 1
fi
fi
ABS_BUILD_DIR_TAR=$PWD/{build_path}
ABS_RELEASE_DIR_TAR=$PWD/{release_path}
ABS_LOG=$PWD/{build_log}
Expand Down Expand Up @@ -131,6 +140,8 @@ tar --create \\
--file $ABS_RELEASE_DIR_TAR \\
*
""".format(
sha256 = ctx.attr.sha256v,
sha256file = sha256file.path,
archive_path = downloaded_archive.path,
strip_prefix = strip_prefix,
build_path = build_dir_tar.path,
Expand Down Expand Up @@ -199,14 +210,15 @@ erlang_build = rule(
"version": attr.string(mandatory = True),
"url": attr.string(mandatory = True),
"strip_prefix": attr.string(),
"sha256": attr.string(),
"sha256v": attr.string(),
"install_prefix": attr.string(default = DEFAULT_INSTALL_PREFIX),
"pre_configure_cmds": attr.string_list(),
"extra_configure_opts": attr.string_list(),
"post_configure_cmds": attr.string_list(),
"extra_make_opts": attr.string_list(
default = ["-j 8"],
),
"sha256": tools["sha256"],
},
)

Expand Down
2 changes: 1 addition & 1 deletion repositories/BUILD_internal.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ erlang_build(
version = "%{ERLANG_VERSION}",
url = "%{URL}",
strip_prefix = "%{STRIP_PREFIX}",
sha256 = "%{SHA_256}",
sha256v = "%{SHA_256}",
pre_configure_cmds = %{PRE_CONFIGURE_CMDS},
extra_configure_opts = %{EXTRA_CONFIGURE_OPTS},
post_configure_cmds = %{POST_CONFIGURE_CMDS},
Expand Down
2 changes: 1 addition & 1 deletion tools/erlang.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def erlang_toolchain_from_http_archive(
version = version,
url = url,
strip_prefix = strip_prefix,
sha256 = sha256,
sha256v = sha256,
extra_configure_opts = extra_configure_opts,
target_compatible_with = [
erlang_constraint,
Expand Down

0 comments on commit 3bca649

Please sign in to comment.