Skip to content

Commit

Permalink
feat: add support for local wrapper
Browse files Browse the repository at this point in the history
This change allows the use of local scripts
in `bob_toolchain` `build_wrapper` to mimic
the behaviour of legacy targets.

Change-Id: Iad6fac9a6c1897a3ce89898f8c682d7519fbd2cb
  • Loading branch information
lukokr-aarch64 committed Oct 11, 2023
1 parent 083d30a commit ac53905
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 36 deletions.
13 changes: 13 additions & 0 deletions core/module_toolchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,19 @@ func (m *ModuleToolchain) GetTags() []string {
return m.Properties.TagableProps.GetTags()
}

func (m *ModuleToolchain) processPaths(ctx blueprint.BaseModuleContext) {
if m.Properties.Build_wrapper != nil {
// Copies core/build_props.go to duplicate the behaviour for `build_wrapper`
*m.Properties.Build_wrapper = strings.TrimSpace(*m.Properties.Build_wrapper)
firstWord := strings.SplitN(*m.Properties.Build_wrapper, " ", 1)[0]
if firstWord[0] != '/' {
if strings.ContainsAny(firstWord, "/") {
*m.Properties.Build_wrapper = getBackendPathInSourceDir(getGenerator(ctx), *m.Properties.Build_wrapper)
}
}
}
}

func ModuleToolchainFactory(config *BobConfig) (blueprint.Module, []interface{}) {
module := &ModuleToolchain{}

Expand Down
36 changes: 33 additions & 3 deletions gendiffer/tests/toolchain/build_wrapper/app/build.bp
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,56 @@ bob_toolchain {
build_wrapper: "ccache",
}

bob_toolchain {
name: "wraps_with_local_file",
// Test source files and Mconfig vars
build_wrapper: "src/wrapper.py {{.target_objcopy_binary}}",
}

bob_library {
name: "lib",
name: "lib_a",
srcs: [
"src.c",
],
toolchain: "toolchain",
}

bob_executable {
name: "bin",
name: "bin_a",
srcs: [
"src.c",
],
toolchain: "toolchain",
}

bob_test {
name: "test",
name: "test_a",
srcs: [
"src.c",
],
toolchain: "toolchain",
}

bob_library {
name: "lib_b",
srcs: [
"src.c",
],
toolchain: "wraps_with_local_file",
}

bob_executable {
name: "bin_b",
srcs: [
"src.c",
],
toolchain: "wraps_with_local_file",
}

bob_test {
name: "test_b",
srcs: [
"src.c",
],
toolchain: "wraps_with_local_file",
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ genrule {
}

cc_binary {
name: "bin",
name: "bin_a",
srcs: ["src.c"],
compile_multilib: "both",
}

cc_binary {
name: "bin_b",
srcs: ["src.c"],
compile_multilib: "both",
}
Expand Down
159 changes: 127 additions & 32 deletions gendiffer/tests/toolchain/build_wrapper/out/linux/build.ninja.out
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,24 @@ rule g.bootstrap.cp
description = cp ${out}

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Module: bin
# Module: bin_a
# Variant: target
# Type: bob_executable
# Factory: github.com/ARM-software/bob-build/core.Main.func1.1
# Defined: build.bp:redacted

m.bin_target.cflags =
m.bin_target.conlyflags =
m.bin_a_target.cflags =
m.bin_a_target.conlyflags =

build ${g.bob.BuildDir}/target/objects/bin/src.c.o: g.bob.cc $
build ${g.bob.BuildDir}/target/objects/bin_a/src.c.o: g.bob.cc $
${g.bob.SrcDir}/src.c
build_wrapper = ccache
ccompiler = gcc
cflags = ${m.bin_target.cflags}
conlyflags = ${m.bin_target.conlyflags}
cflags = ${m.bin_a_target.cflags}
conlyflags = ${m.bin_a_target.conlyflags}

build ${g.bob.BuildDir}/target/executable/bin: g.bob.executable $
${g.bob.BuildDir}/target/objects/bin/src.c.o
build ${g.bob.BuildDir}/target/executable/bin_a: g.bob.executable $
${g.bob.BuildDir}/target/objects/bin_a/src.c.o
build_wrapper = ccache
ldflags = -Wl,--as-needed
ldlibs =
Expand All @@ -79,28 +79,58 @@ build ${g.bob.BuildDir}/target/executable/bin: g.bob.executable $
shared_libs_flags = -Wl,-rpath-link,${g.bob.BuildDir}/target/shared
static_libs =

build bin: phony ${g.bob.BuildDir}/target/executable/bin
default bin
build bin_a: phony ${g.bob.BuildDir}/target/executable/bin_a
default bin_a

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Module: lib
# Module: bin_b
# Variant: target
# Type: bob_executable
# Factory: github.com/ARM-software/bob-build/core.Main.func1.1
# Defined: build.bp:redacted

m.bin_b_target.cflags =
m.bin_b_target.conlyflags =

build ${g.bob.BuildDir}/target/objects/bin_b/src.c.o: g.bob.cc $
${g.bob.SrcDir}/src.c
build_wrapper = ${g.bob.SrcDir}/src/wrapper.py objcopy
ccompiler = gcc
cflags = ${m.bin_b_target.cflags}
conlyflags = ${m.bin_b_target.conlyflags}

build ${g.bob.BuildDir}/target/executable/bin_b: g.bob.executable $
${g.bob.BuildDir}/target/objects/bin_b/src.c.o
build_wrapper = ${g.bob.SrcDir}/src/wrapper.py objcopy
ldflags = -Wl,--as-needed
ldlibs =
linker = g++
shared_libs_dir = ${g.bob.BuildDir}/target/shared
shared_libs_flags = -Wl,-rpath-link,${g.bob.BuildDir}/target/shared
static_libs =

build bin_b: phony ${g.bob.BuildDir}/target/executable/bin_b
default bin_b

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Module: lib_a
# Variant: target
# Type: bob_library
# Factory: github.com/ARM-software/bob-build/core.Main.func1.1
# Defined: build.bp:redacted

m.lib_target.cflags =
m.lib_target.conlyflags =
m.lib_a_target.cflags =
m.lib_a_target.conlyflags =

build ${g.bob.BuildDir}/target/objects/lib/src.c.o: g.bob.cc $
build ${g.bob.BuildDir}/target/objects/lib_a/src.c.o: g.bob.cc $
${g.bob.SrcDir}/src.c
build_wrapper = ccache
ccompiler = gcc
cflags = ${m.lib_target.cflags}
conlyflags = ${m.lib_target.conlyflags}
cflags = ${m.lib_a_target.cflags}
conlyflags = ${m.lib_a_target.conlyflags}

build ${g.bob.BuildDir}/target/shared/lib.so: g.bob.shared_library $
${g.bob.BuildDir}/target/objects/lib/src.c.o
build ${g.bob.BuildDir}/target/shared/lib_a.so: g.bob.shared_library $
${g.bob.BuildDir}/target/objects/lib_a/src.c.o
build_wrapper = ccache
ldflags = -Wl,--as-needed
ldlibs =
Expand All @@ -109,33 +139,68 @@ build ${g.bob.BuildDir}/target/shared/lib.so: g.bob.shared_library $
shared_libs_flags = -Wl,-rpath-link,${g.bob.BuildDir}/target/shared
static_libs =

build ${g.bob.BuildDir}/target/static/lib.a: g.bob.static_library $
${g.bob.BuildDir}/target/objects/lib/src.c.o
build ${g.bob.BuildDir}/target/static/lib_a.a: g.bob.static_library $
${g.bob.BuildDir}/target/objects/lib_a/src.c.o
ar = ar
build_wrapper = ccache

build lib: phony ${g.bob.BuildDir}/target/static/lib.a $
${g.bob.BuildDir}/target/shared/lib.so
build lib_a: phony ${g.bob.BuildDir}/target/static/lib_a.a $
${g.bob.BuildDir}/target/shared/lib_a.so

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Module: lib_b
# Variant: target
# Type: bob_library
# Factory: github.com/ARM-software/bob-build/core.Main.func1.1
# Defined: build.bp:redacted

m.lib_b_target.cflags =
m.lib_b_target.conlyflags =

build ${g.bob.BuildDir}/target/objects/lib_b/src.c.o: g.bob.cc $
${g.bob.SrcDir}/src.c
build_wrapper = ${g.bob.SrcDir}/src/wrapper.py objcopy
ccompiler = gcc
cflags = ${m.lib_b_target.cflags}
conlyflags = ${m.lib_b_target.conlyflags}

build ${g.bob.BuildDir}/target/shared/lib_b.so: g.bob.shared_library $
${g.bob.BuildDir}/target/objects/lib_b/src.c.o
build_wrapper = ${g.bob.SrcDir}/src/wrapper.py objcopy
ldflags = -Wl,--as-needed
ldlibs =
linker = g++
shared_libs_dir = ${g.bob.BuildDir}/target/shared
shared_libs_flags = -Wl,-rpath-link,${g.bob.BuildDir}/target/shared
static_libs =

build ${g.bob.BuildDir}/target/static/lib_b.a: g.bob.static_library $
${g.bob.BuildDir}/target/objects/lib_b/src.c.o
ar = ar
build_wrapper = ${g.bob.SrcDir}/src/wrapper.py objcopy

build lib_b: phony ${g.bob.BuildDir}/target/static/lib_b.a $
${g.bob.BuildDir}/target/shared/lib_b.so

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Module: test
# Module: test_a
# Variant: target
# Type: bob_test
# Factory: github.com/ARM-software/bob-build/core.Main.func1.1
# Defined: build.bp:redacted

m.test_target.cflags =
m.test_target.conlyflags =
m.test_a_target.cflags =
m.test_a_target.conlyflags =

build ${g.bob.BuildDir}/target/objects/test/src.c.o: g.bob.cc $
build ${g.bob.BuildDir}/target/objects/test_a/src.c.o: g.bob.cc $
${g.bob.SrcDir}/src.c
build_wrapper = ccache
ccompiler = gcc
cflags = ${m.test_target.cflags}
conlyflags = ${m.test_target.conlyflags}
cflags = ${m.test_a_target.cflags}
conlyflags = ${m.test_a_target.conlyflags}

build ${g.bob.BuildDir}/target/executable/test: g.bob.executable $
${g.bob.BuildDir}/target/objects/test/src.c.o
build ${g.bob.BuildDir}/target/executable/test_a: g.bob.executable $
${g.bob.BuildDir}/target/objects/test_a/src.c.o
build_wrapper = ccache
ldflags = -Wl,--as-needed
ldlibs =
Expand All @@ -144,8 +209,38 @@ build ${g.bob.BuildDir}/target/executable/test: g.bob.executable $
shared_libs_flags = -Wl,-rpath-link,${g.bob.BuildDir}/target/shared
static_libs =

build test: phony ${g.bob.BuildDir}/target/executable/test
default test
build test_a: phony ${g.bob.BuildDir}/target/executable/test_a
default test_a

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Module: test_b
# Variant: target
# Type: bob_test
# Factory: github.com/ARM-software/bob-build/core.Main.func1.1
# Defined: build.bp:redacted

m.test_b_target.cflags =
m.test_b_target.conlyflags =

build ${g.bob.BuildDir}/target/objects/test_b/src.c.o: g.bob.cc $
${g.bob.SrcDir}/src.c
build_wrapper = ${g.bob.SrcDir}/src/wrapper.py objcopy
ccompiler = gcc
cflags = ${m.test_b_target.cflags}
conlyflags = ${m.test_b_target.conlyflags}

build ${g.bob.BuildDir}/target/executable/test_b: g.bob.executable $
${g.bob.BuildDir}/target/objects/test_b/src.c.o
build_wrapper = ${g.bob.SrcDir}/src/wrapper.py objcopy
ldflags = -Wl,--as-needed
ldlibs =
linker = g++
shared_libs_dir = ${g.bob.BuildDir}/target/shared
shared_libs_flags = -Wl,-rpath-link,${g.bob.BuildDir}/target/shared
static_libs =

build test_b: phony ${g.bob.BuildDir}/target/executable/test_b
default test_b

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Singleton: bootstrap
Expand Down

0 comments on commit ac53905

Please sign in to comment.