From bba714a5ba9575a6086ddce186e2a80eb13d8ece Mon Sep 17 00:00:00 2001 From: kczulko Date: Mon, 23 Sep 2024 19:55:47 +0200 Subject: [PATCH] fix: use python instead gzip+chmod (#59) --- BUILD.bazel | 1 + elm/repositories.bzl | 5 ++++- examples/BUILD.bazel | 4 ++-- tools/gzip/BUILD.bazel | 14 ++++++++++++++ tools/gzip/gzip.py | 15 +++++++++++++++ 5 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 tools/gzip/BUILD.bazel create mode 100644 tools/gzip/gzip.py diff --git a/BUILD.bazel b/BUILD.bazel index 5857f51..e076d13 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -15,6 +15,7 @@ filegroup( "//tools/tests-runner:all_files", "//tools/tests-placeholder-repairer:all_files", "//tools/protoc-gen-elm:all_files", + "//tools/gzip:all_files", ], visibility = ["//visibility:public"], ) diff --git a/elm/repositories.bzl b/elm/repositories.bzl index bde19f0..a56fdbe 100644 --- a/elm/repositories.bzl +++ b/elm/repositories.bzl @@ -66,7 +66,10 @@ genrule( name = "extract_elm_compiler", srcs = [":compiler.gz"], outs = [ "compiler" ], - cmd = "gzip -d -c $(SRCS) > $@ && chmod +x $@" + tools = [ + "@rules_elm//tools/gzip:bin", + ], + cmd = "$(execpath @rules_elm//tools/gzip:bin) $(SRCS) $@", ) elm_toolchain( diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel index c5b90d4..9edab35 100644 --- a/examples/BUILD.bazel +++ b/examples/BUILD.bazel @@ -24,7 +24,7 @@ rules_elm_integration_test_each_bazel( bazel_binaries = bazel_binaries, workspace_path = "elm-binary", bazel_cmd = "build :main", - expected_output = "INFO: Build completed successfully, (8|7) total actions", + expected_output = "INFO: Build completed successfully, .. total actions", # sometimes it fails with an error: # 0.19.1/d.dat: openBinaryFile: resource busy (file is locked) flaky = True, @@ -60,7 +60,7 @@ rules_elm_integration_test_each_bazel( test_runner = ":output_match_runner", workspace_path = "elm-todomvc", bazel_cmd = "build :bin", - expected_output = """INFO: Build completed successfully, (7|8) total actions""", + expected_output = """INFO: Build completed successfully, .. total actions""", ) rules_elm_integration_test_each_bazel( diff --git a/tools/gzip/BUILD.bazel b/tools/gzip/BUILD.bazel new file mode 100644 index 0000000..2b42285 --- /dev/null +++ b/tools/gzip/BUILD.bazel @@ -0,0 +1,14 @@ +load("@rules_python//python:defs.bzl", "py_binary") + +py_binary( + name = "bin", + main = ":gzip.py", + srcs = ["gzip.py"], + visibility = ["//visibility:public"], +) + +filegroup( + name = "all_files", + srcs = glob(["*"]), + visibility = ["//:__subpackages__"], +) diff --git a/tools/gzip/gzip.py b/tools/gzip/gzip.py new file mode 100644 index 0000000..3dc9ddd --- /dev/null +++ b/tools/gzip/gzip.py @@ -0,0 +1,15 @@ +import sys +import os +import gzip + +( + compressed_filepath, + decompressed_filepath, +) = sys.argv[1:3] + +with open(decompressed_filepath, "xb") as decompressed: + with gzip.open(compressed_filepath, 'rb') as compressed: + decompressed.write(compressed.read()) + +os.chmod(decompressed_filepath, 0o555) +