diff options
author | Chris Parsons <cparsons@google.com> | 2016-07-28 17:36:52 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2016-07-29 10:11:10 +0000 |
commit | 7c38828e8cbca27e884db87bf80eda699f8527e4 (patch) | |
tree | 2e40d98ab1d6819fb2efbcd53f6138dc8551b4ba /tools/build_defs | |
parent | 80f635a1bcd86ab08c14d5af4b2f56185d4825f1 (diff) |
executable attribute on apple_genrule, which allows users to run apple_genrule targets on the command line.
If an apple_genrule target is both executable and has more than one output, an error is thrown.
--
MOS_MIGRATED_REVID=128714692
Diffstat (limited to 'tools/build_defs')
-rw-r--r-- | tools/build_defs/apple/apple_genrule.bzl | 69 |
1 files changed, 47 insertions, 22 deletions
diff --git a/tools/build_defs/apple/apple_genrule.bzl b/tools/build_defs/apple/apple_genrule.bzl index cd346b7ee5..b22c480189 100644 --- a/tools/build_defs/apple/apple_genrule.bzl +++ b/tools/build_defs/apple/apple_genrule.bzl @@ -67,28 +67,24 @@ def _apple_genrule(ctx): mnemonic="Genrule", input_manifests=runfiles_manifests) - # Executable has to be specified explicitly - if ctx.attr.executable: - return struct(files=files_to_build, - data_runfiles=ctx.runfiles(transitive_files=files_to_build), - executable=list(files_to_build)[0]) - else: - return struct(files=files_to_build, - data_runfiles=ctx.runfiles(transitive_files=files_to_build)) - - -apple_genrule = rule(implementation=_apple_genrule, - attrs={ - "srcs": attr.label_list(allow_files=True), - "tools": attr.label_list(cfg=HOST_CFG, allow_files=True), - "outs": attr.output_list(mandatory=True), - "cmd": attr.string(mandatory=True), - "message": attr.string(), - "output_licenses": attr.license(), - "executable": attr.bool(default=False), - }, - output_to_genfiles = True, - fragments=APPLE_FRAGMENTS) + return struct(files=files_to_build, + data_runfiles=ctx.runfiles(transitive_files=files_to_build)) + + +_apple_genrule_inner = rule( + implementation=_apple_genrule, + attrs={ + "srcs": attr.label_list(allow_files=True), + "tools": attr.label_list(cfg=HOST_CFG, allow_files=True), + "outs": attr.output_list(mandatory=True), + "cmd": attr.string(mandatory=True), + "message": attr.string(), + "output_licenses": attr.license(), + "executable": attr.bool(default=False), + }, + output_to_genfiles = True, + fragments=APPLE_FRAGMENTS) + """Genrule which provides Apple specific environment and make variables. This mirrors the native genrule except that it provides a different set of make variables. This rule will only run on a Mac. @@ -121,3 +117,32 @@ The following environment variables are added to the rule action: DEVELOPER_DIR: The base developer directory as defined on Apple architectures, most commonly used in invoking Apple tools such as xcrun. """ +def apple_genrule( + name, + cmd, + executable = False, + outs = [], + **kwargs): + if executable: + if len(outs) != 1: + fail("apple_genrule, if executable, must have exactly one output") + intermediate_out = outs[0] + "_nonexecutable" + _apple_genrule_inner( + name = name + "_nonexecutable", + outs = [intermediate_out], + cmd = cmd, + **kwargs) + native.genrule( + name = name, + outs = outs, + srcs = [intermediate_out], + cmd = "cp $< $@", + executable = True, + ) + else: + _apple_genrule_inner( + name = name, + outs = outs, + cmd = cmd, + **kwargs) + |