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

Commit 50d60173 authored by Liz Kammer's avatar Liz Kammer Committed by Gerrit Code Review
Browse files

Merge "Dump bazel product config in Soong"

parents 2fad4368 09f947d6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -567,7 +567,7 @@ func (p *bazelPaths) intermediatesDir() string {
// Returns the path where the contents of the @soong_injection repository live.
// It is used by Soong to tell Bazel things it cannot over the command line.
func (p *bazelPaths) injectedFilesDir() string {
	return filepath.Join(p.buildDir, "soong_injection")
	return filepath.Join(p.buildDir, bazel.SoongInjectionDirName)
}

// Returns the path of the synthetic Bazel workspace that contains a symlink
+41 −12
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import (
	"github.com/google/blueprint/proptools"

	"android/soong/android/soongconfig"
	"android/soong/bazel"
	"android/soong/remoteexec"
)

@@ -169,7 +170,7 @@ func loadConfig(config *config) error {

// loadFromConfigFile loads and decodes configuration options from a JSON file
// in the current working directory.
func loadFromConfigFile(configurable jsonConfigurable, filename string) error {
func loadFromConfigFile(configurable *productVariables, filename string) error {
	// Try to open the file
	configFileReader, err := os.Open(filename)
	defer configFileReader.Close()
@@ -194,13 +195,20 @@ func loadFromConfigFile(configurable jsonConfigurable, filename string) error {
		}
	}

	// No error
	return nil
	if Bool(configurable.GcovCoverage) && Bool(configurable.ClangCoverage) {
		return fmt.Errorf("GcovCoverage and ClangCoverage cannot both be set")
	}

	configurable.Native_coverage = proptools.BoolPtr(
		Bool(configurable.GcovCoverage) ||
			Bool(configurable.ClangCoverage))

	return saveToBazelConfigFile(configurable, filepath.Dir(filename))
}

// atomically writes the config file in case two copies of soong_build are running simultaneously
// (for example, docs generation and ninja manifest generation)
func saveToConfigFile(config jsonConfigurable, filename string) error {
func saveToConfigFile(config *productVariables, filename string) error {
	data, err := json.MarshalIndent(&config, "", "    ")
	if err != nil {
		return fmt.Errorf("cannot marshal config data: %s", err.Error())
@@ -229,6 +237,35 @@ func saveToConfigFile(config jsonConfigurable, filename string) error {
	return nil
}

func saveToBazelConfigFile(config *productVariables, outDir string) error {
	dir := filepath.Join(outDir, bazel.SoongInjectionDirName, "product_config")
	err := createDirIfNonexistent(dir, os.ModePerm)
	if err != nil {
		return fmt.Errorf("Could not create dir %s: %s", dir, err)
	}

	data, err := json.MarshalIndent(&config, "", "    ")
	if err != nil {
		return fmt.Errorf("cannot marshal config data: %s", err.Error())
	}

	bzl := []string{
		bazel.GeneratedBazelFileWarning,
		fmt.Sprintf(`_product_vars = json.decode("""%s""")`, data),
		"product_vars = _product_vars\n",
	}
	err = ioutil.WriteFile(filepath.Join(dir, "product_variables.bzl"), []byte(strings.Join(bzl, "\n")), 0644)
	if err != nil {
		return fmt.Errorf("Could not write .bzl config file %s", err)
	}
	err = ioutil.WriteFile(filepath.Join(dir, "BUILD"), []byte(bazel.GeneratedBazelFileWarning), 0644)
	if err != nil {
		return fmt.Errorf("Could not write BUILD config file %s", err)
	}

	return nil
}

// NullConfig returns a mostly empty Config for use by standalone tools like dexpreopt_gen that
// use the android package.
func NullConfig(buildDir string) Config {
@@ -448,14 +485,6 @@ func NewConfig(srcDir, buildDir string, moduleListFile string, availableEnv map[
		config.AndroidFirstDeviceTarget = firstTarget(config.Targets[Android], "lib64", "lib32")[0]
	}

	if Bool(config.productVariables.GcovCoverage) && Bool(config.productVariables.ClangCoverage) {
		return Config{}, fmt.Errorf("GcovCoverage and ClangCoverage cannot both be set")
	}

	config.productVariables.Native_coverage = proptools.BoolPtr(
		Bool(config.productVariables.GcovCoverage) ||
			Bool(config.productVariables.ClangCoverage))

	config.BazelContext, err = NewBazelContext(config)
	config.bp2buildPackageConfig = bp2buildDefaultConfig
	config.bp2buildModuleTypeConfig = make(map[string]bool)
+4 −0
Original line number Diff line number Diff line
@@ -1990,6 +1990,10 @@ func RemoveAllOutputDir(path WritablePath) error {

func CreateOutputDirIfNonexistent(path WritablePath, perm os.FileMode) error {
	dir := absolutePath(path.String())
	return createDirIfNonexistent(dir, perm)
}

func createDirIfNonexistent(dir string, perm os.FileMode) error {
	if _, err := os.Stat(dir); os.IsNotExist(err) {
		return os.MkdirAll(dir, os.ModePerm)
	} else {
+1 −1
Original line number Diff line number Diff line
@@ -282,7 +282,7 @@ type productVariables struct {
	NativeCoverageExcludePaths []string `json:",omitempty"`

	// Set by NewConfig
	Native_coverage *bool
	Native_coverage *bool `json:",omitempty"`

	SanitizeHost       []string `json:",omitempty"`
	SanitizeDevice     []string `json:",omitempty"`
+4 −0
Original line number Diff line number Diff line
@@ -18,6 +18,10 @@ const (

	// Run bazel as a ninja executer
	BazelNinjaExecRunName = RunName("bazel-ninja-exec")

	SoongInjectionDirName = "soong_injection"

	GeneratedBazelFileWarning = "# GENERATED FOR BAZEL FROM SOONG. DO NOT EDIT"
)

// String returns the name of the run.
Loading