Skip to content

Commit

Permalink
feat: forward tags from bob_toolchain
Browse files Browse the repository at this point in the history
Currently only the `owner:` tag is used within Bob,
for this reason this is the only tag currently forwarded
in the backend.

Should a need for wider tag forwarding arise this will
require changes to `Tagable` interface to retrieve the
property from direct deps via the toolchain tag.

Care must be taken as this can result in duplicate
tags, which will produce an error in the case of `owner:`.

Change-Id: I514f06138fd6d5b9ba9fa7402c50af42a42ecf06
  • Loading branch information
lukokr-aarch64 committed Oct 11, 2023
1 parent 6a711c7 commit 0b84197
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 9 deletions.
12 changes: 11 additions & 1 deletion core/androidbp_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/ARM-software/bob-build/core/config"
"github.com/ARM-software/bob-build/core/file"
"github.com/ARM-software/bob-build/core/tag"
"github.com/ARM-software/bob-build/internal/bpwriter"
"github.com/ARM-software/bob-build/internal/fileutils"
"github.com/ARM-software/bob-build/internal/utils"
Expand Down Expand Up @@ -87,10 +88,19 @@ func (g *androidBpGenerator) aliasActions(a *ModuleAlias, ctx blueprint.ModuleCo

var ownerTagRegex = regexp.MustCompile(`^owner:[a-zA-Z0-9_-]+`)

func addProvenanceProps(writer bpwriter.Module, mod Tagable) {
func addProvenanceProps(ctx blueprint.ModuleContext, writer bpwriter.Module, mod Tagable) {

tags := mod.GetTagsRegex(ownerTagRegex)

// Append any tags applied from the toolchain.
ctx.VisitDirectDepsIf(
func(dep blueprint.Module) bool {
return ctx.OtherModuleDependencyTag(dep) == tag.ToolchainTag
},
func(dep blueprint.Module) {
tags = append(tags, dep.(*ModuleToolchain).GetTagsRegex(ownerTagRegex)...)
})

switch len(tags) {
case 0:
// No owner tag set.
Expand Down
8 changes: 4 additions & 4 deletions core/androidbp_cclibs.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func addCcLibraryProps(mod bpwriter.Module, m ModuleLibrary, ctx blueprint.Modul
mod.AddString("relative_install_path", installRel)
}

addProvenanceProps(mod, &m)
addProvenanceProps(ctx, mod, &m)
addPGOProps(mod, m.Properties.Build.AndroidPGOProps)
addRequiredModules(mod, m, ctx)

Expand Down Expand Up @@ -700,7 +700,7 @@ func (g *androidBpGenerator) strictLibraryActions(m *ModuleStrictLibrary, ctx bl
// mod.AddString("relative_install_path", installRel)
// }

addProvenanceProps(mod, m)
addProvenanceProps(ctx, mod, m)

// TODO: Make addPGOProps generic and enable it if needed
// addPGOProps(mod, m.Properties.Build.AndroidPGOProps)
Expand Down Expand Up @@ -745,7 +745,7 @@ func (g *androidBpGenerator) executableTestActions(m *ModuleTest, ctx blueprint.
// mod.AddString("compile_multilib", "both")
// }

addProvenanceProps(mod, m)
addProvenanceProps(ctx, mod, m)

// Avoid using cc_test default setup
// TODO: `relative_install_path` needed - Module install directory may only be disabled if relative_install_path is set
Expand Down Expand Up @@ -783,5 +783,5 @@ func (g *androidBpGenerator) strictBinaryActions(m *ModuleStrictBinary, ctx blue
mod.AddString("compile_multilib", "both")
}

addProvenanceProps(mod, m)
addProvenanceProps(ctx, mod, m)
}
2 changes: 1 addition & 1 deletion core/androidbp_filegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ func (g *androidBpGenerator) filegroupActions(m *ModuleFilegroup, ctx blueprint.
utils.Die("%v", err.Error())
}
mod.AddStringList("srcs", m.Properties.Srcs)
addProvenanceProps(mod, m)
addProvenanceProps(ctx, mod, m)
}
2 changes: 1 addition & 1 deletion core/androidbp_kernel_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (g *androidBpGenerator) kernelModuleActions(ko *ModuleKernelObject, ctx blu
kdir = getPathInSourceDir(kdir)
}

addProvenanceProps(bpmod, ko)
addProvenanceProps(ctx, bpmod, ko)

srcs := []string{}
ko.Properties.GetFiles(ctx).ForEach(
Expand Down
2 changes: 1 addition & 1 deletion core/androidbp_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (g *androidBpGenerator) resourceActions(r *ModuleResource, ctx blueprint.Mo
utils.Die(err.Error())
}

addProvenanceProps(m, r)
addProvenanceProps(ctx, m, r)

// TODO: temporary workaround for broken symlinks
// Remove while Bob plugins won't be used anymore
Expand Down
3 changes: 2 additions & 1 deletion docs/module_types/bob_toolchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
```bp
bob_toolchain {
name, cflags, conlyflags, cppflags, asflags, ldflags, target, host, mte,
name, cflags, conlyflags, cppflags, asflags, ldflags, target, host, mte, tags
}
```

Expand All @@ -31,6 +31,7 @@ Supports:
| [`asflags`](properties/legacy_properties.md#asflags) | List of strings; default is `[]`<br>Flags used for assembly compilation. |
| [`ldflags`](properties/legacy_properties.md#ldflags) | List of strings; default is `[]`<br>Flags used for linking. |
| `mte` | Property map; default is `{}`.<br>Flags to be used to enable the Arm Memory Tagging Extension.<br>Only supported on Android.<br>- **memtag_heap** - Memory-tagging, only available on arm64 if `diag_memtag_heap` unset or false, enables async memory tagging.<br>- **diag_memtag_heap** - Memory-tagging, only available on arm64 requires `memtag_heap`: true if set, enables sync memory tagging. |
| [`tags`](properties/common_properties.md#tags) | List of strings; default is `[]`<br>This list of tags will be appended to any module using this toolchain configuration. |

## Example

Expand Down
8 changes: 8 additions & 0 deletions gendiffer/tests/toolchain/tagable/out/android/Android.bp.out
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ cc_binary {
"-Werror",
],
compile_multilib: "both",
owner: "toolchain",
vendor: true,
proprietary: true,
soc_specific: true,
}

cc_test {
Expand All @@ -24,6 +28,10 @@ cc_test {
"-Wall",
"-Werror",
],
owner: "toolchain",
vendor: true,
proprietary: true,
soc_specific: true,
include_build_directory: false,
auto_gen_config: false,
gtest: false,
Expand Down

0 comments on commit 0b84197

Please sign in to comment.