Skip to content

Commit

Permalink
feat: implement bob_toolchain defaults
Browse files Browse the repository at this point in the history
This commit enables `bob_toolchain` to be
applied by default for targets which do not
specify their toolchain explicitly.

Change-Id: I994200a6b688c1be81bcfee2fc951e4f4f7d2ded
  • Loading branch information
lukokr-aarch64 committed Oct 10, 2023
1 parent 64d32f2 commit aace92c
Show file tree
Hide file tree
Showing 22 changed files with 374 additions and 6 deletions.
1 change: 1 addition & 0 deletions Blueprints
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ bootstrap_go_package {
"bob-flag",
"bob-backend",
"bob-tag",
"bob-toolchain-mapper",
],
srcs: [
"core/alias.go",
Expand Down
1 change: 1 addition & 0 deletions core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ go_library(
"//core/module",
"//core/tag",
"//core/toolchain",
"//core/toolchain/mapper",
"//internal/bpwriter",
"//internal/ccflags",
"//internal/escape",
Expand Down
18 changes: 12 additions & 6 deletions core/build_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,24 +350,30 @@ func dependerMutator(ctx blueprint.BottomUpMutatorContext) {
ctx.AddVariationDependencies(nil, tag.SharedTag, build.Shared_libs...)
}

toolchainDefault := ToolchainModuleMap.Get(ctx.ModuleDir())

// TODO: refactor this given the duplicated code pattern here.
if sl, ok := ctx.Module().(*ModuleStrictLibrary); ok {
ctx.AddVariationDependencies(nil, tag.DepTag, sl.Properties.Deps...)
if sl.Properties.Toolchain != nil {
ctx.AddVariationDependencies(nil, tag.ToolchainTag, *sl.Properties.Toolchain)
toolchain := proptools.StringDefault(sl.Properties.Toolchain, toolchainDefault)
if toolchain != "" {
ctx.AddVariationDependencies(nil, tag.ToolchainTag, toolchain)
}
}

if sb, ok := ctx.Module().(*ModuleStrictBinary); ok {
ctx.AddVariationDependencies(nil, tag.DepTag, sb.Properties.Deps...)
if sb.Properties.Toolchain != nil {
ctx.AddVariationDependencies(nil, tag.ToolchainTag, *sb.Properties.Toolchain)
toolchain := proptools.StringDefault(sb.Properties.Toolchain, toolchainDefault)
if toolchain != "" {
ctx.AddVariationDependencies(nil, tag.ToolchainTag, toolchain)
}
}

if t, ok := ctx.Module().(*ModuleTest); ok {
ctx.AddVariationDependencies(nil, tag.DepTag, t.Properties.Deps...)
if t.Properties.Toolchain != nil {
ctx.AddVariationDependencies(nil, tag.ToolchainTag, *t.Properties.Toolchain)
toolchain := proptools.StringDefault(t.Properties.Toolchain, toolchainDefault)
if toolchain != "" {
ctx.AddVariationDependencies(nil, tag.ToolchainTag, toolchain)
}
}

Expand Down
9 changes: 9 additions & 0 deletions core/module_toolchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/ARM-software/bob-build/core/flag"
"github.com/ARM-software/bob-build/core/module"
"github.com/ARM-software/bob-build/core/toolchain"
"github.com/ARM-software/bob-build/core/toolchain/mapper"
"github.com/google/blueprint"
)

Expand Down Expand Up @@ -201,3 +202,11 @@ func ModuleToolchainFactory(config *BobConfig) (blueprint.Module, []interface{})
return module, []interface{}{&module.Properties,
&module.SimpleName.Properties}
}

var ToolchainModuleMap = mapper.New() // Global lookup for toolchain names

func RegisterToolchainModules(ctx blueprint.EarlyMutatorContext) {
if _, ok := ctx.Module().(*ModuleToolchain); ok {
ToolchainModuleMap.Add(ctx.ModuleDir(), ctx.ModuleName())
}
}
1 change: 1 addition & 0 deletions core/standalone.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func Main() {
// The depender mutator adds the dependencies between binaries and libraries.
//
// The generated depender mutator add dependencies to generated source modules.
ctx.RegisterEarlyMutator("register_toolchains", RegisterToolchainModules)
ctx.RegisterBottomUpMutator("default_deps1", DefaultDepsStage1Mutator).Parallel()
ctx.RegisterBottomUpMutator("default_deps2", DefaultDepsStage2Mutator).Parallel()
ctx.RegisterTopDownMutator("features_applier", featureApplierMutator).Parallel()
Expand Down
31 changes: 31 additions & 0 deletions docs/module_types/bob_toolchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,34 @@ bob_library {
}
```

## Default Behaviour

A `bob_toolchain` will be applied to the current directory scope and recursively into child directories, unless
overwritten by another `bob_toolchain`.

This toolchain is only applied to modules which support it.

Take the following project structure as an example:

```
.
├── build.bp >>> `bob_toolchain("A")`
├── inherits
│   ├── build.bp
│   └── overwrite
│   ├── build.bp >>> `bob_toolchain("B")`
│   └── parent
│   └── build.bp
```

In this case the mapping will be:

```
`.` -> `A`
`./inherits` -> `A`
`./inherits/overwrite` -> `B`
`./inherits/overwrite/parent` -> `B`
```

> `bob_toolchain` module attributes are overwritten, and **_not_** merged.
Empty file.
4 changes: 4 additions & 0 deletions gendiffer/tests/toolchain/nesting/app/bplist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
inherits/overwrite/parent/build.bp
inherits/overwrite/build.bp
inherits/build.bp
build.bp
14 changes: 14 additions & 0 deletions gendiffer/tests/toolchain/nesting/app/build.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
bob_toolchain {
name: "default_toolchain_config",
cflags: [
"-DROOT_TOOLCHAIN=1",
],
}

bob_library {
name: "foo",
srcs: [
"src.c",
],
build_by_default: true,
}
8 changes: 8 additions & 0 deletions gendiffer/tests/toolchain/nesting/app/inherits/build.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
bob_library {
name: "uses_root",
srcs: [
"src.c",
],
build_by_default: true,

}
15 changes: 15 additions & 0 deletions gendiffer/tests/toolchain/nesting/app/inherits/overwrite/build.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
bob_toolchain {
name: "overwrites_toolchain_config",
cflags: [
"-DOVERWRITES_TOOLCHAIN=1",
],
}

bob_library {
name: "overwrites",
srcs: [
"src.c",
],
build_by_default: true,

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


bob_library {
name: "parent",
srcs: [
"src.c",
],
build_by_default: true,

}
Empty file.
50 changes: 50 additions & 0 deletions gendiffer/tests/toolchain/nesting/out/android/Android.bp.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

genrule {
name: "_check_buildbp_updates_redacted",
srcs: [
"build.bp",
"inherits/build.bp",
"inherits/overwrite/build.bp",
"inherits/overwrite/parent/build.bp",
],
out: ["androidbp_up_to_date"],
tool_files: ["scripts/verify_hash.py"],
cmd: "python $(location scripts/verify_hash.py) --hash redacted --out $(out) -- $(in)",
}

cc_library {
name: "foo",
host_supported: false,
device_supported: true,
srcs: ["src.c"],
cflags: ["-DROOT_TOOLCHAIN=1"],
compile_multilib: "both",
}

cc_library {
name: "overwrites",
host_supported: false,
device_supported: true,
srcs: ["inherits/overwrite/src.c"],
cflags: ["-DOVERWRITES_TOOLCHAIN=1"],
compile_multilib: "both",
}

cc_library {
name: "parent",
host_supported: false,
device_supported: true,
srcs: ["inherits/overwrite/parent/src.c"],
cflags: ["-DOVERWRITES_TOOLCHAIN=1"],
compile_multilib: "both",
}

cc_library {
name: "uses_root",
host_supported: false,
device_supported: true,
srcs: ["inherits/src.c"],
cflags: ["-DROOT_TOOLCHAIN=1"],
compile_multilib: "both",
}

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Empty file.
Empty file.
Loading

0 comments on commit aace92c

Please sign in to comment.