aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper/main.go
diff options
context:
space:
mode:
authorTobias Bosch <tbosch@google.com>2019-06-10 15:50:33 -0700
committerTobias Bosch <tbosch@google.com>2019-06-20 15:41:37 +0000
commitef8f969c8ea2498c2a8aa701cb2e83833339f9a8 (patch)
treea3c988999263f4e43ec561908b452093ad169b53 /compiler_wrapper/main.go
parent87d457dfc5ae0a7631917523eb3c62751453e4bb (diff)
downloadtoolchain-utils-ef8f969c8ea2498c2a8aa701cb2e83833339f9a8.tar.gz
Initial version of a go version of the compiler wrapper.
Still calls the old wrapper if one of the following flags is given: - Xclang-path - clang-syntax - env WITH_TIDY - env FORCE_DISABLE_WERROR - env GETRUSAGE - env BISECT_STAGE BUG=chromium:773875 TEST=Unit tests that also verify the produced command against the TEST=existing compiler wrapper. Change-Id: I1e0a720ce9f485d8015deefb2682f2cb760d82e4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1652057 Reviewed-by: Manoj Gupta <manojgupta@chromium.org> Reviewed-by: Tobias Bosch <tbosch@google.com> Reviewed-by: George Burgess <gbiv@chromium.org> Tested-by: Tobias Bosch <tbosch@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Diffstat (limited to 'compiler_wrapper/main.go')
-rw-r--r--compiler_wrapper/main.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/compiler_wrapper/main.go b/compiler_wrapper/main.go
new file mode 100644
index 00000000..5323a301
--- /dev/null
+++ b/compiler_wrapper/main.go
@@ -0,0 +1,56 @@
+// +build cros
+
+// This binary uses the following build tags:
+// - cros: Whether the wrapper should be built for ChromeOS
+// - nonhardened: For a non-hardened set of compiler flags
+// - hardened: For a hardened set of compiler flags
+//
+// There is a bash script for every meaningful combination.
+// E.g. ./build_cros_hardened_wrapper.sh will build the ChromeOS
+// hardened compiler wrapper.
+//
+// Test arguments:
+// - crosroot: Specifies the ChromeOS toolchain root directory (aka chroot).
+// If this is given, tests will compare the produced commands against the
+// old compiler wrapper.
+//
+// Examples:
+// - run all tests and compare output against old compiler wrapper:
+// go test third_party/toolchain-utils/compiler_wrapper/ -v --crosroot=$HOME/chromiumos/chroot/
+// - run all tests in isolation:
+// go test third_party/toolchain-utils/compiler_wrapper/ -v
+package main
+
+import (
+ "log"
+ "os/exec"
+ "syscall"
+)
+
+func main() {
+ wrapperCmd := newProcessCommand()
+ env, err := newProcessEnv()
+ if err != nil {
+ log.Fatal(err)
+ }
+ cfg := getRealConfig()
+ if shouldForwardToOldWrapper(env, wrapperCmd) {
+ err := forwardToOldWrapper(env, cfg, wrapperCmd)
+ if err != nil {
+ log.Fatal(err)
+ }
+ return
+ }
+
+ cmd, err := calcCompilerCommandAndCompareToOld(env, cfg, wrapperCmd)
+ if err != nil {
+ log.Fatal(err)
+ }
+ if err := execCmd(newExecCmd(env, cmd)); err != nil {
+ log.Fatal(err)
+ }
+}
+
+func execCmd(cmd *exec.Cmd) error {
+ return syscall.Exec(cmd.Path, cmd.Args, cmd.Env)
+}