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

Commit 1c14a219 authored by Liz Kammer's avatar Liz Kammer
Browse files

Add test data dependencies to APEX.

Test: soong go tests

Bug: 155820504
Change-Id: If96d82c27f19953e34efb31f2111f1643c0c4008
parent c81f967d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -120,6 +120,9 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, mo
			if len(fi.symlinks) > 0 {
				fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
			}
			if len(fi.dataPaths) > 0 {
				fmt.Println(w, "LOCAL_TEST_DATA :=", strings.Join(cc.AndroidMkDataPaths(fi.dataPaths), " "))
			}

			if fi.module != nil && len(fi.module.NoticeFiles()) > 0 {
				fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", strings.Join(fi.module.NoticeFiles().Strings(), " "))
+8 −2
Original line number Diff line number Diff line
@@ -1214,6 +1214,7 @@ type apexFile struct {
	module     android.Module
	// list of symlinks that will be created in installDir that point to this apexFile
	symlinks      []string
	dataPaths     android.Paths
	transitiveDep bool
	moduleDir     string

@@ -1249,16 +1250,20 @@ func (af *apexFile) Ok() bool {
	return af.builtFile != nil && af.builtFile.String() != ""
}

func (af *apexFile) apexRelativePath(path string) string {
	return filepath.Join(af.installDir, path)
}

// Path() returns path of this apex file relative to the APEX root
func (af *apexFile) Path() string {
	return filepath.Join(af.installDir, af.builtFile.Base())
	return af.apexRelativePath(af.builtFile.Base())
}

// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
func (af *apexFile) SymlinkPaths() []string {
	var ret []string
	for _, symlink := range af.symlinks {
		ret = append(ret, filepath.Join(af.installDir, symlink))
		ret = append(ret, af.apexRelativePath(symlink))
	}
	return ret
}
@@ -1664,6 +1669,7 @@ func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFil
	fileToCopy := cc.OutputFile().Path()
	af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
	af.symlinks = cc.Symlinks()
	af.dataPaths = cc.DataPaths()
	return af
}

+15 −0
Original line number Diff line number Diff line
@@ -180,6 +180,8 @@ func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*andr
		"build/make/core/proguard.flags":             nil,
		"build/make/core/proguard_basic_keeps.flags": nil,
		"dummy.txt":                                  nil,
		"baz":                                        nil,
		"bar/baz":                                    nil,
	}

	cc.GatherRequiredFilesForTest(fs)
@@ -3267,6 +3269,14 @@ func TestApexWithTests(t *testing.T) {
			private_key: "testkey.pem",
		}

		filegroup {
			name: "fg",
			srcs: [
				"baz",
				"bar/baz"
			],
		}

		cc_test {
			name: "mytest",
			gtest: false,
@@ -3276,6 +3286,7 @@ func TestApexWithTests(t *testing.T) {
			system_shared_libs: [],
			static_executable: true,
			stl: "none",
			data: [":fg"],
		}

		cc_library {
@@ -3308,6 +3319,10 @@ func TestApexWithTests(t *testing.T) {
	ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
	ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")

	//Ensure that test data are copied into apex.
	ensureContains(t, copyCmds, "image.apex/bin/test/baz")
	ensureContains(t, copyCmds, "image.apex/bin/test/bar/baz")

	// Ensure that test deps built with `test_per_src` are copied into apex.
	ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
	ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
+16 −0
Original line number Diff line number Diff line
@@ -350,6 +350,19 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) {
			symlinkDest := android.PathForModuleOut(ctx, "image"+suffix, symlinkPath).String()
			copyCommands = append(copyCommands, "ln -sfn "+filepath.Base(destPath)+" "+symlinkDest)
		}
		for _, d := range fi.dataPaths {
			// TODO(eakammer): This is now the third repetition of ~this logic for test paths, refactoring should be possible
			relPath := d.Rel()
			dataPath := d.String()
			if !strings.HasSuffix(dataPath, relPath) {
				panic(fmt.Errorf("path %q does not end with %q", dataPath, relPath))
			}

			dataDest := android.PathForModuleOut(ctx, "image"+suffix, fi.apexRelativePath(relPath)).String()

			copyCommands = append(copyCommands, "cp -f "+d.String()+" "+dataDest)
			implicitInputs = append(implicitInputs, d)
		}
	}

	// TODO(jiyong): use RuleBuilder
@@ -406,6 +419,9 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) {
			pathInApex := filepath.Join(f.installDir, f.builtFile.Base())
			if f.installDir == "bin" || strings.HasPrefix(f.installDir, "bin/") {
				executablePaths = append(executablePaths, pathInApex)
				for _, d := range f.dataPaths {
					readOnlyPaths = append(readOnlyPaths, filepath.Join(f.installDir, d.Rel()))
				}
				for _, s := range f.symlinks {
					executablePaths = append(executablePaths, filepath.Join(f.installDir, s))
				}
+6 −1
Original line number Diff line number Diff line
@@ -149,7 +149,7 @@ func (c *Module) AndroidMkEntries() []android.AndroidMkEntries {
	return []android.AndroidMkEntries{entries}
}

func androidMkWriteTestData(data android.Paths, ctx AndroidMkContext, entries *android.AndroidMkEntries) {
func AndroidMkDataPaths(data android.Paths) []string {
	var testFiles []string
	for _, d := range data {
		rel := d.Rel()
@@ -160,6 +160,11 @@ func androidMkWriteTestData(data android.Paths, ctx AndroidMkContext, entries *a
		path = strings.TrimSuffix(path, rel)
		testFiles = append(testFiles, path+":"+rel)
	}
	return testFiles
}

func androidMkWriteTestData(data android.Paths, ctx AndroidMkContext, entries *android.AndroidMkEntries) {
	testFiles := AndroidMkDataPaths(data)
	if len(testFiles) > 0 {
		entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
			entries.AddStrings("LOCAL_TEST_DATA", testFiles...)
Loading