Skip to content

Commit

Permalink
fix: override the locale when running bsdtar actions (#2044)
Browse files Browse the repository at this point in the history
* fix: honor shell env on tar extract

Allows users to override the locale, needed for tarballs with filenames not supported by the system locale

* use lc_ctype

* wip: add snowman test

* fixup! use lc_ctype

* chore: update generated file

* update workspace snapshots

* revert short->long form flag

---------

Co-authored-by: Jason Bedard <jason+github@jbedard.ca>
  • Loading branch information
alexeagle and jbedard authored Jan 4, 2025
1 parent 976b6f4 commit 6b1dc20
Show file tree
Hide file tree
Showing 8 changed files with 4,007 additions and 3,664 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ js/private/test/js_run_devserver/package.json=-381403605
js/private/worker/src/package.json=-1243560410
npm/private/test/npm_package/package.json=-1991705133
npm/private/test/npm_package_publish/package.json=-646566766
npm/private/test/package.json=248936204
npm/private/test/package.json=606610593
npm/private/test/vendored/is-odd/package.json=1041695223
npm/private/test/vendored/lodash-4.17.21.tgz=-1206623349
npm/private/test/vendored/semver-max/package.json=578664053
package.json=1510979981
pnpm-lock.yaml=-1005187097
pnpm-lock.yaml=1372779172
pnpm-workspace.yaml=-1123429050
12 changes: 12 additions & 0 deletions npm/private/npm_package_store.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ If set, takes precendance over the package version in the NpmPackageInfo src.
"verbose": attr.bool(
doc = """If true, prints out verbose logs to stdout""",
),
"_macos_constraint": attr.label(default = "@platforms//os:macos"),
}

def _npm_package_store_impl(ctx):
Expand Down Expand Up @@ -223,6 +224,7 @@ def _npm_package_store_impl(ctx):
# tar to strip one directory level. Some packages have directory permissions missing
# executable which make the directories not listable (pngjs@5.0.0 for example).
bsdtar = ctx.toolchains["@aspect_bazel_lib//lib:tar_toolchain_type"]
is_macos = ctx.target_platform_has_constraint(ctx.attr._macos_constraint[platform_common.ConstraintValueInfo])
ctx.actions.run(
executable = bsdtar.tarinfo.binary,
inputs = depset(direct = [src], transitive = [bsdtar.default.files]),
Expand All @@ -240,6 +242,16 @@ def _npm_package_store_impl(ctx):
],
mnemonic = "NpmPackageExtract",
progress_message = "Extracting npm package {}@{}".format(package, version),
# Workaround https://github.com/bazelbuild/bazel-central-registry/issues/2256
# Always override the locale to give better hermeticity.
# See https://github.com/bazelbuild/rules_java/blob/767e4410850453a10ccf89aa1cededf9de05c72e/toolchains/utf8_environment.bzl
env = {
"LC_CTYPE":
# # macOS doesn't have the C.UTF-8 locale, but en_US.UTF-8 is available and works the same way.
"en_US.UTF-8" if is_macos else
# The default UTF-8 locale on all recent Linux distributions. It is also available in Cygwin and MSYS2.
"C.UTF-8",
},
)
else:
copy_directory_bin_action(
Expand Down
3 changes: 3 additions & 0 deletions npm/private/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ build_test(
# puppeteer: has a bin entry in the transitive closure with two segments: @puppeteer/browsers in https://unpkg.com/@puppeteer/browsers@0.5.0/package.json
# segfault-handler: has a node-gyp install step
":node_modules",

# @fastify/send (@3.3.0) contains spaces and a ☃ character in paths
":node_modules/@fastify/send",
],
)

Expand Down
1 change: 1 addition & 0 deletions npm/private/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"// devDependencies": "test linking & building 3rd party npm packages with problematic postinstall",
"devDependencies": {
"hello": "https://gitpkg.vercel.app/EqualMa/gitpkg-hello/packages/hello",
"@fastify/send": "3.3.0",
"@figma/nodegit": "^0.28.0-figma.2",
"@kubernetes/client-node": "https://github.com/kubernetes-client/javascript#bd6ab5810d013103d244ddaebe0304649c012b38",
"@plotly/regl": "2.1.2",
Expand Down
3,689 changes: 1,858 additions & 1,831 deletions npm/private/test/snapshots/bzlmod/npm_defs.bzl

Large diffs are not rendered by default.

3,689 changes: 1,858 additions & 1,831 deletions npm/private/test/snapshots/wksp/npm_defs.bzl

Large diffs are not rendered by default.

211 changes: 211 additions & 0 deletions npm/private/test/snapshots/wksp/repositories.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6b1dc20

Please sign in to comment.