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

Commit 7297f05e authored by Colin Cross's avatar Colin Cross
Browse files

Don't mutate sources when reusing objects

Remove some mutations of properties by checking if a reuseObjTag
dependency exists before reading the property instead of clearing
the property when adding a reuseObjTag dependency.

Test: All soong tests pass
Flag: EXEMPT refactor
Change-Id: I2c0e2f4b596887751e6d2a220a114d7ee246d80e
parent f22fe41c
Loading
Loading
Loading
Loading
+14 −12
Original line number Diff line number Diff line
@@ -228,9 +228,6 @@ type BaseCompilerProperties struct {
		Static *bool `android:"arch_variant"`
	} `android:"arch_variant"`

	// Stores the original list of source files before being cleared by library reuse
	OriginalSrcs proptools.Configurable[[]string] `blueprint:"mutated"`

	// Build and link with OpenMP
	Openmp *bool `android:"arch_variant"`
}
@@ -363,10 +360,20 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
	tc := ctx.toolchain()
	modulePath := ctx.ModuleDir()

	srcs := compiler.Properties.Srcs.GetOrDefault(ctx, nil)
	reuseObjs := false
	if len(ctx.GetDirectDepsWithTag(reuseObjTag)) > 0 {
		reuseObjs = true
	}

	// If a reuseObjTag dependency exists then this module is reusing the objects (generally the shared variant
	// reusing objects from the static variant), and doesn't need to compile any sources of its own.
	var srcs []string
	if !reuseObjs {
		srcs = compiler.Properties.Srcs.GetOrDefault(ctx, nil)
		exclude_srcs := compiler.Properties.Exclude_srcs.GetOrDefault(ctx, nil)
		compiler.srcsBeforeGen = android.PathsForModuleSrcExcludes(ctx, srcs, exclude_srcs)
		compiler.srcsBeforeGen = append(compiler.srcsBeforeGen, deps.GeneratedSources...)
	}

	cflags := compiler.Properties.Cflags.GetOrDefault(ctx, nil)
	cppflags := compiler.Properties.Cppflags.GetOrDefault(ctx, nil)
@@ -721,11 +728,6 @@ func (compiler *baseCompiler) hasSrcExt(ctx BaseModuleContext, ext string) bool
			return true
		}
	}
	for _, src := range compiler.Properties.OriginalSrcs.GetOrDefault(ctx, nil) {
		if filepath.Ext(src) == ext {
			return true
		}
	}

	return false
}
+0 −5
Original line number Diff line number Diff line
@@ -2071,12 +2071,7 @@ func reuseStaticLibrary(ctx android.BottomUpMutatorContext, shared *Module) {
			sharedCompiler.StaticProperties.Static.System_shared_libs == nil &&
			sharedCompiler.SharedProperties.Shared.System_shared_libs == nil {

			// TODO: namespaces?
			ctx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, reuseObjTag, ctx.ModuleName())
			sharedCompiler.baseCompiler.Properties.OriginalSrcs =
				sharedCompiler.baseCompiler.Properties.Srcs
			sharedCompiler.baseCompiler.Properties.Srcs = proptools.NewConfigurable[[]string](nil, nil)
			sharedCompiler.baseCompiler.Properties.Generated_sources = nil
		}

		// This dep is just to reference static variant from shared variant