| OLD | NEW |
| 1 // Utility to create and manage chromium builds. | 1 // Utility to create and manage chromium builds. |
| 2 package util | 2 package util |
| 3 | 3 |
| 4 import ( | 4 import ( |
| 5 "fmt" | 5 "fmt" |
| 6 "io/ioutil" | 6 "io/ioutil" |
| 7 "os" | 7 "os" |
| 8 "path/filepath" | 8 "path/filepath" |
| 9 "runtime" | 9 "runtime" |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 // CreateChromiumBuild creates a chromium build using the specified arguments. | 34 // CreateChromiumBuild creates a chromium build using the specified arguments. |
| 35 | 35 |
| 36 // runID is the unique id of the current run (typically requester + timestamp). | 36 // runID is the unique id of the current run (typically requester + timestamp). |
| 37 // targetPlatform is the platform the benchmark will run on (Android / Linux ). | 37 // targetPlatform is the platform the benchmark will run on (Android / Linux ). |
| 38 // chromiumHash is the hash the checkout should be synced to. If not specified t
hen | 38 // chromiumHash is the hash the checkout should be synced to. If not specified t
hen |
| 39 // Chromium's Tot hash is used. | 39 // Chromium's Tot hash is used. |
| 40 // skiaHash is the hash the checkout should be synced to. If not specified then | 40 // skiaHash is the hash the checkout should be synced to. If not specified then |
| 41 // Skia's LKGR hash is used (the hash in Chromium's DEPS file). | 41 // Skia's LKGR hash is used (the hash in Chromium's DEPS file). |
| 42 // applyPatches if true looks for Chromium/Skia patches in the temp dir and | 42 // applyPatches if true looks for Chromium/Skia patches in the temp dir and |
| 43 // runs once with the patch applied and once without the patch applied. | 43 // runs once with the patch applied and once without the patch applied. |
| 44 func CreateChromiumBuild(runID, targetPlatform, chromiumHash, skiaHash string, a
pplyPatches bool) (string, string, error) { | 44 // uploadSingleBuild if true does not upload a 2nd build of Chromium. |
| 45 func CreateChromiumBuild(runID, targetPlatform, chromiumHash, skiaHash string, a
pplyPatches, uploadSingleBuild bool) (string, string, error) { |
| 45 // Determine which build dir and fetch target to use. | 46 // Determine which build dir and fetch target to use. |
| 46 var chromiumBuildDir, fetchTarget string | 47 var chromiumBuildDir, fetchTarget string |
| 47 if targetPlatform == "Android" { | 48 if targetPlatform == "Android" { |
| 48 chromiumBuildDir = filepath.Join(ChromiumBuildsDir, "android_bas
e") | 49 chromiumBuildDir = filepath.Join(ChromiumBuildsDir, "android_bas
e") |
| 49 fetchTarget = "android" | 50 fetchTarget = "android" |
| 50 } else if targetPlatform == "Linux" { | 51 } else if targetPlatform == "Linux" { |
| 51 chromiumBuildDir = filepath.Join(ChromiumBuildsDir, "linux_base"
) | 52 chromiumBuildDir = filepath.Join(ChromiumBuildsDir, "linux_base"
) |
| 52 fetchTarget = "chromium" | 53 fetchTarget = "chromium" |
| 53 } else { | 54 } else { |
| 54 return "", "", fmt.Errorf("Unrecognized target_platform %s", tar
getPlatform) | 55 return "", "", fmt.Errorf("Unrecognized target_platform %s", tar
getPlatform) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 117 |
| 117 // Upload to Google Storage. | 118 // Upload to Google Storage. |
| 118 gs, err := NewGsUtil(nil) | 119 gs, err := NewGsUtil(nil) |
| 119 if err != nil { | 120 if err != nil { |
| 120 return "", "", fmt.Errorf("Could not create GS object: %s", err) | 121 return "", "", fmt.Errorf("Could not create GS object: %s", err) |
| 121 } | 122 } |
| 122 if err := uploadChromiumBuild(filepath.Join(chromiumBuildDir, "src", "ou
t", "Release"), filepath.Join(CHROMIUM_BUILDS_DIR_NAME, googleStorageDirName), t
argetPlatform, gs); err != nil { | 123 if err := uploadChromiumBuild(filepath.Join(chromiumBuildDir, "src", "ou
t", "Release"), filepath.Join(CHROMIUM_BUILDS_DIR_NAME, googleStorageDirName), t
argetPlatform, gs); err != nil { |
| 123 return "", "", fmt.Errorf("There was an error uploaded the chrom
ium build dir %s: %s", filepath.Join(chromiumBuildDir, "src", "out", "Release"),
err) | 124 return "", "", fmt.Errorf("There was an error uploaded the chrom
ium build dir %s: %s", filepath.Join(chromiumBuildDir, "src", "out", "Release"),
err) |
| 124 } | 125 } |
| 125 | 126 |
| 126 » // Check for the applypatch flag and reset and then build again and copy
to | 127 » // Create and upload another chromium build if the uploadSingleBuild fla
g is false. This build |
| 127 » // google storage. | 128 » // will be created without applying patches. |
| 128 » if applyPatches { | 129 » if !uploadSingleBuild { |
| 129 » » // Now build chromium without the patches and upload it to Googl
e Storage. | |
| 130 | |
| 131 // Make sure we are starting from a clean slate. | 130 // Make sure we are starting from a clean slate. |
| 132 if err := resetChromiumCheckout(filepath.Join(chromiumBuildDir,
"src")); err != nil { | 131 if err := resetChromiumCheckout(filepath.Join(chromiumBuildDir,
"src")); err != nil { |
| 133 return "", "", fmt.Errorf("Could not reset the chromium
checkout in %s: %s", chromiumBuildDir, err) | 132 return "", "", fmt.Errorf("Could not reset the chromium
checkout in %s: %s", chromiumBuildDir, err) |
| 134 } | 133 } |
| 135 // Build chromium. | 134 // Build chromium. |
| 136 if err := buildChromium(chromiumBuildDir, targetPlatform); err !
= nil { | 135 if err := buildChromium(chromiumBuildDir, targetPlatform); err !
= nil { |
| 137 return "", "", fmt.Errorf("There was an error building c
hromium %s + skia %s: %s", chromiumHash, skiaHash, err) | 136 return "", "", fmt.Errorf("There was an error building c
hromium %s + skia %s: %s", chromiumHash, skiaHash, err) |
| 138 } | 137 } |
| 139 // Upload to Google Storage. | 138 // Upload to Google Storage. |
| 140 googleStorageDirName = fmt.Sprintf("try-%s-%s-%s-nopatch", getTr
uncatedHash(chromiumHash), getTruncatedHash(skiaHash), runID) | 139 googleStorageDirName = fmt.Sprintf("try-%s-%s-%s-nopatch", getTr
uncatedHash(chromiumHash), getTruncatedHash(skiaHash), runID) |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 return fmt.Errorf("Could not reset Skia's checkout in %s: %s", s
kiaDir, err) | 240 return fmt.Errorf("Could not reset Skia's checkout in %s: %s", s
kiaDir, err) |
| 242 } | 241 } |
| 243 // Reset Chromium. | 242 // Reset Chromium. |
| 244 if err := ResetCheckout(chromiumSrcDir); err != nil { | 243 if err := ResetCheckout(chromiumSrcDir); err != nil { |
| 245 return fmt.Errorf("Could not reset Chromium's checkout in %s: %s
", chromiumSrcDir, err) | 244 return fmt.Errorf("Could not reset Chromium's checkout in %s: %s
", chromiumSrcDir, err) |
| 246 } | 245 } |
| 247 return nil | 246 return nil |
| 248 } | 247 } |
| 249 | 248 |
| 250 func applyRepoPatches(chromiumSrcDir, runID string) error { | 249 func applyRepoPatches(chromiumSrcDir, runID string) error { |
| 251 » // Apply Skia patch. | 250 » // Apply Skia patch if it exists. |
| 252 skiaDir := filepath.Join(chromiumSrcDir, "third_party", "skia") | 251 skiaDir := filepath.Join(chromiumSrcDir, "third_party", "skia") |
| 253 skiaPatch := filepath.Join(os.TempDir(), runID+".skia.patch") | 252 skiaPatch := filepath.Join(os.TempDir(), runID+".skia.patch") |
| 254 » skiaPatchFile, _ := os.Open(skiaPatch) | 253 » if _, err := os.Stat(skiaPatch); err == nil { |
| 255 » skiaPatchFileInfo, _ := skiaPatchFile.Stat() | 254 » » skiaPatchFile, _ := os.Open(skiaPatch) |
| 256 » if skiaPatchFileInfo.Size() > 10 { | 255 » » skiaPatchFileInfo, _ := skiaPatchFile.Stat() |
| 257 » » if err := ApplyPatch(skiaPatch, skiaDir); err != nil { | 256 » » if skiaPatchFileInfo.Size() > 10 { |
| 258 » » » return fmt.Errorf("Could not apply Skia's patch in %s: %
s", skiaDir, err) | 257 » » » if err := ApplyPatch(skiaPatch, skiaDir); err != nil { |
| 258 » » » » return fmt.Errorf("Could not apply Skia's patch
in %s: %s", skiaDir, err) |
| 259 » » » } |
| 259 } | 260 } |
| 260 } | 261 } |
| 261 » // Apply Chromium patch. | 262 » // Apply Chromium patch if it exists. |
| 262 chromiumPatch := filepath.Join(os.TempDir(), runID+".chromium.patch") | 263 chromiumPatch := filepath.Join(os.TempDir(), runID+".chromium.patch") |
| 263 » chromiumPatchFile, _ := os.Open(chromiumPatch) | 264 » if _, err := os.Stat(chromiumPatch); err == nil { |
| 264 » chromiumPatchFileInfo, _ := chromiumPatchFile.Stat() | 265 » » chromiumPatchFile, _ := os.Open(chromiumPatch) |
| 265 » if chromiumPatchFileInfo.Size() > 10 { | 266 » » chromiumPatchFileInfo, _ := chromiumPatchFile.Stat() |
| 266 » » if err := ApplyPatch(chromiumPatch, chromiumSrcDir); err != nil
{ | 267 » » if chromiumPatchFileInfo.Size() > 10 { |
| 267 » » » return fmt.Errorf("Could not apply Chromium's patch in %
s: %s", chromiumSrcDir, err) | 268 » » » if err := ApplyPatch(chromiumPatch, chromiumSrcDir); err
!= nil { |
| 269 » » » » return fmt.Errorf("Could not apply Chromium's pa
tch in %s: %s", chromiumSrcDir, err) |
| 270 » » » } |
| 268 } | 271 } |
| 269 } | 272 } |
| 270 return nil | 273 return nil |
| 271 } | 274 } |
| 272 | 275 |
| 273 func InstallChromeAPK(chromiumBuildName string) error { | 276 func InstallChromeAPK(chromiumBuildName string) error { |
| 274 // Install the APK on the Android device. | 277 // Install the APK on the Android device. |
| 275 chromiumApk := filepath.Join(ChromiumBuildsDir, chromiumBuildName, ApkNa
me) | 278 chromiumApk := filepath.Join(ChromiumBuildsDir, chromiumBuildName, ApkNa
me) |
| 276 glog.Infof("Installing the APK at %s", chromiumApk) | 279 glog.Infof("Installing the APK at %s", chromiumApk) |
| 277 err := ExecuteCmd(BINARY_ADB, []string{"install", "-r", chromiumApk}, []
string{}, | 280 err := ExecuteCmd(BINARY_ADB, []string{"install", "-r", chromiumApk}, []
string{}, |
| 278 ADB_INSTALL_TIMEOUT, nil, nil) | 281 ADB_INSTALL_TIMEOUT, nil, nil) |
| 279 if err != nil { | 282 if err != nil { |
| 280 return fmt.Errorf("Could not install the chromium APK at %s: %s"
, chromiumBuildName, err) | 283 return fmt.Errorf("Could not install the chromium APK at %s: %s"
, chromiumBuildName, err) |
| 281 } | 284 } |
| 282 return nil | 285 return nil |
| 283 } | 286 } |
| OLD | NEW |