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

Commit 76d9446e authored by Yu Liu's avatar Yu Liu
Browse files

Remove 3 make vars related globals from cc.

Replace them with providers.

Bug: 358427516
Test: Manually compare the generated ninja files.
Change-Id: Ifbf217974542a0adbe8e4b1953a96f6533008cb3
parent 59855831
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -660,3 +660,13 @@ func (m *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool) {
	v, loaded := m.Map.LoadOrStore(key, value)
	return v.(V), loaded
}

// AppendIfNotZero append the given value to the slice if it is not the zero value
// for its type.
func AppendIfNotZero[T comparable](slice []T, value T) []T {
	var zeroValue T // Get the zero value of the type T
	if value != zeroValue {
		return append(slice, value)
	}
	return slice
}
+32 −3
Original line number Diff line number Diff line
@@ -35,6 +35,14 @@ import (
	"android/soong/genrule"
)

type CcMakeVarsInfo struct {
	WarningsAllowed string
	UsingWnoError   string
	MissingProfile  string
}

var CcMakeVarsInfoProvider = blueprint.NewProvider[*CcMakeVarsInfo]()

func init() {
	RegisterCCBuildComponents(android.InitRegistrationContext)

@@ -531,6 +539,7 @@ type ModuleContextIntf interface {
	getSharedFlags() *SharedFlags
	notInPlatform() bool
	optimizeForSize() bool
	getOrCreateMakeVarsInfo() *CcMakeVarsInfo
}

type SharedFlags struct {
@@ -848,6 +857,7 @@ type Module struct {
	hod         android.HostOrDeviceSupported
	multilib    android.Multilib
	testModule  bool
	incremental bool

	// Allowable SdkMemberTypes of this module type.
	sdkMemberTypes []android.SdkMemberType
@@ -913,8 +923,16 @@ type Module struct {
	hasSysprop      bool
	hasWinMsg       bool
	hasYacc         bool

	makeVarsInfo *CcMakeVarsInfo
}

func (c *Module) IncrementalSupported() bool {
	return c.incremental
}

var _ blueprint.Incremental = (*Module)(nil)

func (c *Module) AddJSONData(d *map[string]interface{}) {
	c.AndroidModuleBase().AddJSONData(d)
	(*d)["Cc"] = map[string]interface{}{
@@ -1700,6 +1718,13 @@ func (ctx *moduleContextImpl) notInPlatform() bool {
	return ctx.mod.NotInPlatform()
}

func (ctx *moduleContextImpl) getOrCreateMakeVarsInfo() *CcMakeVarsInfo {
	if ctx.mod.makeVarsInfo == nil {
		ctx.mod.makeVarsInfo = &CcMakeVarsInfo{}
	}
	return ctx.mod.makeVarsInfo
}

func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
	return &Module{
		hod:      hod,
@@ -2091,6 +2116,10 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
	}

	c.setOutputFiles(ctx)

	if c.makeVarsInfo != nil {
		android.SetProvider(ctx, CcMakeVarsInfoProvider, c.makeVarsInfo)
	}
}

func (c *Module) setOutputFiles(ctx ModuleContext) {
+2 −2
Original line number Diff line number Diff line
@@ -685,10 +685,10 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
	if len(srcs) > 0 {
		module := ctx.ModuleDir() + "/Android.bp:" + ctx.ModuleName()
		if inList("-Wno-error", flags.Local.CFlags) || inList("-Wno-error", flags.Local.CppFlags) {
			addToModuleList(ctx, modulesUsingWnoErrorKey, module)
			ctx.getOrCreateMakeVarsInfo().UsingWnoError = module
		} else if !inList("-Werror", flags.Local.CFlags) && !inList("-Werror", flags.Local.CppFlags) {
			if warningsAreAllowed(ctx.ModuleDir()) {
				addToModuleList(ctx, modulesWarningsAllowedKey, module)
				ctx.getOrCreateMakeVarsInfo().WarningsAllowed = module
			} else {
				flags.Local.CFlags = append([]string{"-Werror"}, flags.Local.CFlags...)
			}
+18 −22
Original line number Diff line number Diff line
@@ -25,9 +25,6 @@ import (
)

var (
	modulesWarningsAllowedKey    = android.NewOnceKey("ModulesWarningsAllowed")
	modulesUsingWnoErrorKey      = android.NewOnceKey("ModulesUsingWnoError")
	modulesMissingProfileFileKey = android.NewOnceKey("ModulesMissingProfileFile")
	sanitizerVariables = map[string]string{
		"ADDRESS_SANITIZER_RUNTIME_LIBRARY":   config.AddressSanitizerRuntimeLibrary(),
		"HWADDRESS_SANITIZER_RUNTIME_LIBRARY": config.HWAddressSanitizerRuntimeLibrary(),
@@ -50,15 +47,9 @@ func getNamedMapForConfig(config android.Config, key android.OnceKey) *sync.Map
	}).(*sync.Map)
}

func makeStringOfKeys(ctx android.MakeVarsContext, key android.OnceKey) string {
	set := getNamedMapForConfig(ctx.Config(), key)
	keys := []string{}
	set.Range(func(key interface{}, value interface{}) bool {
		keys = append(keys, key.(string))
		return true
	})
	sort.Strings(keys)
	return strings.Join(keys, " ")
func makeVarsString(items []string) string {
	items = android.SortedUniqueStrings(items)
	return strings.Join(items, " ")
}

func makeStringOfWarningAllowedProjects() string {
@@ -108,28 +99,33 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
	ctx.Strict("GLOBAL_CLANG_EXTERNAL_CFLAGS_NO_OVERRIDE", "${config.NoOverrideExternalGlobalCflags}")

	// Filter vendor_public_library that are exported to make
	exportedVendorPublicLibraries := []string{}
	var exportedVendorPublicLibraries []string
	var warningsAllowed []string
	var usingWnoErrors []string
	var missingProfiles []string
	ctx.VisitAllModules(func(module android.Module) {
		if v, ok := android.OtherModuleProvider(ctx, module, CcMakeVarsInfoProvider); ok {
			warningsAllowed = android.AppendIfNotZero(warningsAllowed, v.WarningsAllowed)
			usingWnoErrors = android.AppendIfNotZero(usingWnoErrors, v.UsingWnoError)
			missingProfiles = android.AppendIfNotZero(missingProfiles, v.MissingProfile)
		}
		if ccModule, ok := module.(*Module); ok {
			baseName := ccModule.BaseModuleName()
			if ccModule.IsVendorPublicLibrary() && module.ExportedToMake() {
				if !inList(baseName, exportedVendorPublicLibraries) {
				exportedVendorPublicLibraries = append(exportedVendorPublicLibraries, baseName)
			}
		}
		}
	})
	sort.Strings(exportedVendorPublicLibraries)
	ctx.Strict("VENDOR_PUBLIC_LIBRARIES", strings.Join(exportedVendorPublicLibraries, " "))
	ctx.Strict("VENDOR_PUBLIC_LIBRARIES", makeVarsString(exportedVendorPublicLibraries))

	lsdumpPaths := *lsdumpPaths(ctx.Config())
	sort.Strings(lsdumpPaths)
	ctx.Strict("LSDUMP_PATHS", strings.Join(lsdumpPaths, " "))

	ctx.Strict("ANDROID_WARNING_ALLOWED_PROJECTS", makeStringOfWarningAllowedProjects())
	ctx.Strict("SOONG_MODULES_WARNINGS_ALLOWED", makeStringOfKeys(ctx, modulesWarningsAllowedKey))
	ctx.Strict("SOONG_MODULES_USING_WNO_ERROR", makeStringOfKeys(ctx, modulesUsingWnoErrorKey))
	ctx.Strict("SOONG_MODULES_MISSING_PGO_PROFILE_FILE", makeStringOfKeys(ctx, modulesMissingProfileFileKey))
	ctx.Strict("SOONG_MODULES_WARNINGS_ALLOWED", makeVarsString(warningsAllowed))
	ctx.Strict("SOONG_MODULES_USING_WNO_ERROR", makeVarsString(usingWnoErrors))
	ctx.Strict("SOONG_MODULES_MISSING_PGO_PROFILE_FILE", makeVarsString(missingProfiles))

	ctx.Strict("CLANG_COVERAGE_CONFIG_CFLAGS", strings.Join(clangCoverageCFlags, " "))
	ctx.Strict("CLANG_COVERAGE_CONFIG_COMMFLAGS", strings.Join(clangCoverageCommonFlags, " "))
+1 −5
Original line number Diff line number Diff line
@@ -54,10 +54,6 @@ func getOrderfileProjects(config android.DeviceConfig) []string {
	})
}

func recordMissingOrderfile(ctx BaseModuleContext, missing string) {
	getNamedMapForConfig(ctx.Config(), modulesMissingProfileFileKey).Store(missing, true)
}

type OrderfileProperties struct {
	Orderfile struct {
		Instrumentation *bool
@@ -117,7 +113,7 @@ func (props *OrderfileProperties) getOrderfile(ctx BaseModuleContext) android.Op

	// Record that this module's order file is absent
	missing := *props.Orderfile.Order_file_path + ":" + ctx.ModuleDir() + "/Android.bp:" + ctx.ModuleName()
	recordMissingOrderfile(ctx, missing)
	ctx.getOrCreateMakeVarsInfo().MissingProfile = missing

	return android.OptionalPath{}
}