aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Bosch <tbosch@google.com>2019-08-19 09:55:30 -0700
committerTobias Bosch <tbosch@google.com>2019-08-19 20:57:09 +0000
commitd8aa0d03924683c67577b6e0725f3f8a90dce0bc (patch)
treebdff67d1fddfa8d7e4382c745507627b780af022
parent1c95e747af51c784a7bdbf9a584f67e90bab32df (diff)
downloadtoolchain-utils-d8aa0d03924683c67577b6e0725f3f8a90dce0bc.tar.gz
Store change id as version in the config.
This helps in debugging the wrapper. The version can be printed via the -print-config command. BUG=chromium:773875 TEST=unit test Change-Id: Ic6f84b4ccaa4a201473c408022d80c73f6ee7899 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1760971 Tested-by: Tobias Bosch <tbosch@google.com> Reviewed-by: George Burgess <gbiv@chromium.org>
-rwxr-xr-xcompiler_wrapper/build.py14
-rwxr-xr-xcompiler_wrapper/bundle.py6
-rw-r--r--compiler_wrapper/config.go179
-rw-r--r--compiler_wrapper/cros_hardened_config_test.go12
-rw-r--r--compiler_wrapper/cros_host_config_test.go14
-rw-r--r--compiler_wrapper/cros_nonhardened_config_test.go6
6 files changed, 133 insertions, 98 deletions
diff --git a/compiler_wrapper/build.py b/compiler_wrapper/build.py
index 40e8aa64..9d3384d1 100755
--- a/compiler_wrapper/build.py
+++ b/compiler_wrapper/build.py
@@ -26,13 +26,14 @@ def parse_args():
return parser.parse_args()
-def calc_go_args(args):
+def calc_go_args(args, version):
# See https://github.com/golang/go/issues/26492 for how to
# build a fully static binary in go.
ldFlags = [
'-X', 'main.ConfigName=' + args.config, '-X',
'main.UseCCache=' + args.use_ccache, '-X',
- 'main.OldWrapperPath=' + args.old_wrapper_path, "-extldflags '-static'"
+ 'main.OldWrapperPath=' + args.old_wrapper_path, '-X',
+ 'main.Version=' + version, "-extldflags '-static'"
]
return [
'go', 'build', '-o',
@@ -41,11 +42,18 @@ def calc_go_args(args):
]
+def read_version(build_dir):
+ with open(os.path.join(build_dir, 'VERSION'), 'r') as r:
+ return r.read()
+
+
def main():
args = parse_args()
+ build_dir = os.path.dirname(__file__)
+ version = read_version(build_dir)
# Note: Go does not support using absolute package names.
# So we run go inside the directory of the the build file.
- sys.exit(subprocess.call(calc_go_args(args), cwd=os.path.dirname(__file__)))
+ sys.exit(subprocess.call(calc_go_args(args, version), cwd=build_dir))
if __name__ == '__main__':
diff --git a/compiler_wrapper/bundle.py b/compiler_wrapper/bundle.py
index 0a32669e..63757f78 100755
--- a/compiler_wrapper/bundle.py
+++ b/compiler_wrapper/bundle.py
@@ -46,6 +46,11 @@ def write_readme(input_dir, output_dir, change_id):
w.write(content.format(change_id=change_id))
+def write_version(output_dir, change_id):
+ with open(os.path.join(output_dir, 'VERSION'), 'w') as w:
+ w.write(change_id)
+
+
def main():
args = parse_args()
input_dir = os.path.dirname(__file__)
@@ -54,6 +59,7 @@ def main():
os.makedirs(args.output_dir)
copy_files(input_dir, args.output_dir)
write_readme(input_dir, args.output_dir, change_id)
+ write_version(args.output_dir, change_id)
if __name__ == '__main__':
diff --git a/compiler_wrapper/config.go b/compiler_wrapper/config.go
index 70d08c15..bd5786b6 100644
--- a/compiler_wrapper/config.go
+++ b/compiler_wrapper/config.go
@@ -27,8 +27,14 @@ type config struct {
mockOldWrapperCmds bool
// Directory to store errors that were prevented with -Wno-error.
newWarningsDir string
+ // Version. Only used for printing via -print-cmd.
+ version string
}
+// Version can be set via a linker flag.
+// Values fills config.version.
+var Version = ""
+
// OldWrapperPath can be set via a linker flag.
// Value fills config.oldWrapperPath.
var OldWrapperPath = ""
@@ -50,116 +56,109 @@ func getRealConfig() (*config, error) {
if err != nil {
return nil, wrapErrorwithSourceLocf(err, "invalid format for UseCCache")
}
- config, err := getConfig(useCCache, ConfigName, OldWrapperPath)
+ config, err := getConfig(ConfigName, useCCache, OldWrapperPath, Version)
if err != nil {
return nil, err
}
return config, nil
}
-func getConfig(useCCache bool, configName string, oldWrapperPath string) (*config, error) {
+func getConfig(configName string, useCCache bool, oldWrapperPath string, version string) (*config, error) {
+ var cfg *config
switch configName {
case "cros.hardened":
- return getCrosHardenedConfig(useCCache, oldWrapperPath), nil
+ cfg = crosHardenedConfig
case "cros.nonhardened":
- return getCrosNonHardenedConfig(useCCache, oldWrapperPath), nil
+ cfg = crosNonHardenedConfig
case "cros.host":
- return getCrosHostConfig(oldWrapperPath), nil
+ cfg = crosHostConfig
default:
return nil, newErrorwithSourceLocf("unknown config name: %s", configName)
}
+ cfg.useCCache = useCCache
+ cfg.oldWrapperPath = oldWrapperPath
+ cfg.version = version
+ return cfg, nil
}
// Full hardening.
-func getCrosHardenedConfig(useCCache bool, oldWrapperPath string) *config {
- // Temporarily disable function splitting because of chromium:434751.
- return &config{
- useCCache: useCCache,
- rootRelPath: "../../../../..",
- oldWrapperPath: oldWrapperPath,
- commonFlags: []string{
- "-fstack-protector-strong",
- "-fPIE",
- "-pie",
- "-D_FORTIFY_SOURCE=2",
- "-fno-omit-frame-pointer",
- },
- gccFlags: []string{
- "-fno-reorder-blocks-and-partition",
- "-Wno-unused-local-typedefs",
- "-Wno-maybe-uninitialized",
- },
- // Temporarily disable tautological-*-compare chromium:778316.
- // Temporarily add no-unknown-warning-option to deal with old clang versions.
- // Temporarily disable Wsection since kernel gets a bunch of these. chromium:778867
- // Disable "-faddrsig" since it produces object files that strip doesn't understand, chromium:915742.
- clangFlags: []string{
- "-Qunused-arguments",
- "-grecord-gcc-switches",
- "-fno-addrsig",
- "-Wno-tautological-constant-compare",
- "-Wno-tautological-unsigned-enum-zero-compare",
- "-Wno-unknown-warning-option",
- "-Wno-section",
- "-static-libgcc",
- },
- newWarningsDir: "/tmp/fatal_clang_warnings",
- }
+// Temporarily disable function splitting because of chromium:434751.
+var crosHardenedConfig = &config{
+ rootRelPath: "../../../../..",
+ commonFlags: []string{
+ "-fstack-protector-strong",
+ "-fPIE",
+ "-pie",
+ "-D_FORTIFY_SOURCE=2",
+ "-fno-omit-frame-pointer",
+ },
+ gccFlags: []string{
+ "-fno-reorder-blocks-and-partition",
+ "-Wno-unused-local-typedefs",
+ "-Wno-maybe-uninitialized",
+ },
+ // Temporarily disable tautological-*-compare chromium:778316.
+ // Temporarily add no-unknown-warning-option to deal with old clang versions.
+ // Temporarily disable Wsection since kernel gets a bunch of these. chromium:778867
+ // Disable "-faddrsig" since it produces object files that strip doesn't understand, chromium:915742.
+ clangFlags: []string{
+ "-Qunused-arguments",
+ "-grecord-gcc-switches",
+ "-fno-addrsig",
+ "-Wno-tautological-constant-compare",
+ "-Wno-tautological-unsigned-enum-zero-compare",
+ "-Wno-unknown-warning-option",
+ "-Wno-section",
+ "-static-libgcc",
+ },
+ newWarningsDir: "/tmp/fatal_clang_warnings",
}
// Flags to be added to non-hardened toolchain.
-func getCrosNonHardenedConfig(useCCache bool, oldWrapperPath string) *config {
- return &config{
- useCCache: useCCache,
- rootRelPath: "../../../../..",
- oldWrapperPath: oldWrapperPath,
- commonFlags: []string{},
- gccFlags: []string{
- "-Wno-maybe-uninitialized",
- "-Wno-unused-local-typedefs",
- "-Wno-deprecated-declarations",
- "-Wtrampolines",
- },
- // Temporarily disable tautological-*-compare chromium:778316.
- // Temporarily add no-unknown-warning-option to deal with old clang versions.
- // Temporarily disable Wsection since kernel gets a bunch of these. chromium:778867
- clangFlags: []string{
- "-Qunused-arguments",
- "-Wno-tautological-constant-compare",
- "-Wno-tautological-unsigned-enum-zero-compare",
- "-Wno-unknown-warning-option",
- "-Wno-section",
- "-static-libgcc",
- },
- newWarningsDir: "/tmp/fatal_clang_warnings",
- }
+var crosNonHardenedConfig = &config{
+ rootRelPath: "../../../../..",
+ commonFlags: []string{},
+ gccFlags: []string{
+ "-Wno-maybe-uninitialized",
+ "-Wno-unused-local-typedefs",
+ "-Wno-deprecated-declarations",
+ "-Wtrampolines",
+ },
+ // Temporarily disable tautological-*-compare chromium:778316.
+ // Temporarily add no-unknown-warning-option to deal with old clang versions.
+ // Temporarily disable Wsection since kernel gets a bunch of these. chromium:778867
+ clangFlags: []string{
+ "-Qunused-arguments",
+ "-Wno-tautological-constant-compare",
+ "-Wno-tautological-unsigned-enum-zero-compare",
+ "-Wno-unknown-warning-option",
+ "-Wno-section",
+ "-static-libgcc",
+ },
+ newWarningsDir: "/tmp/fatal_clang_warnings",
}
// Flags to be added to host toolchain.
-func getCrosHostConfig(oldWrapperPath string) *config {
- return &config{
- isHostWrapper: true,
- useCCache: false,
- rootRelPath: "../..",
- oldWrapperPath: oldWrapperPath,
- commonFlags: []string{},
- gccFlags: []string{
- "-Wno-maybe-uninitialized",
- "-Wno-unused-local-typedefs",
- "-Wno-deprecated-declarations",
- },
- // Temporarily disable tautological-*-compare chromium:778316.
- // Temporarily add no-unknown-warning-option to deal with old clang versions.
- clangFlags: []string{
- "-Qunused-arguments",
- "-grecord-gcc-switches",
- "-fno-addrsig",
- "-Wno-unused-local-typedefs",
- "-Wno-deprecated-declarations",
- "-Wno-tautological-constant-compare",
- "-Wno-tautological-unsigned-enum-zero-compare",
- "-Wno-unknown-warning-option",
- },
- newWarningsDir: "/tmp/fatal_clang_warnings",
- }
+var crosHostConfig = &config{
+ isHostWrapper: true,
+ rootRelPath: "../..",
+ commonFlags: []string{},
+ gccFlags: []string{
+ "-Wno-maybe-uninitialized",
+ "-Wno-unused-local-typedefs",
+ "-Wno-deprecated-declarations",
+ },
+ // Temporarily disable tautological-*-compare chromium:778316.
+ // Temporarily add no-unknown-warning-option to deal with old clang versions.
+ clangFlags: []string{
+ "-Qunused-arguments",
+ "-grecord-gcc-switches",
+ "-fno-addrsig",
+ "-Wno-unused-local-typedefs",
+ "-Wno-deprecated-declarations",
+ "-Wno-tautological-constant-compare",
+ "-Wno-tautological-unsigned-enum-zero-compare",
+ "-Wno-unknown-warning-option",
+ },
+ newWarningsDir: "/tmp/fatal_clang_warnings",
}
diff --git a/compiler_wrapper/cros_hardened_config_test.go b/compiler_wrapper/cros_hardened_config_test.go
index cbce1416..f667595e 100644
--- a/compiler_wrapper/cros_hardened_config_test.go
+++ b/compiler_wrapper/cros_hardened_config_test.go
@@ -21,7 +21,11 @@ const crosHardenedNoCCacheGoldenDir = "testdata/cros_hardened_noccache_golden"
func TestCrosHardenedConfig(t *testing.T) {
withTestContext(t, func(ctx *testContext) {
useCCache := true
- ctx.updateConfig(getCrosHardenedConfig(useCCache, oldHardenedWrapperPathForTest))
+ cfg, err := getConfig("cros.hardened", useCCache, oldHardenedWrapperPathForTest, "123")
+ if err != nil {
+ t.Fatal(err)
+ }
+ ctx.updateConfig(cfg)
runGoldenRecords(ctx, crosHardenedGoldenDir, createSyswrapperGoldenInputs(ctx))
})
@@ -30,7 +34,11 @@ func TestCrosHardenedConfig(t *testing.T) {
func TestCrosHardenedConfigWithoutCCache(t *testing.T) {
withTestContext(t, func(ctx *testContext) {
useCCache := false
- ctx.updateConfig(getCrosHardenedConfig(useCCache, oldHardenedWrapperPathForTest))
+ cfg, err := getConfig("cros.hardened", useCCache, oldHardenedWrapperPathForTest, "123")
+ if err != nil {
+ t.Fatal(err)
+ }
+ ctx.updateConfig(cfg)
// Create a copy of the old wrapper where the CCACHE_DEFAULT is false.
if ctx.cfg.oldWrapperPath != "" {
diff --git a/compiler_wrapper/cros_host_config_test.go b/compiler_wrapper/cros_host_config_test.go
index 61f1b867..2ddbc397 100644
--- a/compiler_wrapper/cros_host_config_test.go
+++ b/compiler_wrapper/cros_host_config_test.go
@@ -16,7 +16,12 @@ const crosGccHostGoldenDir = "testdata/cros_gcc_host_golden"
func TestCrosClangHostConfig(t *testing.T) {
withTestContext(t, func(ctx *testContext) {
- ctx.updateConfig(getCrosHostConfig(oldClangHostWrapperPathForTest))
+ useCCache := false
+ cfg, err := getConfig("cros.host", useCCache, oldClangHostWrapperPathForTest, "123")
+ if err != nil {
+ t.Fatal(err)
+ }
+ ctx.updateConfig(cfg)
gomaPath := path.Join(ctx.tempDir, "gomacc")
ctx.writeFile(gomaPath, "")
@@ -39,7 +44,12 @@ func TestCrosClangHostConfig(t *testing.T) {
func TestCrosGccHostConfig(t *testing.T) {
withTestContext(t, func(ctx *testContext) {
- ctx.updateConfig(getCrosHostConfig(oldGccHostWrapperPathForTest))
+ useCCache := false
+ cfg, err := getConfig("cros.host", useCCache, oldClangHostWrapperPathForTest, "123")
+ if err != nil {
+ t.Fatal(err)
+ }
+ ctx.updateConfig(cfg)
gomaPath := path.Join(ctx.tempDir, "gomacc")
ctx.writeFile(gomaPath, "")
diff --git a/compiler_wrapper/cros_nonhardened_config_test.go b/compiler_wrapper/cros_nonhardened_config_test.go
index e876d309..b6748db6 100644
--- a/compiler_wrapper/cros_nonhardened_config_test.go
+++ b/compiler_wrapper/cros_nonhardened_config_test.go
@@ -14,7 +14,11 @@ const crosNonHardenedGoldenDir = "testdata/cros_nonhardened_golden"
func TestCrosNonHardenedConfig(t *testing.T) {
withTestContext(t, func(ctx *testContext) {
useCCache := true
- ctx.updateConfig(getCrosNonHardenedConfig(useCCache, oldNonHardenedWrapperPathForTest))
+ cfg, err := getConfig("cros.nonhardened", useCCache, oldNonHardenedWrapperPathForTest, "123")
+ if err != nil {
+ t.Fatal(err)
+ }
+ ctx.updateConfig(cfg)
runGoldenRecords(ctx, crosNonHardenedGoldenDir, createSyswrapperGoldenInputs(ctx))
})