-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow anonymous dependency (#200)
- Loading branch information
1 parent
84c1297
commit 757db4f
Showing
6 changed files
with
55 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,44 @@ | ||
def images(name = "images", src = ":PACKAGE_ICON.PNG"): | ||
sizes = [16, 24, 32, 48, 64, 72, 90, 120, 256] | ||
|
||
[native.genrule( | ||
name = "{}_{}".format(name, sz), | ||
srcs = [src], | ||
outs = ["PACKAGE_ICON_{}.PNG".format(sz)], | ||
cmd = "$(location @rules_synology//tools:resize) -src=$< -size={} -dest=$@".format(sz), | ||
tools = ["@rules_synology//tools:resize"], | ||
) for sz in sizes] | ||
|
||
native.filegroup( | ||
name = "{}.group".format(name), | ||
srcs = [":{}_{}".format(name, sz) for sz in sizes], | ||
) | ||
def _images_impl(ctx): | ||
out_collector = [] | ||
images_template = ctx.attr.images_template or "PACKAGE_ICON_{}.PNG" | ||
for sz in ctx.attr.sizes: | ||
target_name = images_template.format(sz) | ||
target = ctx.actions.declare_file(target_name) | ||
ctx.actions.run( | ||
outputs = [target], | ||
inputs = [ctx.file.src], | ||
arguments = [ | ||
"-src={}".format(ctx.file.src.path), | ||
"-size={}".format(sz), | ||
"-dest={}".format(target.path), | ||
"-verbose" if ctx.attr.verbose else "", | ||
], | ||
executable = ctx.executable._resize, | ||
mnemonic = "Resizing", | ||
) | ||
out_collector.append(target) | ||
|
||
return [DefaultInfo( | ||
files=depset(out_collector), | ||
#runfiles= ctx.executable._resize[DefaultInfo].default_runfiles, | ||
runfiles= ctx.attr._resize[DefaultInfo].default_runfiles, | ||
)] | ||
|
||
|
||
images = rule( | ||
doc = """Create a filegroup of resized images: 16x16, 24x24, etc""", | ||
implementation = _images_impl, | ||
attrs = { | ||
"sizes": attr.int_list(mandatory = False, default = [ 16, 24, 32, 48, 64, 72, 90, 120, 256 ], doc = "sizes to convert: use a list of ints, each of which is a desired size of a square bounding box."), | ||
"src": attr.label(allow_single_file = True,mandatory = True, doc = "Initial source image to convert to various sizes."), | ||
"images_template": attr.string(doc = "template for output files: use a string with a single {} that will be replaced with the size. The template should end with a suffix that determines the resulting format: .png, .jpg, .PNG, etc. Note that Synology SPK packaging requires files of the form PACKAGE_ICON_<size>.PNG so changing this should ential converting the result back however desired for the payload of the SPK.", mandatory=False), | ||
"_resize": attr.label( | ||
default=Label("//tools:resize"), | ||
allow_single_file = True, | ||
executable = True, | ||
cfg = "exec", | ||
), | ||
"verbose": attr.bool(default=False, doc = "Verbosity can enable some debug messages from //tools:resize that can help resolve errors."), | ||
} | ||
) | ||
|
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
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
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