From 08ae3a44a6817dd446fefc5e7209794158305427 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Fri, 2 Aug 2024 16:39:11 -0400 Subject: [PATCH] bazel: Fix resource paths as external repo (see #3757) - Headers that are included by .rc files need to be supplied to `declare_exe` via the `resources_deps` attribute (passed as the `deps attribute to `compile_rc`). The headers must be part of a cc_library target via either the `hdrs` or `srcs` attribute. - File paths for CEF resources are prefixed with "external/" when CEF is loaded as an external repo. Update `copy_filegroups` to work with these paths. --- bazel/copy_filegroups.bzl | 8 ++++++-- tools/distrib/bazel/tests-cefclient-BUILD.bazel.in | 6 +++--- tools/distrib/bazel/tests-cefclient-win-BUILD.bazel | 4 +++- tools/distrib/bazel/tests-cefsimple-BUILD.bazel.in | 6 +++--- tools/distrib/bazel/tests-cefsimple-win-BUILD.bazel | 4 +++- tools/distrib/bazel/tests-ceftests-BUILD.bazel.in | 6 +++--- tools/distrib/bazel/tests-ceftests-win-BUILD.bazel | 4 +++- 7 files changed, 24 insertions(+), 14 deletions(-) diff --git a/bazel/copy_filegroups.bzl b/bazel/copy_filegroups.bzl index e2ffc56f7..5b701a1cd 100644 --- a/bazel/copy_filegroups.bzl +++ b/bazel/copy_filegroups.bzl @@ -10,12 +10,16 @@ def _copy_filegroups_impl(ctx): outputs = [] for f in inputs: relative_path = f.path + if relative_path.startswith("external/"): + # Remove the "external/" component, if any. + relative_path = "/".join(relative_path.split("/")[2:]) + for prefix in remove_prefixes: # Add trailing forward slash if necessary. if prefix[-1] != "/": prefix += "/" - if len(prefix) > 0 and f.path.startswith(prefix): - relative_path = f.path[len(prefix):] + if len(prefix) > 0 and relative_path.startswith(prefix): + relative_path = relative_path[len(prefix):] break if len(add_prefix) > 0: diff --git a/tools/distrib/bazel/tests-cefclient-BUILD.bazel.in b/tools/distrib/bazel/tests-cefclient-BUILD.bazel.in index 14358dd3d..beeebd76d 100644 --- a/tools/distrib/bazel/tests-cefclient-BUILD.bazel.in +++ b/tools/distrib/bazel/tests-cefclient-BUILD.bazel.in @@ -81,10 +81,10 @@ objc_library( # Windows targets. # -# Allow access from the declare_exe target. -filegroup( +# Allow access to resource.h from the declare_exe target. +cc_library( name = "ResourceH", - srcs = [ + hdrs = [ "browser/resource.h" ] ) diff --git a/tools/distrib/bazel/tests-cefclient-win-BUILD.bazel b/tools/distrib/bazel/tests-cefclient-win-BUILD.bazel index 94ddb81c1..d27b262a5 100644 --- a/tools/distrib/bazel/tests-cefclient-win-BUILD.bazel +++ b/tools/distrib/bazel/tests-cefclient-win-BUILD.bazel @@ -43,12 +43,14 @@ declare_exe( "{}.exe.manifest".format(PRODUCT_NAME), ], resources_srcs = [ - "{}:ResourceH".format(PKG_NAME), "{}:Resources".format(PKG_NAME), "{}.ico".format(PRODUCT_NAME), "small.ico", "//tests/shared:Resources", ], + resources_deps = [ + "{}:ResourceH".format(PKG_NAME), + ], linkopts = [ "/SUBSYSTEM:WINDOWS", ] + [ diff --git a/tools/distrib/bazel/tests-cefsimple-BUILD.bazel.in b/tools/distrib/bazel/tests-cefsimple-BUILD.bazel.in index 689176d97..53ac0b759 100644 --- a/tools/distrib/bazel/tests-cefsimple-BUILD.bazel.in +++ b/tools/distrib/bazel/tests-cefsimple-BUILD.bazel.in @@ -66,10 +66,10 @@ cc_library( # Windows targets. # -# Allow access from the declare_exe target. -filegroup( +# Allow access to resource.h from the declare_exe target. +cc_library( name = "ResourceH", - srcs = [ + hdrs = [ "resource.h" ] ) diff --git a/tools/distrib/bazel/tests-cefsimple-win-BUILD.bazel b/tools/distrib/bazel/tests-cefsimple-win-BUILD.bazel index 6420d7669..8a2197eb8 100644 --- a/tools/distrib/bazel/tests-cefsimple-win-BUILD.bazel +++ b/tools/distrib/bazel/tests-cefsimple-win-BUILD.bazel @@ -27,10 +27,12 @@ declare_exe( "{}.exe.manifest".format(PRODUCT_NAME), ], resources_srcs = [ - "{}:ResourceH".format(PKG_NAME), "{}.ico".format(PRODUCT_NAME), "small.ico", ], + resources_deps = [ + "{}:ResourceH".format(PKG_NAME), + ], linkopts = [ "/SUBSYSTEM:WINDOWS", ], diff --git a/tools/distrib/bazel/tests-ceftests-BUILD.bazel.in b/tools/distrib/bazel/tests-ceftests-BUILD.bazel.in index c8e38b99b..50ab55fa9 100644 --- a/tools/distrib/bazel/tests-ceftests-BUILD.bazel.in +++ b/tools/distrib/bazel/tests-ceftests-BUILD.bazel.in @@ -81,10 +81,10 @@ objc_library( # Windows targets. # -# Allow access from the declare_exe target. -filegroup( +# Allow access to resource.h from the declare_exe target. +cc_library( name = "ResourceH", - srcs = [ + hdrs = [ "resource.h" ] ) diff --git a/tools/distrib/bazel/tests-ceftests-win-BUILD.bazel b/tools/distrib/bazel/tests-ceftests-win-BUILD.bazel index 14397898d..bb02299d9 100644 --- a/tools/distrib/bazel/tests-ceftests-win-BUILD.bazel +++ b/tools/distrib/bazel/tests-ceftests-win-BUILD.bazel @@ -45,11 +45,13 @@ declare_exe( "{}.exe.manifest".format(PRODUCT_NAME), ], resources_srcs = [ - "{}:ResourceH".format(PKG_NAME), "{}.ico".format(PRODUCT_NAME), "small.ico", "//tests/shared:Resources", ], + resources_deps = [ + "{}:ResourceH".format(PKG_NAME), + ], linkopts = [ "/SUBSYSTEM:CONSOLE", ],