Skip to content

Commit 167e5de

Browse files
authored
feat: support make vars in postfix_script (#1375)
postfix_script did not support make vars which means we cannot use things like $(execpath :target) in it. This limited the functionality of the attribute. Note, this is a breaking change as $$ wrapped variable declaration and single $ shell variable declaration will no longer work in postfix_script e.g. $$INSTALLDIR$$ and $INSTALLDIR. Need to used shell variable with an escaped $ like $$INSTALLDIR.
1 parent db96000 commit 167e5de

File tree

6 files changed

+9
-10
lines changed

6 files changed

+9
-10
lines changed

examples/cmake_synthetic/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ cmake(
88
# Demonstrate non-alphanumeric name
99
lib_name = "liba++",
1010
lib_source = "//cmake_synthetic/liba:a_srcs",
11-
postfix_script = "cp -p $$INSTALLDIR$$/lib/liba.a $$INSTALLDIR$$/lib/liba++.a",
11+
postfix_script = "cp -p $$INSTALLDIR/lib/liba.a $$INSTALLDIR/lib/liba++.a",
1212
)
1313

1414
cmake(

examples/third_party/gn/BUILD.gn.bazel

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ ninja(
3232
# gn has no install step, manually grab the artifacts
3333
postfix_script = select({
3434
":windows": " && ".join([
35-
"cp -a out/gn_lib.lib $$INSTALLDIR$$/lib",
36-
"cp -a out/gn.exe $$INSTALLDIR$$/bin",
35+
"cp -a out/gn_lib.lib $$INSTALLDIR/lib",
36+
"cp -a out/gn.exe $$INSTALLDIR/bin",
3737
]),
3838
"//conditions:default": " && ".join([
39-
"cp -a out/gn_lib.a $$INSTALLDIR$$/lib",
40-
"cp -a out/gn $$INSTALLDIR$$/bin",
39+
"cp -a out/gn_lib.a $$INSTALLDIR/lib",
40+
"cp -a out/gn $$INSTALLDIR/bin",
4141
]),
4242
}),
4343
)

foreign_cc/built_tools/pkgconfig_build.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def pkgconfig_tool(name, srcs, **kwargs):
168168
"@gettext_runtime",
169169
],
170170
postfix_script = select({
171-
"@platforms//os:windows": "cp release/x64/pkg-config.exe $$INSTALLDIR$$/bin",
171+
"@platforms//os:windows": "cp release/x64/pkg-config.exe $$INSTALLDIR/bin",
172172
"//conditions:default": "",
173173
}),
174174
toolchain = str(Label("//toolchains:preinstalled_nmake_toolchain")),

foreign_cc/configure.bzl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,10 @@ def _configure_make(ctx):
4444
ctx.label,
4545
))
4646

47-
copy_results = "##copy_dir_contents_to_dir## $$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$ $$INSTALLDIR$$\n"
48-
4947
attrs = create_attrs(
5048
ctx.attr,
5149
configure_name = "Configure",
5250
create_configure_script = _create_configure_script,
53-
postfix_script = copy_results + "\n" + ctx.attr.postfix_script,
5451
tools_data = tools_data,
5552
make_path = make_data.path,
5653
)

foreign_cc/private/configure_script.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def create_configure_script(
9898

9999
script.extend(make_commands)
100100
script.append("##disable_tracing##")
101+
script.append("##copy_dir_contents_to_dir## $$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$ $$INSTALLDIR$$\n")
101102

102103
return script
103104

foreign_cc/private/framework.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,10 @@ def cc_external_rule_impl(ctx, attrs):
454454
installdir = target_root + "/" + lib_name
455455
env_prelude = get_env_prelude(ctx, installdir, data_dependencies)
456456

457-
postfix_script = [attrs.postfix_script]
458457
if not attrs.postfix_script:
459458
postfix_script = []
459+
else:
460+
postfix_script = [expand_locations_and_make_variables(ctx, attrs.postfix_script, "postfix_script", data_dependencies)]
460461

461462
script_lines = [
462463
"##echo## \"\"",

0 commit comments

Comments
 (0)