Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ddebd2c8 authored by Lukács T. Berki's avatar Lukács T. Berki Committed by Gerrit Code Review
Browse files

Merge "cd to / before running soong_build ."

parents 7d3f2cae 7690c099
Loading
Loading
Loading
Loading
+27 −38
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ package android
import (
	"fmt"
	"os"
	"os/exec"
	"strings"
	"syscall"

@@ -34,37 +33,27 @@ import (
var originalEnv map[string]string
var soongDelveListen string
var soongDelvePath string
var soongDelveEnv []string

func init() {
	// Delve support needs to read this environment variable very early, before NewConfig has created a way to
	// access originalEnv with dependencies.  Store the value where soong_build can find it, it will manually
	// ensure the dependencies are created.
	soongDelveListen = os.Getenv("SOONG_DELVE")
	soongDelvePath = os.Getenv("SOONG_DELVE_PATH")
	if soongDelvePath == "" {
		soongDelvePath, _ = exec.LookPath("dlv")
	}
var isDebugging bool

	originalEnv = make(map[string]string)
	soongDelveEnv = []string{}
	for _, env := range os.Environ() {
		idx := strings.IndexRune(env, '=')
		if idx != -1 {
			originalEnv[env[:idx]] = env[idx+1:]
			if env[:idx] != "SOONG_DELVE" && env[:idx] != "SOONG_DELVE_PATH" {
				soongDelveEnv = append(soongDelveEnv, env)
			}
		}
func InitEnvironment(envFile string) {
	var err error
	originalEnv, err = shared.EnvFromFile(envFile)
	if err != nil {
		panic(err)
	}

	// Clear the environment to prevent use of os.Getenv(), which would not provide dependencies on environment
	// variable values.  The environment is available through ctx.Config().Getenv, ctx.Config().IsEnvTrue, etc.
	os.Clearenv()
	soongDelveListen = originalEnv["SOONG_DELVE"]
	soongDelvePath = originalEnv["SOONG_DELVE_PATH"]
}

// Returns whether the current process is running under Delve due to
// ReexecWithDelveMaybe().
func IsDebugging() bool {
	return isDebugging
}
func ReexecWithDelveMaybe() {
	if soongDelveListen == "" {
	isDebugging = os.Getenv("SOONG_DELVE_REEXECUTED") == "true"
	if isDebugging || soongDelveListen == "" {
		return
	}

@@ -72,6 +61,17 @@ func ReexecWithDelveMaybe() {
		fmt.Fprintln(os.Stderr, "SOONG_DELVE is set but failed to find dlv")
		os.Exit(1)
	}

	soongDelveEnv := []string{}
	for _, env := range os.Environ() {
		idx := strings.IndexRune(env, '=')
		if idx != -1 {
			soongDelveEnv = append(soongDelveEnv, env)
		}
	}

	soongDelveEnv = append(soongDelveEnv, "SOONG_DELVE_REEXECUTED=true")

	dlvArgv := []string{
		soongDelvePath,
		"--listen=:" + soongDelveListen,
@@ -88,17 +88,6 @@ func ReexecWithDelveMaybe() {
	os.Exit(1)
}

// getenv checks either os.Getenv or originalEnv so that it works before or after the init()
// function above.  It doesn't add any dependencies on the environment variable, so it should
// only be used for values that won't change.  For values that might change use ctx.Config().Getenv.
func getenv(key string) string {
	if originalEnv == nil {
		return os.Getenv(key)
	} else {
		return originalEnv[key]
	}
}

func EnvSingleton() Singleton {
	return &envSingleton{}
}
@@ -108,7 +97,7 @@ type envSingleton struct{}
func (c *envSingleton) GenerateBuildActions(ctx SingletonContext) {
	envDeps := ctx.Config().EnvDeps()

	envFile := PathForOutput(ctx, ".soong.environment")
	envFile := PathForOutput(ctx, "soong.environment.used")
	if ctx.Failed() {
		return
	}
+2 −23
Original line number Diff line number Diff line
@@ -14,29 +14,8 @@

package android

import (
	"fmt"
	"os"
)

func init() {
	// Stash the working directory in a private variable and then change the working directory
	// to "/", which will prevent untracked accesses to files by Go Soong plugins. The
	// SOONG_SANDBOX_SOONG_BUILD environment variable is set by soong_ui, and is not
	// overrideable on the command line.

	orig, err := os.Getwd()
	if err != nil {
		panic(fmt.Errorf("failed to get working directory: %s", err))
	}
	absSrcDir = orig

	if getenv("SOONG_SANDBOX_SOONG_BUILD") == "true" {
		err = os.Chdir("/")
		if err != nil {
			panic(fmt.Errorf("failed to change working directory to '/': %s", err))
		}
	}
func InitSandbox(topDir string) {
	absSrcDir = topDir
}

// DO NOT USE THIS FUNCTION IN NEW CODE.
+2 −1
Original line number Diff line number Diff line
@@ -34,7 +34,8 @@ func DocsSingleton() Singleton {
type docsSingleton struct{}

func primaryBuilderPath(ctx SingletonContext) Path {
	primaryBuilder, err := filepath.Rel(ctx.Config().BuildDir(), os.Args[0])
	buildDir := absolutePath(ctx.Config().BuildDir())
	primaryBuilder, err := filepath.Rel(buildDir, os.Args[0])
	if err != nil {
		ctx.Errorf("path to primary builder %q is not in build dir %q",
			os.Args[0], ctx.Config().BuildDir())
+2 −1
Original line number Diff line number Diff line
@@ -2534,7 +2534,8 @@ func TestVendorApex(t *testing.T) {
	var builder strings.Builder
	data.Custom(&builder, name, prefix, "", data)
	androidMk := builder.String()
	ensureContains(t, androidMk, `LOCAL_MODULE_PATH := /tmp/target/product/test_device/vendor/apex`)
	installPath := path.Join(buildDir, "../target/product/test_device/vendor/apex")
	ensureContains(t, androidMk, "LOCAL_MODULE_PATH := "+installPath)

	apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
	requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"])
+13 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import (
	"path/filepath"
	"strings"

	"android/soong/shared"
	"github.com/google/blueprint/bootstrap"

	"android/soong/android"
@@ -28,11 +29,15 @@ import (
)

var (
	topDir            string
	outDir            string
	docFile           string
	bazelQueryViewDir string
)

func init() {
	flag.StringVar(&topDir, "top", "", "Top directory of the Android source tree")
	flag.StringVar(&outDir, "out", "", "Soong output directory (usually $TOP/out/soong)")
	flag.StringVar(&docFile, "soong_docs", "", "build documentation file to output")
	flag.StringVar(&bazelQueryViewDir, "bazel_queryview_dir", "", "path to the bazel queryview directory")
}
@@ -80,15 +85,22 @@ func newConfig(srcDir string) android.Config {
}

func main() {
	android.ReexecWithDelveMaybe()
	flag.Parse()

	android.InitSandbox(topDir)
	android.InitEnvironment(shared.JoinPath(topDir, outDir, "soong.environment.available"))
	android.ReexecWithDelveMaybe()

	// The top-level Blueprints file is passed as the first argument.
	srcDir := filepath.Dir(flag.Arg(0))
	var ctx *android.Context
	configuration := newConfig(srcDir)
	extraNinjaDeps := []string{configuration.ProductVariablesFileName}

	// These two are here so that we restart a non-debugged soong_build when the
	// user sets SOONG_DELVE the first time.
	configuration.Getenv("SOONG_DELVE")
	configuration.Getenv("SOONG_DELVE_PATH")
	// Read the SOONG_DELVE again through configuration so that there is a dependency on the environment variable
	// and soong_build will rerun when it is set for the first time.
	if listen := configuration.Getenv("SOONG_DELVE"); listen != "" {
Loading