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

Commit 41b3324a authored by Ulyana Trafimovich's avatar Ulyana Trafimovich Committed by Automerger Merge Worker
Browse files

Merge changes from topic "uses-libs-5" am: 8fab5bcc am: a4cdcd37 am: 21b5ffa9

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1353554

Change-Id: I4aa8ff98526ceb6b1475eae1f284ce7ca18bb8b2
parents bec7c73a 21b5ffa9
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -383,7 +383,7 @@ func createGlobalSoongConfig(ctx android.ModuleContext) *GlobalSoongConfig {
		SoongZip:         ctx.Config().HostToolPath(ctx, "soong_zip"),
		SoongZip:         ctx.Config().HostToolPath(ctx, "soong_zip"),
		Zip2zip:          ctx.Config().HostToolPath(ctx, "zip2zip"),
		Zip2zip:          ctx.Config().HostToolPath(ctx, "zip2zip"),
		ManifestCheck:    ctx.Config().HostToolPath(ctx, "manifest_check"),
		ManifestCheck:    ctx.Config().HostToolPath(ctx, "manifest_check"),
		ConstructContext: android.PathForSource(ctx, "build/soong/scripts/construct_context.sh"),
		ConstructContext: ctx.Config().HostToolPath(ctx, "construct_context"),
	}
	}
}
}


@@ -574,7 +574,7 @@ func GlobalSoongConfigForTests(config android.Config) *GlobalSoongConfig {
			SoongZip:         android.PathForTesting("soong_zip"),
			SoongZip:         android.PathForTesting("soong_zip"),
			Zip2zip:          android.PathForTesting("zip2zip"),
			Zip2zip:          android.PathForTesting("zip2zip"),
			ManifestCheck:    android.PathForTesting("manifest_check"),
			ManifestCheck:    android.PathForTesting("manifest_check"),
			ConstructContext: android.PathForTesting("construct_context.sh"),
			ConstructContext: android.PathForTesting("construct_context"),
		}
		}
	}).(*GlobalSoongConfig)
	}).(*GlobalSoongConfig)
}
}
+41 −48
Original line number Original line Diff line number Diff line
@@ -208,7 +208,7 @@ type classLoaderContext struct {
// targetSdkVersion in the manifest or APK is less than that API version.
// targetSdkVersion in the manifest or APK is less than that API version.
type classLoaderContextMap map[int]*classLoaderContext
type classLoaderContextMap map[int]*classLoaderContext


const anySdkVersion int = -1
const anySdkVersion int = 9999 // should go last in class loader context


func (m classLoaderContextMap) getSortedKeys() []int {
func (m classLoaderContextMap) getSortedKeys() []int {
	keys := make([]int, 0, len(m))
	keys := make([]int, 0, len(m))
@@ -276,14 +276,30 @@ func dexpreoptCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, g


	invocationPath := odexPath.ReplaceExtension(ctx, "invocation")
	invocationPath := odexPath.ReplaceExtension(ctx, "invocation")


	classLoaderContexts := make(classLoaderContextMap)
	systemServerJars := NonUpdatableSystemServerJars(ctx, global)
	systemServerJars := NonUpdatableSystemServerJars(ctx, global)


	classLoaderContexts := make(classLoaderContextMap)
	rule.Command().FlagWithArg("mkdir -p ", filepath.Dir(odexPath.String()))
	rule.Command().FlagWithOutput("rm -f ", odexPath)


	// A flag indicating if the '&' class loader context is used.
	if jarIndex := android.IndexList(module.Name, systemServerJars); jarIndex >= 0 {
	unknownClassLoaderContext := false
		// System server jars should be dexpreopted together: class loader context of each jar
		// should include all preceding jars on the system server classpath.
		classLoaderContexts.addSystemServerLibs(anySdkVersion, ctx, module, systemServerJars[:jarIndex]...)


	if module.EnforceUsesLibraries {
		// Copy the system server jar to a predefined location where dex2oat will find it.
		dexPathHost := SystemServerDexJarHostPath(ctx, module.Name)
		rule.Command().Text("mkdir -p").Flag(filepath.Dir(dexPathHost.String()))
		rule.Command().Text("cp -f").Input(module.DexPath).Output(dexPathHost)

		checkSystemServerOrder(ctx, jarIndex)

		clc := classLoaderContexts[anySdkVersion]
		rule.Command().
			Text("class_loader_context_arg=--class-loader-context=PCL[" + strings.Join(clc.Host.Strings(), ":") + "]").
			Implicits(clc.Host).
			Text("stored_class_loader_context_arg=--stored-class-loader-context=PCL[" + strings.Join(clc.Target, ":") + "]")
	} else if module.EnforceUsesLibraries {
		// Unconditional class loader context.
		// Unconditional class loader context.
		usesLibs := append(copyOf(module.UsesLibraries), module.OptionalUsesLibraries...)
		usesLibs := append(copyOf(module.UsesLibraries), module.OptionalUsesLibraries...)
		classLoaderContexts.addLibs(anySdkVersion, module, usesLibs...)
		classLoaderContexts.addLibs(anySdkVersion, module, usesLibs...)
@@ -306,41 +322,8 @@ func dexpreoptCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, g
		if !contains(usesLibs, testBase) {
		if !contains(usesLibs, testBase) {
			classLoaderContexts.addLibs(30, module, testBase)
			classLoaderContexts.addLibs(30, module, testBase)
		}
		}
	} else if jarIndex := android.IndexList(module.Name, systemServerJars); jarIndex >= 0 {
		// System server jars should be dexpreopted together: class loader context of each jar
		// should include all preceding jars on the system server classpath.
		classLoaderContexts.addSystemServerLibs(anySdkVersion, ctx, module, systemServerJars[:jarIndex]...)

		// Copy the system server jar to a predefined location where dex2oat will find it.
		dexPathHost := SystemServerDexJarHostPath(ctx, module.Name)
		rule.Command().Text("mkdir -p").Flag(filepath.Dir(dexPathHost.String()))
		rule.Command().Text("cp -f").Input(module.DexPath).Output(dexPathHost)

		checkSystemServerOrder(ctx, jarIndex)
	} else {
		// Pass special class loader context to skip the classpath and collision check.
		// This will get removed once LOCAL_USES_LIBRARIES is enforced.
		// Right now LOCAL_USES_LIBRARIES is opt in, for the case where it's not specified we still default
		// to the &.
		unknownClassLoaderContext = true
	}

	rule.Command().FlagWithArg("mkdir -p ", filepath.Dir(odexPath.String()))
	rule.Command().FlagWithOutput("rm -f ", odexPath)
	// Set values in the environment of the rule.  These may be modified by construct_context.sh.
	if unknownClassLoaderContext {
		rule.Command().
			Text(`class_loader_context_arg=--class-loader-context=\&`).
			Text(`stored_class_loader_context_arg=""`)
	} else {
		clc := classLoaderContexts[anySdkVersion]
		rule.Command().
			Text("class_loader_context_arg=--class-loader-context=PCL[" + strings.Join(clc.Host.Strings(), ":") + "]").
			Implicits(clc.Host).
			Text("stored_class_loader_context_arg=--stored-class-loader-context=PCL[" + strings.Join(clc.Target, ":") + "]")
	}


	if module.EnforceUsesLibraries {
		// Generate command that saves target SDK version in a shell variable.
		if module.ManifestPath != nil {
		if module.ManifestPath != nil {
			rule.Command().Text(`target_sdk_version="$(`).
			rule.Command().Text(`target_sdk_version="$(`).
				Tool(globalSoong.ManifestCheck).
				Tool(globalSoong.ManifestCheck).
@@ -356,20 +339,30 @@ func dexpreoptCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, g
				Text(`| grep "targetSdkVersion" | sed -n "s/targetSdkVersion:'\(.*\)'/\1/p"`).
				Text(`| grep "targetSdkVersion" | sed -n "s/targetSdkVersion:'\(.*\)'/\1/p"`).
				Text(`)"`)
				Text(`)"`)
		}
		}

		// Generate command that saves host and target class loader context in shell variables.
		cmd := rule.Command().
			Text(`eval "$(`).Tool(globalSoong.ConstructContext).
			Text(` --target-sdk-version ${target_sdk_version}`)
		for _, ver := range classLoaderContexts.getSortedKeys() {
		for _, ver := range classLoaderContexts.getSortedKeys() {
			clc := classLoaderContexts.getValue(ver)
			clc := classLoaderContexts.getValue(ver)
			var varHost, varTarget string
			verString := fmt.Sprintf("%d", ver)
			if ver == anySdkVersion {
			if ver == anySdkVersion {
				varHost = "dex_preopt_host_libraries"
				verString = "any" // a special keyword that means any SDK version
				varTarget = "dex_preopt_target_libraries"
			} else {
				varHost = fmt.Sprintf("conditional_host_libs_%d", ver)
				varTarget = fmt.Sprintf("conditional_target_libs_%d", ver)
			}
			}
			rule.Command().Textf(varHost+`="%s"`, strings.Join(clc.Host.Strings(), " ")).Implicits(clc.Host)
			cmd.Textf(`--host-classpath-for-sdk %s %s`, verString, strings.Join(clc.Host.Strings(), ":")).
			rule.Command().Textf(varTarget+`="%s"`, strings.Join(clc.Target, " "))
				Implicits(clc.Host).
				Textf(`--target-classpath-for-sdk %s %s`, verString, strings.Join(clc.Target, ":"))
		}
		}
		rule.Command().Text("source").Tool(globalSoong.ConstructContext).Input(module.DexPath)
		cmd.Text(`)"`)
	} else {
		// Pass special class loader context to skip the classpath and collision check.
		// This will get removed once LOCAL_USES_LIBRARIES is enforced.
		// Right now LOCAL_USES_LIBRARIES is opt in, for the case where it's not specified we still default
		// to the &.
		rule.Command().
			Text(`class_loader_context_arg=--class-loader-context=\&`).
			Text(`stored_class_loader_context_arg=""`)
	}
	}


	// Devices that do not have a product partition use a symlink from /product to /system/product.
	// Devices that do not have a product partition use a symlink from /product to /system/product.
+2 −3
Original line number Original line Diff line number Diff line
@@ -1879,9 +1879,8 @@ func (u *usesLibrary) deps(ctx android.BottomUpMutatorContext, hasFrameworkLibs
		// creating a cyclic dependency:
		// creating a cyclic dependency:
		//     e.g. framework-res -> org.apache.http.legacy -> ... -> framework-res.
		//     e.g. framework-res -> org.apache.http.legacy -> ... -> framework-res.
		if hasFrameworkLibs {
		if hasFrameworkLibs {
			// dexpreopt/dexpreopt.go needs the paths to the dex jars of these libraries in case construct_context.sh needs
			// Dexpreopt needs paths to the dex jars of these libraries in order to construct
			// to pass them to dex2oat.  Add them as a dependency so we can determine the path to the dex jar of each
			// class loader context for dex2oat. Add them as a dependency with a special tag.
			// library to dexpreopt.
			ctx.AddVariationDependencies(nil, usesLibTag,
			ctx.AddVariationDependencies(nil, usesLibTag,
				"org.apache.http.legacy",
				"org.apache.http.legacy",
				"android.hidl.base-V1.0-java",
				"android.hidl.base-V1.0-java",
+2 −2
Original line number Original line Diff line number Diff line
@@ -2652,13 +2652,13 @@ func TestUsesLibraries(t *testing.T) {
	// Test that only present libraries are preopted
	// Test that only present libraries are preopted
	cmd = app.Rule("dexpreopt").RuleParams.Command
	cmd = app.Rule("dexpreopt").RuleParams.Command


	if w := `dex_preopt_target_libraries="/system/framework/foo.jar /system/framework/bar.jar"`; !strings.Contains(cmd, w) {
	if w := `--target-classpath-for-sdk any /system/framework/foo.jar:/system/framework/bar.jar`; !strings.Contains(cmd, w) {
		t.Errorf("wanted %q in %q", w, cmd)
		t.Errorf("wanted %q in %q", w, cmd)
	}
	}


	cmd = prebuilt.Rule("dexpreopt").RuleParams.Command
	cmd = prebuilt.Rule("dexpreopt").RuleParams.Command


	if w := `dex_preopt_target_libraries="/system/framework/foo.jar /system/framework/bar.jar"`; !strings.Contains(cmd, w) {
	if w := `--target-classpath-for-sdk any /system/framework/foo.jar:/system/framework/bar.jar`; !strings.Contains(cmd, w) {
		t.Errorf("wanted %q in %q", w, cmd)
		t.Errorf("wanted %q in %q", w, cmd)
	}
	}
}
}
+40 −0
Original line number Original line Diff line number Diff line
@@ -149,6 +149,46 @@ python_test_host {
    test_suites: ["general-tests"],
    test_suites: ["general-tests"],
}
}


python_binary_host {
    name: "construct_context",
    main: "construct_context.py",
    srcs: [
        "construct_context.py",
    ],
    version: {
        py2: {
            enabled: true,
        },
        py3: {
            enabled: false,
        },
    },
    libs: [
        "manifest_utils",
    ],
}

python_test_host {
    name: "construct_context_test",
    main: "construct_context_test.py",
    srcs: [
        "construct_context_test.py",
        "construct_context.py",
    ],
    version: {
        py2: {
            enabled: true,
        },
        py3: {
            enabled: false,
        },
    },
    libs: [
        "manifest_utils",
    ],
    test_suites: ["general-tests"],
}

python_binary_host {
python_binary_host {
    name: "lint-project-xml",
    name: "lint-project-xml",
    main: "lint-project-xml.py",
    main: "lint-project-xml.py",
Loading