@@ -4,7 +4,6 @@ load("@aspect_rules_js//js:defs.bzl", "js_binary")
44
55# https://github.com/bazelbuild/bazel-skylib/blob/main/rules/common_settings.bzl
66load ("@bazel_skylib//rules:common_settings.bzl" , skylib_bool_flag = "bool_flag" )
7- load ("@io_bazel_rules_docker//container:flatten.bzl" , "container_flatten" )
87load ("@npm//:mocha/package_json.bzl" , _mocha_bin = "bin" )
98load ("//bazel/test_on_env:test_on_env.bzl" , "test_on_env" )
109load ("//infra-sk/esbuild:esbuild.bzl" , "esbuild_dev_bundle" , "esbuild_node_bundle" , "esbuild_prod_bundle" )
@@ -623,109 +622,6 @@ def sk_page(
623622 visibility = ["//visibility:public" ],
624623 )
625624
626- def extract_files_from_skia_wasm_container (name , container , container_files , enabled_flag , ** kwargs ):
627- """Extracts files from the Skia WASM container image (gcr.io/skia-public/skia-wasm-release).
628-
629- This macro takes as inputs a list of paths inside the Docker container (container_files
630- argument), and a list of the same length with the destination paths for each of the files to
631- extract (outs argument), relative to the directory where the macro is instantiated.
632-
633- This image will be pulled if the enabled_flag is true, so users who need to set that flag to
634- true (e.g. infra folks pushing a clean image) should be granted permissions and have Docker
635- authentication set up. Users who are working with a local build should set the flag to false
636- and not need Docker authentication.
637-
638- Args:
639- name: Name of the target.
640- container: The name of the docker container (defined in //WORKSPACE) which contains the files.
641- container_files: Dictionary of absolute paths inside the Docker container to extract mapped to
642- the path they should be extracted to.
643- enabled_flag: Label. If set, should be the name of a bool_flag. If the bool_flag
644- is True, the real skia_wasm_container image will be pulled and the images loaded as per
645- usual. If the bool_flag is false, the container will not be loaded, but any outs will be
646- created as empty files to make dependent rules happy. It is up to the caller to use that
647- same flag to properly ignore those empty files if the flag is false (e.g. via a select).
648- **kwargs: Any flags that should be forwarded to the generated rule
649- """
650-
651- # Generates a .tar file with the contents of the image's filesystem (and a .json metadata file
652- # which we ignore).
653- #
654- # See the rule implementation here:
655- # https://github.com/bazelbuild/rules_docker/blob/02ad0a48fac9afb644908a634e8b2139c5e84670/container/flatten.bzl#L48
656- #
657- # Notes:
658- # - It is unclear whether container_flatten is part of the public API because it is not
659- # documented. But the fact that container_flatten is re-exported along with other, well
660- # documented rules in rules_docker suggests that it might indeed be part of the public API
661- # (see [1] and [2]).
662- # - If they ever make breaking changes to container_flatten, then it is probably best to fork
663- # it. The rule itself is relatively small; it is just a wrapper around a Go program that does
664- # all the heavy lifting.
665- # - This rule was chosen because most other rules in the rules_docker repository produce .tar
666- # files with layered outputs, which means we would have to do the flattening ourselves.
667- #
668- # [1] https://github.com/bazelbuild/rules_docker/blob/6c29619903b6bc533ad91967f41f2a3448758e6f/container/container.bzl#L28
669- # [2] https://github.com/bazelbuild/rules_docker/blob/e290d0975ab19f9811933d2c93be275b6daf7427/container/BUILD#L158
670-
671- # We expect enabled_flag to be a bool_flag, which means we should have two labels defined
672- # based on the passed in flag name, one with a _true suffix and one with a _false suffix. If
673- # the flag is set to false, we pull from a public image that has no files in it.
674- container_flatten (
675- name = name + "_skia_wasm_container_filesystem" ,
676- image = select ({
677- enabled_flag + "_true" : container + "//image" ,
678- enabled_flag + "_false" : "@empty_container//image" ,
679- }),
680- )
681-
682- # Name of the .tar file produced by the container_flatten target.
683- skia_wasm_filesystem_tar = name + "_skia_wasm_container_filesystem.tar"
684-
685- # Shell command that returns the directory of the BUILD file where this macro was instantiated.
686- #
687- # This works because:
688- # - The $< variable[1] is expanded by the below genrule to the path of its only input file.
689- # - The only input file to the genrule is the .tar file produced by the above container_flatten
690- # target (see the genrule's srcs attribute).
691- # - Said .tar file is produced in the directory of the BUILD file where this macro was
692- # instantiated.
693- #
694- # [1] https://bazel.build/reference/be/make-variables
695- output_dir = "$$(dirname $<)"
696-
697- # Directory where we will untar the .tar file produced by the container_flatten target.
698- skia_wasm_filesystem_dir = output_dir + "/" + skia_wasm_filesystem_tar + "_untarred"
699-
700- # Untar the .tar file produced by the container_flatten rule.
701- cmd = ("mkdir -p " + skia_wasm_filesystem_dir +
702- " && tar xf $< -C " + skia_wasm_filesystem_dir )
703-
704- outs = []
705-
706- # Copy each requested file from the container filesystem to its desired destination.
707- for src in container_files :
708- dst = container_files [src ]
709- copy = " && (cp %s/%s %s/%s" % (skia_wasm_filesystem_dir , src , output_dir , dst )
710-
711- # If the enabled_flag is False, we will be loading from an empty image and thus the
712- # files will not exist. As such, we need to create them or Bazel will fail because the
713- # expected generated files will not be created. It is up to the dependent rules to properly
714- # ignore these files. We cannot easily have the genrule change its behavior depending on
715- # how the flag is set, so we always touch the file as a backup. We write stderr to
716- # /dev/null to squash any errors about files not existing.
717- copy += " 2>/dev/null || touch %s/%s) " % (output_dir , dst )
718- cmd += copy
719- outs .append (dst )
720-
721- native .genrule (
722- name = name ,
723- srcs = [skia_wasm_filesystem_tar ],
724- outs = outs ,
725- cmd = cmd ,
726- ** kwargs
727- )
728-
729625def bool_flag (flag_name , default = True , name = "" ): # buildifier: disable=unused-variable
730626 """Create a boolean flag and corresponding config_settings.
731627
0 commit comments