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

Commit 41907646 authored by Jihoon Kang's avatar Jihoon Kang Committed by Gerrit Code Review
Browse files

Merge changes from topic "android_stubs_current_refactor"

* changes:
  Cleanup android.JavaApiLibraryName references
  Redefine core and core platform API surface java_library
  Introduce product variable Build_from_text_stub
  Introduce "Exclude_static_libs" property for Java modules
parents efd18370 91c83956
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -517,6 +517,8 @@ func NewConfig(cmdArgs CmdArgs, availableEnv map[string]string) (Config, error)
		config: config,
	}

	config.productVariables.Build_from_text_stub = boolPtr(config.buildFromTextStub)

	// Soundness check of the build and source directories. This won't catch strange
	// configurations with symlinks, but at least checks the obvious case.
	absBuildDir, err := filepath.Abs(cmdArgs.SoongOutDir)
@@ -2017,6 +2019,7 @@ func (c *config) BuildFromTextStub() bool {

func (c *config) SetBuildFromTextStub(b bool) {
	c.buildFromTextStub = b
	c.productVariables.Build_from_text_stub = boolPtr(b)
}

func (c *config) AddForceEnabledModules(forceEnabled []string) {
+9 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ func init() {
	AddNeverAllowRules(createProhibitFrameworkAccessRules()...)
	AddNeverAllowRules(createBp2BuildRule())
	AddNeverAllowRules(createCcStubsRule())
	AddNeverAllowRules(createJavaExcludeStaticLibsRule())
}

// Add a NeverAllow rule to the set of rules to apply.
@@ -253,6 +254,14 @@ func createProhibitFrameworkAccessRules() []Rule {
	}
}

func createJavaExcludeStaticLibsRule() Rule {
	return NeverAllow().
		NotIn("build/soong").
		ModuleType("java_library").
		WithMatcher("exclude_static_libs", isSetMatcherInstance).
		Because("exclude_static_libs property is only allowed for java modules defined in build/soong")
}

func neverallowMutator(ctx BottomUpMutatorContext) {
	m, ok := ctx.Module().(Module)
	if !ok {
+21 −3
Original line number Diff line number Diff line
@@ -344,6 +344,23 @@ var neverallowTests = []struct {
			`module "outside_allowed_list": violates neverallow`,
		},
	},
	// Test for the rule restricting use of exclude_static_libs
	{
		name: `"exclude_static_libs" outside allowed directory`,
		fs: map[string][]byte{
			"a/b/Android.bp": []byte(`
				java_library {
					name: "baz",
					exclude_static_libs: [
						"bar",
					],
				}
			`),
		},
		expectedErrors: []string{
			`exclude_static_libs property is only allowed for java modules defined in build/soong`,
		},
	},
}

var prepareForNeverAllowTest = GroupFixturePreparers(
@@ -433,6 +450,7 @@ type mockJavaLibraryProperties struct {
	Libs                []string
	Sdk_version         *string
	Uncompress_dex      *bool
	Exclude_static_libs []string
}

type mockJavaLibraryModule struct {
+6 −13
Original line number Diff line number Diff line
@@ -84,12 +84,6 @@ func (k SdkKind) String() string {
	}
}

// JavaLibraryName returns the soong module containing the Java APIs of that API surface.
func (k SdkKind) JavaLibraryName(c Config) string {
	name := k.DefaultJavaLibraryName()
	return JavaApiLibraryName(c, name)
}

// JavaApiLibraryName returns the name of .txt equivalent of a java_library, but does
// not check if either module exists.
// TODO: Return .txt (single-tree or multi-tree equivalents) based on config
@@ -335,11 +329,10 @@ func init() {

// Export the name of the soong modules representing the various Java API surfaces.
func javaSdkMakeVars(ctx MakeVarsContext) {
	ctx.Strict("ANDROID_PUBLIC_STUBS", SdkPublic.JavaLibraryName(ctx.Config()))
	ctx.Strict("ANDROID_SYSTEM_STUBS", SdkSystem.JavaLibraryName(ctx.Config()))
	ctx.Strict("ANDROID_TEST_STUBS", SdkTest.JavaLibraryName(ctx.Config()))
	ctx.Strict("ANDROID_MODULE_LIB_STUBS", SdkModule.JavaLibraryName(ctx.Config()))
	ctx.Strict("ANDROID_SYSTEM_SERVER_STUBS", SdkSystemServer.JavaLibraryName(ctx.Config()))
	// TODO (jihoonkang): Create a .txt equivalent for core.current.stubs
	ctx.Strict("ANDROID_CORE_STUBS", SdkCore.JavaLibraryName(ctx.Config()))
	ctx.Strict("ANDROID_PUBLIC_STUBS", SdkPublic.DefaultJavaLibraryName())
	ctx.Strict("ANDROID_SYSTEM_STUBS", SdkSystem.DefaultJavaLibraryName())
	ctx.Strict("ANDROID_TEST_STUBS", SdkTest.DefaultJavaLibraryName())
	ctx.Strict("ANDROID_MODULE_LIB_STUBS", SdkModule.DefaultJavaLibraryName())
	ctx.Strict("ANDROID_SYSTEM_SERVER_STUBS", SdkSystemServer.DefaultJavaLibraryName())
	ctx.Strict("ANDROID_CORE_STUBS", SdkCore.DefaultJavaLibraryName())
}
+7 −0
Original line number Diff line number Diff line
@@ -109,6 +109,11 @@ type variableProperties struct {
			Cflags []string
		}

		Build_from_text_stub struct {
			Static_libs         []string
			Exclude_static_libs []string
		}

		// debuggable is true for eng and userdebug builds, and can be used to turn on additional
		// debugging features that don't significantly impact runtime behavior.  userdebug builds
		// are used for dogfooding and performance testing, and should be as similar to user builds
@@ -286,6 +291,7 @@ type productVariables struct {
	Uml                          *bool    `json:",omitempty"`
	Arc                          *bool    `json:",omitempty"`
	MinimizeJavaDebugInfo        *bool    `json:",omitempty"`
	Build_from_text_stub         *bool    `json:",omitempty"`

	Check_elf_files *bool `json:",omitempty"`

@@ -526,6 +532,7 @@ func (v *productVariables) SetDefaultConfig() {
		Malloc_pattern_fill_contents: boolPtr(false),
		Safestack:                    boolPtr(false),
		TrimmedApex:                  boolPtr(false),
		Build_from_text_stub:         boolPtr(false),

		BootJars:     ConfiguredJarList{apexes: []string{}, jars: []string{}},
		ApexBootJars: ConfiguredJarList{apexes: []string{}, jars: []string{}},
Loading