Merge "Move environment staleness check to soong_ui."
This commit is contained in:
commit
b821b9b852
9 changed files with 16 additions and 130 deletions
|
@ -12,7 +12,6 @@ bootstrap_go_package {
|
||||||
"soong",
|
"soong",
|
||||||
"soong-android-soongconfig",
|
"soong-android-soongconfig",
|
||||||
"soong-bazel",
|
"soong-bazel",
|
||||||
"soong-env",
|
|
||||||
"soong-shared",
|
"soong-shared",
|
||||||
"soong-ui-metrics_proto",
|
"soong-ui-metrics_proto",
|
||||||
],
|
],
|
||||||
|
|
|
@ -21,7 +21,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"android/soong/env"
|
"android/soong/shared"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This file supports dependencies on environment variables. During build manifest generation,
|
// This file supports dependencies on environment variables. During build manifest generation,
|
||||||
|
@ -113,7 +113,7 @@ func (c *envSingleton) GenerateBuildActions(ctx SingletonContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := env.EnvFileContents(envDeps)
|
data, err := shared.EnvFileContents(envDeps)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Errorf(err.Error())
|
ctx.Errorf(err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ bootstrap_go_binary {
|
||||||
"soong",
|
"soong",
|
||||||
"soong-android",
|
"soong-android",
|
||||||
"soong-bp2build",
|
"soong-bp2build",
|
||||||
"soong-env",
|
|
||||||
"soong-ui-metrics_proto",
|
"soong-ui-metrics_proto",
|
||||||
],
|
],
|
||||||
srcs: [
|
srcs: [
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
// Copyright 2015 Google Inc. All rights reserved.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package {
|
|
||||||
default_applicable_licenses: ["Android-Apache-2.0"],
|
|
||||||
}
|
|
||||||
|
|
||||||
bootstrap_go_binary {
|
|
||||||
name: "soong_env",
|
|
||||||
deps: [
|
|
||||||
"soong-env",
|
|
||||||
],
|
|
||||||
srcs: [
|
|
||||||
"soong_env.go",
|
|
||||||
],
|
|
||||||
default: true,
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
// Copyright 2015 Google Inc. All rights reserved.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// soong_env determines if the given soong environment file (usually ".soong.environment") is stale
|
|
||||||
// by comparing its contents to the current corresponding environment variable values.
|
|
||||||
// It fails if the file cannot be opened or corrupted, or its contents differ from the current
|
|
||||||
// values.
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"android/soong/env"
|
|
||||||
)
|
|
||||||
|
|
||||||
func usage() {
|
|
||||||
fmt.Fprintf(os.Stderr, "usage: soong_env env_file\n")
|
|
||||||
fmt.Fprintf(os.Stderr, "exits with success if the environment varibles in env_file match\n")
|
|
||||||
fmt.Fprintf(os.Stderr, "the current environment\n")
|
|
||||||
flag.PrintDefaults()
|
|
||||||
os.Exit(2)
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is a simple executable packaging, and the real work happens in env.StaleEnvFile.
|
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
if flag.NArg() != 1 {
|
|
||||||
usage()
|
|
||||||
}
|
|
||||||
|
|
||||||
stale, err := env.StaleEnvFile(flag.Arg(0))
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "error: %s\n", err.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if stale {
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
11
env/Android.bp
vendored
11
env/Android.bp
vendored
|
@ -1,11 +0,0 @@
|
||||||
package {
|
|
||||||
default_applicable_licenses: ["Android-Apache-2.0"],
|
|
||||||
}
|
|
||||||
|
|
||||||
bootstrap_go_package {
|
|
||||||
name: "soong-env",
|
|
||||||
pkgPath: "android/soong/env",
|
|
||||||
srcs: [
|
|
||||||
"env.go",
|
|
||||||
],
|
|
||||||
}
|
|
|
@ -6,6 +6,7 @@ bootstrap_go_package {
|
||||||
name: "soong-shared",
|
name: "soong-shared",
|
||||||
pkgPath: "android/soong/shared",
|
pkgPath: "android/soong/shared",
|
||||||
srcs: [
|
srcs: [
|
||||||
|
"env.go",
|
||||||
"paths.go",
|
"paths.go",
|
||||||
],
|
],
|
||||||
deps: [
|
deps: [
|
||||||
|
|
|
@ -12,15 +12,15 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// env implements the environment JSON file handling for the soong_env command line tool run before
|
// Implements the environment JSON file handling for serializing the
|
||||||
// the builder and for the env writer in the builder.
|
// environment variables that were used in soong_build so that soong_ui can
|
||||||
package env
|
// check whether they have changed
|
||||||
|
package shared
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
|
||||||
"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ func EnvFileContents(envDeps map[string]string) ([]byte, error) {
|
||||||
// Reads and deserializes a Soong environment file located at the given file path to determine its
|
// Reads and deserializes a Soong environment file located at the given file path to determine its
|
||||||
// staleness. If any environment variable values have changed, it prints them out and returns true.
|
// staleness. If any environment variable values have changed, it prints them out and returns true.
|
||||||
// Failing to read or parse the file also causes it to return true.
|
// Failing to read or parse the file also causes it to return true.
|
||||||
func StaleEnvFile(filepath string) (bool, error) {
|
func StaleEnvFile(filepath string, getenv func(string) string) (bool, error) {
|
||||||
data, err := ioutil.ReadFile(filepath)
|
data, err := ioutil.ReadFile(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return true, err
|
return true, err
|
||||||
|
@ -74,7 +74,7 @@ func StaleEnvFile(filepath string) (bool, error) {
|
||||||
for _, entry := range contents {
|
for _, entry := range contents {
|
||||||
key := entry.Key
|
key := entry.Key
|
||||||
old := entry.Value
|
old := entry.Value
|
||||||
cur := os.Getenv(key)
|
cur := getenv(key)
|
||||||
if old != cur {
|
if old != cur {
|
||||||
changed = append(changed, fmt.Sprintf("%s (%q -> %q)", key, old, cur))
|
changed = append(changed, fmt.Sprintf("%s (%q -> %q)", key, old, cur))
|
||||||
}
|
}
|
|
@ -19,8 +19,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
|
"android/soong/shared"
|
||||||
soong_metrics_proto "android/soong/ui/metrics/metrics_proto"
|
soong_metrics_proto "android/soong/ui/metrics/metrics_proto"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
@ -79,29 +79,12 @@ func runSoong(ctx Context, config Config) {
|
||||||
defer ctx.EndTrace()
|
defer ctx.EndTrace()
|
||||||
|
|
||||||
envFile := filepath.Join(config.SoongOutDir(), ".soong.environment")
|
envFile := filepath.Join(config.SoongOutDir(), ".soong.environment")
|
||||||
envTool := filepath.Join(config.SoongOutDir(), ".bootstrap/bin/soong_env")
|
getenv := func(k string) string {
|
||||||
if _, err := os.Stat(envFile); err == nil {
|
v, _ := config.Environment().Get(k)
|
||||||
if _, err := os.Stat(envTool); err == nil {
|
return v
|
||||||
cmd := Command(ctx, config, "soong_env", envTool, envFile)
|
}
|
||||||
cmd.Sandbox = soongSandbox
|
if stale, _ := shared.StaleEnvFile(envFile, getenv); stale {
|
||||||
|
os.Remove(envFile)
|
||||||
var buf strings.Builder
|
|
||||||
cmd.Stdout = &buf
|
|
||||||
cmd.Stderr = &buf
|
|
||||||
if err := cmd.Run(); err != nil {
|
|
||||||
ctx.Verboseln("soong_env failed, forcing manifest regeneration")
|
|
||||||
os.Remove(envFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
if buf.Len() > 0 {
|
|
||||||
ctx.Verboseln(buf.String())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ctx.Verboseln("Missing soong_env tool, forcing manifest regeneration")
|
|
||||||
os.Remove(envFile)
|
|
||||||
}
|
|
||||||
} else if !os.IsNotExist(err) {
|
|
||||||
ctx.Fatalf("Failed to stat %f: %v", envFile, err)
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue