| 1 |
def _opencc_resources_zip_impl(ctx): |
| 2 |
args = ctx.actions.args() |
| 3 |
args.add("--output", ctx.outputs.out) |
| 4 |
args.add("--source-url", ctx.attr.source_url) |
| 5 |
args.add("--stable-status", ctx.info_file) |
| 6 |
args.add("--volatile-status", ctx.version_file) |
| 7 |
args.add_all("--configs", ctx.files.configs) |
| 8 |
args.add_all("--dicts", ctx.files.dicts) |
| 9 |
|
| 10 |
ctx.actions.run( |
| 11 |
executable = ctx.executable.tool, |
| 12 |
arguments = [args], |
| 13 |
inputs = ( |
| 14 |
ctx.files.configs + |
| 15 |
ctx.files.dicts + |
| 16 |
[ctx.info_file, ctx.version_file] |
| 17 |
), |
| 18 |
outputs = [ctx.outputs.out], |
| 19 |
mnemonic = "OpenccResourcesZip", |
| 20 |
progress_message = "Building OpenCC resource zip %{output}", |
| 21 |
) |
| 22 |
|
| 23 |
opencc_resources_zip = rule( |
| 24 |
implementation = _opencc_resources_zip_impl, |
| 25 |
attrs = { |
| 26 |
"configs": attr.label_list(allow_files = True, mandatory = True), |
| 27 |
"dicts": attr.label_list(allow_files = True, mandatory = True), |
| 28 |
"source_url": attr.string(default = "https://github.com/BYVoid/OpenCC"), |
| 29 |
"tool": attr.label( |
| 30 |
default = Label("//data/scripts:opencc_resources_zip"), |
| 31 |
executable = True, |
| 32 |
cfg = "exec", |
| 33 |
), |
| 34 |
"out": attr.output(mandatory = True), |
| 35 |
}, |
| 36 |
) |
| 37 |
|
| 38 |
def _opencc_resources_ocd2_zip_impl(ctx): |
| 39 |
args = ctx.actions.args() |
| 40 |
args.add("--input", ctx.file.src) |
| 41 |
args.add("--output", ctx.outputs.out) |
| 42 |
args.add("--opencc-dict", ctx.executable.opencc_dict) |
| 43 |
|
| 44 |
ctx.actions.run( |
| 45 |
executable = ctx.executable.tool, |
| 46 |
arguments = [args], |
| 47 |
inputs = [ctx.file.src], |
| 48 |
tools = [ctx.executable.opencc_dict], |
| 49 |
outputs = [ctx.outputs.out], |
| 50 |
mnemonic = "OpenccResourcesOcd2Zip", |
| 51 |
progress_message = "Converting OpenCC resource zip to ocd2 %{output}", |
| 52 |
) |
| 53 |
|
| 54 |
opencc_resources_ocd2_zip = rule( |
| 55 |
implementation = _opencc_resources_ocd2_zip_impl, |
| 56 |
attrs = { |
| 57 |
"src": attr.label(allow_single_file = True, mandatory = True), |
| 58 |
"opencc_dict": attr.label( |
| 59 |
default = Label("//src/tools:dict_converter"), |
| 60 |
executable = True, |
| 61 |
cfg = "exec", |
| 62 |
), |
| 63 |
"tool": attr.label( |
| 64 |
default = Label("//scripts:convert_resource_zip"), |
| 65 |
executable = True, |
| 66 |
cfg = "exec", |
| 67 |
), |
| 68 |
"out": attr.output(mandatory = True), |
| 69 |
}, |
| 70 |
) |
| 71 |
|