Skip to content

Commit 6348f54

Browse files
authored
Fix component ccInfo provider (#24)
* fix ccinfo targets for windows and linux
1 parent ea75935 commit 6348f54

File tree

11 files changed

+127
-27
lines changed

11 files changed

+127
-27
lines changed

bcr-modules/modules/rules_cfg5/0.0.2/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ pkg_files(
4343
srcs = [
4444
"//bcr-modules/modules/rules_cfg5/srcs:BUILD.bazel",
4545
"//bcr-modules/modules/rules_cfg5/srcs:MODULE.bazel",
46-
"//bcr-modules/modules/rules_cfg5/srcs:README.md",
4746
"//bcr-modules/modules/rules_cfg5/srcs:defs.bzl",
4847
"//bcr-modules/modules/rules_cfg5/srcs:generate.bzl",
4948
],

bcr-modules/modules/rules_cfg5/0.0.3/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ pkg_files(
4343
srcs = [
4444
"//bcr-modules/modules/rules_cfg5/srcs:BUILD.bazel",
4545
"//bcr-modules/modules/rules_cfg5/srcs:MODULE.bazel",
46-
"//bcr-modules/modules/rules_cfg5/srcs:README.md",
4746
"//bcr-modules/modules/rules_cfg5/srcs:defs.bzl",
4847
"//bcr-modules/modules/rules_cfg5/srcs:generate.bzl",
4948
],
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
load("@rules_pkg//:mappings.bzl", "pkg_files")
2+
load("//bcr-modules/macros:module_macro.bzl", "module")
3+
load("//bcr-modules/macros:upload_macro.bzl", "module_upload")
4+
5+
package(default_visibility = ["//visibility:public"])
6+
7+
module_upload(
8+
name = "upload",
9+
archive = ":rules_cfg5",
10+
upload_module_name = "rules_cfg5",
11+
version = "0.0.4",
12+
)
13+
14+
pkg_files(
15+
name = "private",
16+
srcs = [
17+
"//bcr-modules/modules/rules_cfg5/srcs:private/generate.bzl",
18+
"//bcr-modules/modules/rules_cfg5/srcs:private/start.bzl",
19+
"//bcr-modules/modules/rules_cfg5/srcs:private/toolchains.bzl",
20+
],
21+
prefix = "private",
22+
)
23+
24+
pkg_files(
25+
name = "private_common",
26+
srcs = [
27+
"//bcr-modules/modules/rules_cfg5/srcs:private/common/component_refs.bzl",
28+
],
29+
prefix = "private/common",
30+
)
31+
32+
pkg_files(
33+
name = "private_templates",
34+
srcs = [
35+
"//bcr-modules/modules/rules_cfg5/srcs:private/templates/filter_linux.sh.tpl",
36+
"//bcr-modules/modules/rules_cfg5/srcs:private/templates/filter_windows.ps1.tpl",
37+
],
38+
prefix = "private/templates",
39+
)
40+
41+
pkg_files(
42+
name = "public",
43+
srcs = [
44+
"//bcr-modules/modules/rules_cfg5/srcs:BUILD.bazel",
45+
"//bcr-modules/modules/rules_cfg5/srcs:MODULE.bazel",
46+
"//bcr-modules/modules/rules_cfg5/srcs:defs.bzl",
47+
"//bcr-modules/modules/rules_cfg5/srcs:generate.bzl",
48+
],
49+
)
50+
51+
module(
52+
name = "rules_cfg5",
53+
additional_dependencies = [
54+
55+
56+
57+
58+
59+
],
60+
module_version = "0.0.4",
61+
pkg_files_targets = [
62+
"public",
63+
"private",
64+
"private_common",
65+
"private_templates",
66+
],
67+
)

bcr-modules/modules/rules_cfg5/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module_bcr_dir(
77
versions = [
88
"0.0.2",
99
"0.0.3",
10+
"0.0.4",
1011
],
1112
visibility = ["//visibility:public"],
1213
)

bcr-modules/modules/rules_cfg5/README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,10 @@ The output directory for GenData in the .dpa file must be set to:
341341

342342
When `components` list is provided, the rule creates separate targets for each component:
343343
- Main target: `{name}` - All generated code
344-
- Component targets: `{name}_{ComponentName}` - Component-specific code
344+
- Unmapped target: `{name}_unmapped` - Shared headers without component-specific directories
345+
- Component targets: `{name}_{ComponentName}` - Component-specific code with includes
346+
347+
The unmapped target provides access to shared generated headers (GenData directory) that are not filtered to any component-specific header directories. This is useful for Gendata, that cannot be filtered that easily.
345348

346349
Example:
347350
```python
@@ -353,10 +356,16 @@ cfg5_generate_rt(
353356

354357
# Creates targets:
355358
# - :bsw (all code)
356-
# - :bsw_CanIf (CanIf only)
357-
# - :bsw_Com (Com only)
359+
# - :bsw_unmapped (shared headers only)
360+
# - :bsw_CanIf (CanIf headers and sources)
361+
# - :bsw_Com (Com headers and sources)
358362
```
359363

364+
**Include Path Behavior:**
365+
- **Main target** (`bsw`): Provides all headers and all component-specific include directories
366+
- **Unmapped target** (`bsw_unmapped`): Provides only shared GenData includes (no component-specific directories)
367+
- **Component targets** (`bsw_CanIf`, `bsw_Com`): Each provides its own component headers plus shared GenData includes
368+
360369
### File Filtering
361370

362371
Control which files are included/excluded from generation:

bcr-modules/modules/rules_cfg5/srcs/MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
module(
2525
name = "rules_cfg5",
26-
version = "0.0.3",
26+
version = "0.0.4",
2727
compatibility_level = 0,
2828
)
2929

bcr-modules/modules/rules_cfg5/srcs/generate.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,5 @@ def cfg5_generate_rt(name, components = [], **kwargs):
122122
extract_component_cc_info(
123123
name = name + "_unmapped",
124124
src = ":" + name,
125-
component = "main", # "main" contains all unmapped files
125+
component = "unmapped", # Unmapped files with restricted includes
126126
)

bcr-modules/modules/rules_cfg5/srcs/private/generate.bzl

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ def _cfg5_generate(ctx, dpa_path, dpa_folder, inputs, template, additional_genar
177177

178178
compilation_context = cc_common.create_compilation_context(
179179
headers = depset(
180-
[headers_dir] + component_headers_dirs,
180+
[headers_dir],
181181
),
182182
includes = depset(
183-
[headers_dir.path] + [comp_hdr_dir.path for comp_hdr_dir in component_headers_dirs],
183+
[headers_dir.path],
184184
),
185185
)
186186

@@ -276,24 +276,31 @@ def _cfg5_generate(ctx, dpa_path, dpa_folder, inputs, template, additional_genar
276276
# Main CcInfo containing all generated files (for backward compatibility)
277277
main_cc_info = CcInfo(compilation_context = compilation_context)
278278

279+
# Create unmapped CcInfo with only headers_dir (no component-specific dirs)
280+
if ctx.attr.private_is_windows:
281+
unmapped_includes = [headers_dir.path]
282+
else:
283+
unmapped_includes = [
284+
headers_dir.path + "/" + gen_dir,
285+
headers_dir.path + "/" + gen_dir + "/Components",
286+
]
287+
288+
unmapped_compilation_context = cc_common.create_compilation_context(
289+
headers = depset([headers_dir]),
290+
includes = depset(unmapped_includes),
291+
)
292+
unmapped_cc_info = CcInfo(compilation_context = unmapped_compilation_context)
293+
279294
# Create component-specific CcInfo providers only for actual components
280295
component_cc_infos = {}
281296
for i, component in enumerate(actual_components):
282297
if i < len(component_headers_dirs):
283298
# Include both component-specific and main headers for proper include resolution
284299
component_headers = [component_headers_dirs[i], headers_dir]
285300

286-
if ctx.attr.private_is_windows:
287-
component_includes = [
288-
component_headers_dirs[i].path,
289-
headers_dir.path,
290-
]
291-
else:
292-
component_includes = [
293-
component_headers_dirs[i].path + "/" + gen_dir,
294-
component_headers_dirs[i].path + "/" + gen_dir + "/Components",
295-
headers_dir.path,
296-
]
301+
component_includes = [
302+
component_headers_dirs[i].path,
303+
]
297304

298305
component_compilation_context = cc_common.create_compilation_context(
299306
headers = depset(component_headers),
@@ -305,13 +312,16 @@ def _cfg5_generate(ctx, dpa_path, dpa_folder, inputs, template, additional_genar
305312
# Collect all output directories for DefaultInfo
306313
all_output_dirs = [sources_dir, headers_dir] + component_sources_dirs + component_headers_dirs
307314

315+
# Add unmapped to components dict
316+
component_cc_infos["unmapped"] = unmapped_cc_info
317+
308318
return [
309319
DefaultInfo(files = depset(additional_output_file_artifacts + all_output_dirs + [dvcfg5_report_file, dvcfg5_log_file])),
310320
main_cc_info,
311321
MultipleCcInfo(
312322
main = main_cc_info,
313323
components = component_cc_infos,
314-
component_names = actual_components,
324+
component_names = actual_components + ["unmapped"],
315325
),
316326
]
317327

@@ -375,11 +385,11 @@ def _extract_component_cc_info_impl(ctx):
375385
multiple_cc_info = ctx.attr.src[MultipleCcInfo]
376386
component_name = ctx.attr.component
377387

378-
if component_name in multiple_cc_info.components or component_name == "main":
379-
if component_name == "main":
380-
# For unmapped files, use main CcInfo and main directories (which contain unmapped files after component files are moved)
381-
component_cc_info = ctx.attr.src[CcInfo] # Use the main CcInfo from the source target
382-
directory_suffix = "" # Main directories don't have suffix
388+
if component_name in multiple_cc_info.components:
389+
if component_name == "unmapped":
390+
# For unmapped files, use the unmapped-specific CcInfo with only headers_dir
391+
component_cc_info = multiple_cc_info.components["unmapped"]
392+
directory_suffix = "" # Unmapped files are in main directories without suffix
383393
else:
384394
component_cc_info = multiple_cc_info.components[component_name]
385395
directory_suffix = "_" + component_name
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module(
2+
name = "rules_cfg5",
3+
version = "0.0.4",
4+
compatibility_level = 1,
5+
)
6+
7+
bazel_dep(name = "ape", version = "1.0.1")
8+
bazel_dep(name = "bazel_skylib", version = "1.7.1")
9+
bazel_dep(name = "rules_cc", version = "0.1.1")
10+
bazel_dep(name = "rules_common", version = "0.2.0")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"url": "https://github.com/vectorgrp/bazel-rules/releases/download/rules_cfg5/0.0.4/rules_cfg5.tar.gz",
3+
"integrity": ""
4+
}

0 commit comments

Comments
 (0)