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

Commit 3d31a128 authored by Christopher Parsons's avatar Christopher Parsons Committed by Gerrit Code Review
Browse files

Merge "Add --bazel-mode and --bazel-mode-dev"

parents b28effac ef615e58
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -620,4 +620,9 @@ var (
		"prebuilt_platform-robolectric-4.5.1-prebuilt",
		"prebuilt_currysrc_org.eclipse",
	}

	ProdMixedBuildsEnabledList = []string{
		// This list left intentionally empty for now. Add specific module names
		// to have them built by Bazel in Prod Mixed Builds mode.
	}
)
+5 −5
Original line number Diff line number Diff line
@@ -219,16 +219,16 @@ type bp2BuildConversionAllowlist struct {
	// in the synthetic Bazel workspace.
	keepExistingBuildFile map[string]bool

	// Per-module allowlist to always opt modules in of both bp2build and mixed builds.
	// These modules are usually in directories with many other modules that are not ready for
	// conversion.
	// Per-module allowlist to always opt modules into both bp2build and Bazel Dev Mode mixed
	// builds. These modules are usually in directories with many other modules that are not ready
	// for conversion.
	//
	// A module can either be in this list or its directory allowlisted entirely
	// in bp2buildDefaultConfig, but not both at the same time.
	moduleAlwaysConvert map[string]bool

	// Per-module-type allowlist to always opt modules in to both bp2build and mixed builds
	// when they have the same type as one listed.
	// Per-module-type allowlist to always opt modules in to both bp2build and
	// Bazel Dev Mode mixed builds when they have the same type as one listed.
	moduleTypeAlwaysConvert map[string]bool

	// Per-module denylist to always opt modules out of bp2build conversion.
+26 −15
Original line number Diff line number Diff line
@@ -343,18 +343,20 @@ func (m noopBazelContext) AqueryDepsets() []bazel.AqueryDepset {
}

func NewBazelContext(c *config) (BazelContext, error) {
	if !c.IsMixedBuildsEnabled() {
		return noopBazelContext{}, nil
	}
	var modulesDefaultToBazel bool
	disabledModules := map[string]bool{}
	enabledModules := map[string]bool{}

	p, err := bazelPathsFromConfig(c)
	if err != nil {
		return nil, err
	switch c.BuildMode {
	case BazelProdMode:
		modulesDefaultToBazel = false

		for _, enabledProdModule := range allowlists.ProdMixedBuildsEnabledList {
			enabledModules[enabledProdModule] = true
		}
	case BazelDevMode:
		modulesDefaultToBazel = true

	// TODO(cparsons): Use a different allowlist depending on prod vs. dev
	// bazel mode.
	disabledModules := map[string]bool{}
		// Don't use partially-converted cc_library targets in mixed builds,
		// since mixed builds would generally rely on both static and shared
		// variants of a cc_library.
@@ -364,12 +366,21 @@ func NewBazelContext(c *config) (BazelContext, error) {
		for _, disabledDevModule := range allowlists.MixedBuildsDisabledList {
			disabledModules[disabledDevModule] = true
		}
	default:
		return noopBazelContext{}, nil
	}

	p, err := bazelPathsFromConfig(c)
	if err != nil {
		return nil, err
	}

	return &bazelContext{
		bazelRunner:           &builtinBazelRunner{},
		paths:                 p,
		requests:              make(map[cqueryKey]bool),
		modulesDefaultToBazel: true,
		modulesDefaultToBazel: modulesDefaultToBazel,
		bazelEnabledModules:   enabledModules,
		bazelDisabledModules:  disabledModules,
	}, nil
}
+1 −12
Original line number Diff line number Diff line
@@ -96,7 +96,6 @@ const (

	// Use bazel during analysis of build modules from an allowlist carefully
	// curated by the build team to be proven stable.
	// TODO(cparsons): Implement this mode.
	BazelProdMode
)

@@ -481,14 +480,6 @@ func NewConfig(moduleListFile string, buildMode SoongBuildMode, runGoTests bool,
		config.AndroidFirstDeviceTarget = FirstTarget(config.Targets[Android], "lib64", "lib32")[0]
	}

	// Checking USE_BAZEL_ANALYSIS must be done here instead of in the caller, so
	// that we can invoke IsEnvTrue (which also registers the env var as a
	// dependency of the build).
	// TODO(cparsons): Remove this hack once USE_BAZEL_ANALYSIS is removed.
	if buildMode == AnalysisNoBazel && config.IsEnvTrue("USE_BAZEL_ANALYSIS") {
		buildMode = BazelDevMode
	}

	config.BuildMode = buildMode
	config.BazelContext, err = NewBazelContext(config)
	config.bp2buildPackageConfig = GetBp2BuildAllowList()
@@ -678,9 +669,7 @@ func (c *config) DeviceName() string {
// DeviceProduct returns the current product target. There could be multiple of
// these per device type.
//
// NOTE: Do not base conditional logic on this value. It may break product
//
//	inheritance.
// NOTE: Do not base conditional logic on this value. It may break product inheritance.
func (c *config) DeviceProduct() string {
	return *c.productVariables.DeviceProduct
}
+6 −0
Original line number Diff line number Diff line
@@ -84,6 +84,8 @@ func init() {
	flag.StringVar(&bp2buildMarker, "bp2build_marker", "", "If set, run bp2build, touch the specified marker file then exit")
	flag.StringVar(&cmdlineArgs.OutFile, "o", "build.ninja", "the Ninja file to output")
	flag.BoolVar(&cmdlineArgs.EmptyNinjaFile, "empty-ninja-file", false, "write out a 0-byte ninja file")
	flag.BoolVar(&cmdlineArgs.BazelMode, "bazel-mode", false, "use bazel for analysis of certain modules")
	flag.BoolVar(&cmdlineArgs.BazelModeDev, "bazel-mode-dev", false, "use bazel for analysis of a large number of modules (less stable)")

	// Flags that probably shouldn't be flags of soong_build but we haven't found
	// the time to remove them yet
@@ -131,6 +133,10 @@ func newConfig(availableEnv map[string]string) android.Config {
		buildMode = android.GenerateModuleGraph
	} else if docFile != "" {
		buildMode = android.GenerateDocFile
	} else if cmdlineArgs.BazelModeDev {
		buildMode = android.BazelDevMode
	} else if cmdlineArgs.BazelMode {
		buildMode = android.BazelProdMode
	} else {
		buildMode = android.AnalysisNoBazel
	}
Loading