@@ -17,6 +17,7 @@ This module provides an interface (`pkg_install`) for creating a `bazel
1717run`-able installation script.
1818"""
1919
20+ load ("@bazel_skylib//rules:common_settings.bzl" , "BuildSettingInfo" )
2021load ("@rules_python//python:defs.bzl" , "py_binary" )
2122load ("//pkg:providers.bzl" , "PackageDirsInfo" , "PackageFilegroupInfo" , "PackageFilesInfo" , "PackageSymlinkInfo" )
2223load ("//pkg/private:pkg_files.bzl" , "create_mapping_context_from_ctx" , "process_src" , "write_manifest" )
@@ -34,6 +35,11 @@ def _pkg_install_script_impl(ctx):
3435
3536 manifest_file = ctx .actions .declare_file (ctx .attr .name + "-install-manifest.json" )
3637
38+ destdir = ctx .attr .destdir
39+ if ctx .attr .destdir_flag :
40+ if BuildSettingInfo in ctx .attr .destdir_flag :
41+ destdir = ctx .attr .destdir_flag [BuildSettingInfo ].value
42+
3743 # Write out the manifest in terms of "short" paths, which are those expected
3844 # when you make `bazel run`nable binaries).
3945 #
@@ -62,7 +68,7 @@ def _pkg_install_script_impl(ctx):
6268 "{WORKSPACE_NAME}" : ctx .workspace_name ,
6369 # Used to annotate --help with "bazel run //path/to/your:installer"
6470 "{TARGET_LABEL}" : label_str ,
65- "{DEFAULT_DESTDIR}" : ctx . attr . destdir ,
71+ "{DEFAULT_DESTDIR}" : destdir ,
6672 },
6773 is_executable = True ,
6874 )
@@ -100,6 +106,7 @@ _pkg_install_script = rule(
100106 doc = "Source mapping/grouping targets" ,
101107 ),
102108 "destdir" : attr .string (),
109+ "destdir_flag" : attr .label (doc = "string flag to obtain destdir from" ),
103110 # This is private for now -- one could perhaps imagine making this
104111 # public, but that would require more documentation of the underlying
105112 # scripts and expected interfaces.
@@ -111,7 +118,7 @@ _pkg_install_script = rule(
111118 executable = True ,
112119)
113120
114- def pkg_install (name , srcs , destdir = None , ** kwargs ):
121+ def pkg_install (name , srcs , destdir = None , destdir_flag = None , ** kwargs ):
115122 """Create an installer script from pkg_filegroups and friends.
116123
117124 This macro allows users to create `bazel run`nable installation scripts
@@ -170,14 +177,18 @@ def pkg_install(name, srcs, destdir = None, **kwargs):
170177
171178 If this is an absolute path, it is used as-is. If this is a relative
172179 path, it is interpreted against `BUILD_WORKSPACE_DIRECTORY`.
180+ destdir_flag: A string_flag target used to obtain the value of destdir.
173181 **kwargs: common rule attributes
174182
175183 """
184+ if destdir and destdir_flag :
185+ fail ("You may only set on of destdir or destdir_flag" )
176186
177187 _pkg_install_script (
178188 name = name + "_install_script" ,
179189 srcs = srcs ,
180190 destdir = destdir ,
191+ destdir_flag = destdir_flag ,
181192 ** kwargs
182193 )
183194
0 commit comments