-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
attr.output
instead of deprecated outputs
dict
Backwards compatibility is preserved by wrapping the `jar_jar` rule in a macro that populates the new `output_jar` attribute if the user doesn't set it. The output of a `jar_jar` target can still be referenced as a file target as demonstrated by new tests. In addition, user can now provide a custom name for the output jar.
- Loading branch information
Showing
5 changed files
with
73 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
def _jar_jar_impl(ctx): | ||
rule_file = ctx.file.rules | ||
if rule_file != None and ctx.attr.inline_rules != []: | ||
fail("Using both a rules file and inline_rules are incompatible; use one or the other.") | ||
if rule_file == None and ctx.attr.inline_rules == []: | ||
fail("You have to specify either a rules file or inline_rules.") | ||
if rule_file == None: | ||
rule_file = ctx.actions.declare_file("jar_jar-rules-" + ctx.label.name + ".tmp") | ||
ctx.actions.write( | ||
output = rule_file, | ||
content = "\n".join(ctx.attr.inline_rules) | ||
) | ||
|
||
args = ctx.actions.args() | ||
args.add("process") | ||
args.add(rule_file) | ||
args.add(ctx.file.input_jar) | ||
args.add(ctx.outputs.output_jar) | ||
|
||
ctx.actions.run( | ||
inputs = [rule_file, ctx.file.input_jar], | ||
outputs = [ctx.outputs.output_jar], | ||
executable = ctx.executable._jarjar_runner, | ||
progress_message = "jarjar %s" % ctx.label, | ||
arguments = [args], | ||
) | ||
|
||
return [ | ||
JavaInfo( | ||
output_jar = ctx.outputs.output_jar, | ||
compile_jar = ctx.outputs.output_jar, | ||
), | ||
DefaultInfo(files = depset([ctx.outputs.output_jar])), | ||
] | ||
|
||
jar_jar = rule( | ||
implementation = _jar_jar_impl, | ||
attrs = { | ||
"output_jar": attr.output(mandatory = True), | ||
"input_jar": attr.label(allow_single_file = True), | ||
"rules": attr.label(allow_single_file = True), | ||
"inline_rules" : attr.string_list(), | ||
"_jarjar_runner": attr.label(executable = True, cfg = "exec", default = "//src/main/java/com/github/johnynek/jarjar:app"), | ||
}, | ||
provides = [JavaInfo], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters