diff --git a/synology/images.bzl b/synology/images.bzl index 8b39154..185a71b 100644 --- a/synology/images.bzl +++ b/synology/images.bzl @@ -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_.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."), + } +) + diff --git a/synology/info-file.bzl b/synology/info-file.bzl index 777cc9f..92345a3 100644 --- a/synology/info-file.bzl +++ b/synology/info-file.bzl @@ -25,7 +25,7 @@ attributes can be provided to unblock immediate progress. (`BUILD` file) ``` -load("@rules_synology//:defs.bzl", "info_file", "maintainer") +load("@//:defs.bzl", "info_file", "maintainer") maintainer( name = "chickenandpork", diff --git a/synology/unittests.bzl b/synology/unittests.bzl index f898c97..23585e8 100644 --- a/synology/unittests.bzl +++ b/synology/unittests.bzl @@ -40,9 +40,9 @@ def confirm_binary_matches_platform(binary, size = "small"): out = "{}_test_arch.sh".format(token), is_executable = True, substitutions = select({ - "@rules_synology//arch:armada37xx": {"DETECT_STRING": " ELF 64-bit LSB pie executable, ARM aarch64"}, - "@rules_synology//arch:denverton": {"DETECT_STRING": " ELF 64-bit LSB pie executable, x86-64"}, - "@rules_synology//arch:geminilake": {"DETECT_STRING": " ELF 64-bit LSB pie executable, x86-64"}, + "@//arch:armada37xx": {"DETECT_STRING": " ELF 64-bit LSB pie executable, ARM aarch64"}, + "@//arch:denverton": {"DETECT_STRING": " ELF 64-bit LSB pie executable, x86-64"}, + "@//arch:geminilake": {"DETECT_STRING": " ELF 64-bit LSB pie executable, x86-64"}, "//conditions:default": {"DETECT_STRING": "no-possible-match"}, }), template = ":{}_test_arch_tmpl".format(token), diff --git a/synology/usr-local-linker.bzl b/synology/usr-local-linker.bzl index fe1e7a4..aa3267c 100644 --- a/synology/usr-local-linker.bzl +++ b/synology/usr-local-linker.bzl @@ -28,7 +28,7 @@ failing, triggering any rollback. This will cause a softlink to be created in `/usr/local/bin` that points to `/var/packages//target/bin/netfilter-mods`: ``` -load("@rules_synology//:defs.bzl", "usr_local_linker") +load("@//:defs.bzl", "usr_local_linker") usr_local_linker( name = "softlinks", diff --git a/tools/main.go b/tools/main.go index 96937ea..81115e2 100644 --- a/tools/main.go +++ b/tools/main.go @@ -33,11 +33,14 @@ func main() { dest = *destFilenamePattern } + if *verbose { + log.Println("resizing", *srcFilename, "size", *maxSize, "to", dest) + } err := ResizeImageFromFile(*srcFilename, dest, *maxSize) if err == nil { log.Println("OK:", dest) } else { - log.Println("result:", dest, err) + log.Println("result:", dest, "err:", err) } } diff --git a/tools/resize.go b/tools/resize.go index 530d155..319ed59 100644 --- a/tools/resize.go +++ b/tools/resize.go @@ -1,13 +1,14 @@ package main import ( + "errors" "github.com/disintegration/imaging" ) func ResizeImageFromFile(imageFile string, outFile string, newHeight int) error { img, err := imaging.Open(imageFile) if err != nil { - return err + return errors.New("Failure opening " + imageFile + ": " + err.Error()) } // calculator new width of image