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/<repo>"
  when CEF is loaded as an external repo. Update `copy_filegroups` to
  work with these paths.
This commit is contained in:
Marshall Greenblatt 2024-08-02 16:39:11 -04:00
parent 5ddeef736a
commit 08ae3a44a6
7 changed files with 24 additions and 14 deletions

View File

@ -10,12 +10,16 @@ def _copy_filegroups_impl(ctx):
outputs = [] outputs = []
for f in inputs: for f in inputs:
relative_path = f.path relative_path = f.path
if relative_path.startswith("external/"):
# Remove the "external/<repo>" component, if any.
relative_path = "/".join(relative_path.split("/")[2:])
for prefix in remove_prefixes: for prefix in remove_prefixes:
# Add trailing forward slash if necessary. # Add trailing forward slash if necessary.
if prefix[-1] != "/": if prefix[-1] != "/":
prefix += "/" prefix += "/"
if len(prefix) > 0 and f.path.startswith(prefix): if len(prefix) > 0 and relative_path.startswith(prefix):
relative_path = f.path[len(prefix):] relative_path = relative_path[len(prefix):]
break break
if len(add_prefix) > 0: if len(add_prefix) > 0:

View File

@ -81,10 +81,10 @@ objc_library(
# Windows targets. # Windows targets.
# #
# Allow access from the declare_exe target. # Allow access to resource.h from the declare_exe target.
filegroup( cc_library(
name = "ResourceH", name = "ResourceH",
srcs = [ hdrs = [
"browser/resource.h" "browser/resource.h"
] ]
) )

View File

@ -43,12 +43,14 @@ declare_exe(
"{}.exe.manifest".format(PRODUCT_NAME), "{}.exe.manifest".format(PRODUCT_NAME),
], ],
resources_srcs = [ resources_srcs = [
"{}:ResourceH".format(PKG_NAME),
"{}:Resources".format(PKG_NAME), "{}:Resources".format(PKG_NAME),
"{}.ico".format(PRODUCT_NAME), "{}.ico".format(PRODUCT_NAME),
"small.ico", "small.ico",
"//tests/shared:Resources", "//tests/shared:Resources",
], ],
resources_deps = [
"{}:ResourceH".format(PKG_NAME),
],
linkopts = [ linkopts = [
"/SUBSYSTEM:WINDOWS", "/SUBSYSTEM:WINDOWS",
] + [ ] + [

View File

@ -66,10 +66,10 @@ cc_library(
# Windows targets. # Windows targets.
# #
# Allow access from the declare_exe target. # Allow access to resource.h from the declare_exe target.
filegroup( cc_library(
name = "ResourceH", name = "ResourceH",
srcs = [ hdrs = [
"resource.h" "resource.h"
] ]
) )

View File

@ -27,10 +27,12 @@ declare_exe(
"{}.exe.manifest".format(PRODUCT_NAME), "{}.exe.manifest".format(PRODUCT_NAME),
], ],
resources_srcs = [ resources_srcs = [
"{}:ResourceH".format(PKG_NAME),
"{}.ico".format(PRODUCT_NAME), "{}.ico".format(PRODUCT_NAME),
"small.ico", "small.ico",
], ],
resources_deps = [
"{}:ResourceH".format(PKG_NAME),
],
linkopts = [ linkopts = [
"/SUBSYSTEM:WINDOWS", "/SUBSYSTEM:WINDOWS",
], ],

View File

@ -81,10 +81,10 @@ objc_library(
# Windows targets. # Windows targets.
# #
# Allow access from the declare_exe target. # Allow access to resource.h from the declare_exe target.
filegroup( cc_library(
name = "ResourceH", name = "ResourceH",
srcs = [ hdrs = [
"resource.h" "resource.h"
] ]
) )

View File

@ -45,11 +45,13 @@ declare_exe(
"{}.exe.manifest".format(PRODUCT_NAME), "{}.exe.manifest".format(PRODUCT_NAME),
], ],
resources_srcs = [ resources_srcs = [
"{}:ResourceH".format(PKG_NAME),
"{}.ico".format(PRODUCT_NAME), "{}.ico".format(PRODUCT_NAME),
"small.ico", "small.ico",
"//tests/shared:Resources", "//tests/shared:Resources",
], ],
resources_deps = [
"{}:ResourceH".format(PKG_NAME),
],
linkopts = [ linkopts = [
"/SUBSYSTEM:CONSOLE", "/SUBSYSTEM:CONSOLE",
], ],