aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper/bisect_flag.go
diff options
context:
space:
mode:
Diffstat (limited to 'compiler_wrapper/bisect_flag.go')
-rw-r--r--compiler_wrapper/bisect_flag.go45
1 files changed, 40 insertions, 5 deletions
diff --git a/compiler_wrapper/bisect_flag.go b/compiler_wrapper/bisect_flag.go
index 2a805352..62bcbd31 100644
--- a/compiler_wrapper/bisect_flag.go
+++ b/compiler_wrapper/bisect_flag.go
@@ -4,22 +4,57 @@
package main
-const bisectPythonCommand = "import bisect_driver; sys.exit(bisect_driver.bisect_driver(sys.argv[1], sys.argv[2], sys.argv[3:]))"
+import (
+ "os"
+ "path/filepath"
+)
+
+// Note: We keep this code in python as golang has no builtin
+// shlex function.
+const bisectPythonCommand = `
+import bisect_driver
+import shlex
+import sys
+
+def ExpandArgs(args, target):
+ for arg in args:
+ if arg[0] == '@':
+ with open(arg[1:], 'rb') as f:
+ ExpandArgs(shlex.split(f.read()), target)
+ else:
+ target.append(arg)
+ return target
+
+stage = sys.argv[1]
+dir = sys.argv[2]
+execargs = ExpandArgs(sys.argv[3:], [])
+
+sys.exit(bisect_driver.bisect_driver(stage, dir, execargs))
+`
func getBisectStage(env env) string {
value, _ := env.getenv("BISECT_STAGE")
return value
}
-func calcBisectCommand(env env, bisectStage string, compilerCmd *command) *command {
+func calcBisectCommand(env env, cfg *config, bisectStage string, compilerCmd *command) (*command, error) {
bisectDir, _ := env.getenv("BISECT_DIR")
if bisectDir == "" {
- bisectDir = "/tmp/sysroot_bisect"
+ if cfg.isAndroidWrapper {
+ homeDir, err := os.UserHomeDir()
+ if err != nil {
+ return nil, err
+ }
+ bisectDir = filepath.Join(homeDir, "ANDROID_BISECT")
+ } else {
+ bisectDir = "/tmp/sysroot_bisect"
+ }
}
absCompilerPath := getAbsCmdPath(env, compilerCmd)
return &command{
- Path: "/usr/bin/python2",
+ Path: "/usr/bin/env",
Args: append([]string{
+ "python",
"-c",
bisectPythonCommand,
bisectStage,
@@ -27,5 +62,5 @@ func calcBisectCommand(env env, bisectStage string, compilerCmd *command) *comma
absCompilerPath,
}, compilerCmd.Args...),
EnvUpdates: compilerCmd.EnvUpdates,
- }
+ }, nil
}