Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Allow anonymous dependency #200

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 44 additions & 15 deletions synology/images.bzl
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."),
}
)

2 changes: 1 addition & 1 deletion synology/info-file.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions synology/unittests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion synology/usr-local-linker.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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/<package>/target/bin/netfilter-mods`:
```
load("@rules_synology//:defs.bzl", "usr_local_linker")
load("@//:defs.bzl", "usr_local_linker")

usr_local_linker(
name = "softlinks",
Expand Down
5 changes: 4 additions & 1 deletion tools/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
3 changes: 2 additions & 1 deletion tools/resize.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading