BUILD_NUMBER and BUILD_HOSTNAME doesn't affect kati regeneration
* Extract BUILD_NUMBER, BUILD_HOSTNAME to file to avoid kati change * Handle FILE_NAME_TAG_PLACEHOLDER string in dist in build/make/packaging/distdir.mk Ignore-AOSP-First: there are internal use cases of FILE_NAME_TAG Test: check if kati isn't invoked even though BUILD_NUMBER, BUILD_HOSTNAME is changed Test: m && m, and check if the second m is no-op Bug: 278060169 (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:1fb4ece718bd34f9c47754c14281c7ad644bb174) Merged-In: I65eefc6bb86d4076098a1bf8b317b4cb88201499 Change-Id: I65eefc6bb86d4076098a1bf8b317b4cb88201499
This commit is contained in:
committed by
Cherrypicker Worker
parent
19f380eb6a
commit
2050c90e2f
@@ -242,7 +242,7 @@ func (s *sdkRepoHost) AndroidMk() android.AndroidMkData {
|
|||||||
fmt.Fprintln(w, ".PHONY:", name, "sdk_repo", "sdk-repo-"+name)
|
fmt.Fprintln(w, ".PHONY:", name, "sdk_repo", "sdk-repo-"+name)
|
||||||
fmt.Fprintln(w, "sdk_repo", "sdk-repo-"+name+":", strings.Join(s.FilesToInstall().Strings(), " "))
|
fmt.Fprintln(w, "sdk_repo", "sdk-repo-"+name+":", strings.Join(s.FilesToInstall().Strings(), " "))
|
||||||
|
|
||||||
fmt.Fprintf(w, "$(call dist-for-goals,sdk_repo sdk-repo-%s,%s:%s-$(FILE_NAME_TAG).zip)\n\n", s.BaseModuleName(), s.outputFile.String(), s.outputBaseName)
|
fmt.Fprintf(w, "$(call dist-for-goals,sdk_repo sdk-repo-%s,%s:%s-FILE_NAME_TAG_PLACEHOLDER.zip)\n\n", s.BaseModuleName(), s.outputFile.String(), s.outputBaseName)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@ import (
|
|||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"android/soong/ui/metrics"
|
"android/soong/ui/metrics"
|
||||||
"android/soong/ui/status"
|
"android/soong/ui/status"
|
||||||
@@ -66,6 +67,21 @@ func genKatiSuffix(ctx Context, config Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func writeValueIfChanged(ctx Context, config Config, dir string, filename string, value string) {
|
||||||
|
filePath := filepath.Join(dir, filename)
|
||||||
|
previousValue := ""
|
||||||
|
rawPreviousValue, err := ioutil.ReadFile(filePath)
|
||||||
|
if err == nil {
|
||||||
|
previousValue = string(rawPreviousValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
if previousValue != value {
|
||||||
|
if err = ioutil.WriteFile(filePath, []byte(value), 0666); err != nil {
|
||||||
|
ctx.Fatalf("Failed to write: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Base function to construct and run the Kati command line with additional
|
// Base function to construct and run the Kati command line with additional
|
||||||
// arguments, and a custom function closure to mutate the environment Kati runs
|
// arguments, and a custom function closure to mutate the environment Kati runs
|
||||||
// in.
|
// in.
|
||||||
@@ -157,28 +173,57 @@ func runKati(ctx Context, config Config, extraSuffix string, args []string, envF
|
|||||||
}
|
}
|
||||||
cmd.Stderr = cmd.Stdout
|
cmd.Stderr = cmd.Stdout
|
||||||
|
|
||||||
// Apply the caller's function closure to mutate the environment variables.
|
var username string
|
||||||
envFunc(cmd.Environment)
|
|
||||||
|
|
||||||
// Pass on various build environment metadata to Kati.
|
// Pass on various build environment metadata to Kati.
|
||||||
if _, ok := cmd.Environment.Get("BUILD_USERNAME"); !ok {
|
if usernameFromEnv, ok := cmd.Environment.Get("BUILD_USERNAME"); !ok {
|
||||||
username := "unknown"
|
username = "unknown"
|
||||||
if u, err := user.Current(); err == nil {
|
if u, err := user.Current(); err == nil {
|
||||||
username = u.Username
|
username = u.Username
|
||||||
} else {
|
} else {
|
||||||
ctx.Println("Failed to get current user:", err)
|
ctx.Println("Failed to get current user:", err)
|
||||||
}
|
}
|
||||||
cmd.Environment.Set("BUILD_USERNAME", username)
|
cmd.Environment.Set("BUILD_USERNAME", username)
|
||||||
|
} else {
|
||||||
|
username = usernameFromEnv
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := cmd.Environment.Get("BUILD_HOSTNAME"); !ok {
|
hostname, ok := cmd.Environment.Get("BUILD_HOSTNAME")
|
||||||
hostname, err := os.Hostname()
|
if !ok {
|
||||||
|
hostname, err = os.Hostname()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Println("Failed to read hostname:", err)
|
ctx.Println("Failed to read hostname:", err)
|
||||||
hostname = "unknown"
|
hostname = "unknown"
|
||||||
}
|
}
|
||||||
cmd.Environment.Set("BUILD_HOSTNAME", hostname)
|
cmd.Environment.Set("BUILD_HOSTNAME", hostname)
|
||||||
}
|
}
|
||||||
|
writeValueIfChanged(ctx, config, config.SoongOutDir(), "build_hostname.txt", hostname)
|
||||||
|
|
||||||
|
// BUILD_NUMBER should be set to the source control value that
|
||||||
|
// represents the current state of the source code. E.g., a
|
||||||
|
// perforce changelist number or a git hash. Can be an arbitrary string
|
||||||
|
// (to allow for source control that uses something other than numbers),
|
||||||
|
// but must be a single word and a valid file name.
|
||||||
|
//
|
||||||
|
// If no BUILD_NUMBER is set, create a useful "I am an engineering build
|
||||||
|
// from this date/time" value. Make it start with a non-digit so that
|
||||||
|
// anyone trying to parse it as an integer will probably get "0".
|
||||||
|
cmd.Environment.Unset("HAS_BUILD_NUMBER")
|
||||||
|
buildNumber, ok := cmd.Environment.Get("BUILD_NUMBER")
|
||||||
|
if ok {
|
||||||
|
cmd.Environment.Set("HAS_BUILD_NUMBER", "true")
|
||||||
|
writeValueIfChanged(ctx, config, config.OutDir(), "file_name_tag.txt", buildNumber)
|
||||||
|
} else {
|
||||||
|
buildNumber = fmt.Sprintf("eng.%.6s.%s", username, time.Now().Format("20060102.150405" /* YYYYMMDD.HHMMSS */))
|
||||||
|
cmd.Environment.Set("HAS_BUILD_NUMBER", "false")
|
||||||
|
writeValueIfChanged(ctx, config, config.OutDir(), "file_name_tag.txt", username)
|
||||||
|
}
|
||||||
|
// Write the build number to a file so it can be read back in
|
||||||
|
// without changing the command line every time. Avoids rebuilds
|
||||||
|
// when using ninja.
|
||||||
|
writeValueIfChanged(ctx, config, config.SoongOutDir(), "build_number.txt", buildNumber)
|
||||||
|
|
||||||
|
// Apply the caller's function closure to mutate the environment variables.
|
||||||
|
envFunc(cmd.Environment)
|
||||||
|
|
||||||
cmd.StartOrFatal()
|
cmd.StartOrFatal()
|
||||||
// Set up the ToolStatus command line reader for Kati for a consistent UI
|
// Set up the ToolStatus command line reader for Kati for a consistent UI
|
||||||
@@ -336,6 +381,7 @@ func runKatiPackage(ctx Context, config Config) {
|
|||||||
"ANDROID_BUILD_SHELL",
|
"ANDROID_BUILD_SHELL",
|
||||||
"DIST_DIR",
|
"DIST_DIR",
|
||||||
"OUT_DIR",
|
"OUT_DIR",
|
||||||
|
"FILE_NAME_TAG",
|
||||||
}...)
|
}...)
|
||||||
|
|
||||||
if config.Dist() {
|
if config.Dist() {
|
||||||
|
Reference in New Issue
Block a user