Skip to content

Commit c2562fb

Browse files
devversionjelbourn
authored andcommitted
build: ensure build-packages-dist script works on macOS (#17247)
The `build-packages-dist` script does not seem to work on MacOS because the `cp --no-preserve` flag is not supported by default. This commit switches to a simple `chmod` call in order to make it work in all Bash environments. Additionally the script has been updated to clean previous `npm_package` outputs. This ensures that the version placeholder is properly replaced in the release output. This is necessary due to a bug in `rules_nodejs`. Read more here: bazel-contrib/rules_nodejs#1219
1 parent 65a8c96 commit c2562fb

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

scripts/build-packages-dist.sh

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,24 @@ echo ""
2828
dest_path="dist/releases"
2929

3030
# Path to the bazel-bin directory.
31-
bazel_bin_path=$(${bazel} info bazel-bin 2> /dev/null)
31+
bazel_bin_path=$(${bazel} info bazel-bin)
3232

3333
# List of targets that need to be built, e.g. //src/lib, //src/cdk, etc. Note we need to remove all
3434
# carriage returns because Bazel prints these on Windows. This breaks the Bash array parsing.
3535
targets=$(${bazel} query --output=label 'attr("tags", "\[.*release-package.*\]", //src/...)' \
36-
'intersect kind(".*_package", //src/...)' 2> /dev/null | tr -d "\r")
36+
'intersect kind(".*_package", //src/...)' | tr -d "\r")
37+
38+
# Extracts the package name from the Bazel target names.
39+
# e.g. `src/material:npm_package` will result in "material".
40+
dirs=`echo "$targets" | sed -e 's/\/\/src\/\(.*\):npm_package/\1/'`
41+
42+
# Walk through each release package and clear previous "npm_package" outputs. This is
43+
# a workaround for: https://github.com/bazelbuild/rules_nodejs/issues/1219. We need to
44+
# do this to ensure that the version placeholders are properly populated.
45+
for pkg in ${dirs}; do
46+
pkg_dir="${bazel_bin_path}/src/${pkg}/npm_package"
47+
rm -Rf ${pkg_dir}
48+
done
3749

3850
# Walk through each release package target and build it.
3951
for target in ${targets}; do
@@ -49,10 +61,6 @@ done
4961
rm -Rf ${dest_path}
5062
mkdir -p ${dest_path}
5163

52-
# Extracts the package name from the Bazel target names. e.g. `src/material:npm_package`
53-
# will result in "material".
54-
dirs=`echo "$targets" | sed -e 's/\/\/src\/\(.*\):npm_package/\1/'`
55-
5664
# Copy the package output for all built NPM packages into the dist directory.
5765
for pkg in ${dirs}; do
5866
pkg_dir="${bazel_bin_path}/src/${pkg}/npm_package"
@@ -61,6 +69,7 @@ for pkg in ${dirs}; do
6169
if [[ -d ${pkg_dir} ]]; then
6270
echo "> Copying package output to \"${target_dir}\".."
6371
rm -rf ${target_dir}
64-
cp -R --no-preserve=mode ${pkg_dir} ${target_dir}
72+
cp -R ${pkg_dir} ${target_dir}
73+
chmod -R u+w ${target_dir}
6574
fi
6675
done

0 commit comments

Comments
 (0)