Index: ct/go/util/util.go |
diff --git a/ct/go/util/util.go b/ct/go/util/util.go |
index e4291fbed729b83df942f967d0187b4538772688..34823d247e2b67b2b9ddc4511f3fb183321a8514 100644 |
--- a/ct/go/util/util.go |
+++ b/ct/go/util/util.go |
@@ -445,7 +445,7 @@ func TriggerSwarmingTask(pagesetType, taskPrefix, isolateName string, hardTimeou |
return fmt.Errorf("len(genJSONs) was %d and len(tasksToHashes) was %d", len(genJSONs), len(tasksToHashes)) |
} |
// Trigger swarming using the isolate hashes. |
- dimensions := map[string]string{"pool": SWARMING_POOL} |
+ dimensions := map[string]string{"pool": SWARMING_POOL, "cores": strconv.Itoa(2)} |
tasks, err := s.TriggerSwarmingTasks(tasksToHashes, dimensions, swarming.RECOMMENDED_PRIORITY, swarming.RECOMMENDED_EXPIRATION, hardTimeout, ioTimeout, false) |
if err != nil { |
return fmt.Errorf("Could not trigger swarming task: %s", err) |
@@ -684,3 +684,61 @@ func writeRowsToCSV(csvPath string, headers []string, values [][]string) error { |
} |
return nil |
} |
+ |
+func TriggerBuildRepoSwarmingTask(taskName, runID, repo, targetPlatform string, hashes, patches []string, singleBuild bool, hardTimeout, ioTimeout time.Duration) (string, error) { |
+ // Instantiate the swarming client. |
+ workDir, err := ioutil.TempDir("", "swarming_work_") |
+ if err != nil { |
+ return "", fmt.Errorf("Could not get temp dir: %s", err) |
+ } |
+ s, err := swarming.NewSwarmingClient(workDir) |
+ if err != nil { |
+ return "", fmt.Errorf("Could not instantiate swarming client: %s", err) |
+ } |
+ //defer s.Cleanup() |
+ // Create isolated.gen.json. |
+ // Get path to isolate files. |
+ _, currentFile, _, _ := runtime.Caller(0) |
+ pathToIsolates := filepath.Join(filepath.Dir(filepath.Dir(filepath.Dir(currentFile))), "isolates") |
+ isolateArgs := map[string]string{ |
+ "RUN_ID": runID, |
+ "REPO": repo, |
+ "HASHES": strings.Join(hashes, ","), |
+ "PATCHES": strings.Join(patches, ","), |
+ "SINGLE_BUILD": strconv.FormatBool(singleBuild), |
+ "TARGET_PLATFORM": targetPlatform, |
+ } |
+ genJSON, err := s.CreateIsolatedGenJSON(path.Join(pathToIsolates, BUILD_REPO_ISOLATE), s.WorkDir, "linux", taskName, isolateArgs, []string{}) |
+ if err != nil { |
+ return "", fmt.Errorf("Could not create isolated.gen.json for task %s: %s", taskName, err) |
+ } |
+ // Batcharchive the task. |
+ tasksToHashes, err := s.BatchArchiveTargets([]string{genJSON}, BATCHARCHIVE_TIMEOUT) |
+ if err != nil { |
+ return "", fmt.Errorf("Could not batch archive target: %s", err) |
+ } |
+ // Trigger swarming using the isolate hash. |
+ dimensions := map[string]string{ |
+ "pool": SWARMING_POOL, |
+ "cores": strconv.Itoa(32), |
+ } |
+ tasks, err := s.TriggerSwarmingTasks(tasksToHashes, dimensions, swarming.RECOMMENDED_PRIORITY, swarming.RECOMMENDED_EXPIRATION, hardTimeout, ioTimeout, false) |
+ if err != nil { |
+ return "", fmt.Errorf("Could not trigger swarming task: %s", err) |
+ } |
+ if len(tasks) != 1 { |
+ return "", fmt.Errorf("Expected a single task instead got: %v", tasks) |
+ } |
+ // Collect all tasks and log the ones that fail. |
+ task := tasks[0] |
+ _, outputDir, err := task.Collect(s) |
+ if err != nil { |
+ return "", fmt.Errorf("task %s failed: %s", task.Title, err) |
+ } |
+ outputFile := filepath.Join(outputDir, BUILD_OUTPUT_FILENAME) |
+ contents, err := ioutil.ReadFile(outputFile) |
+ if err != nil { |
+ return "", fmt.Errorf("Could not read outputfile %s: %s", outputFile, err) |
+ } |
+ return string(contents), nil |
+} |