Replace RelPathString() with ToMakePath()
Add a ToMakePath() method that returns a new path that points out out/ instead of out/soong/, and replace the "$(OUT_DIR)/" + path.RelPathString() pattern with path.ToMakePath().String() Bug: 141877526 Test: m checkbuild Change-Id: I391b9f2ed78c83a58d905d48355ce9b01d610d16
This commit is contained in:
parent
70dda7e3da
commit
ff6c33d885
11 changed files with 88 additions and 70 deletions
|
@ -821,17 +821,6 @@ func PathForOutput(ctx PathContext, pathComponents ...string) OutputPath {
|
|||
return OutputPath{basePath{path, ctx.Config(), ""}}
|
||||
}
|
||||
|
||||
// pathForInstallInMakeDir is used by PathForModuleInstall when the module returns true
|
||||
// for InstallBypassMake to produce an OutputPath that installs to $OUT_DIR instead of
|
||||
// $OUT_DIR/soong.
|
||||
func pathForInstallInMakeDir(ctx PathContext, pathComponents ...string) InstallPath {
|
||||
path, err := validatePath(pathComponents...)
|
||||
if err != nil {
|
||||
reportPathError(ctx, err)
|
||||
}
|
||||
return InstallPath{basePath{"../" + path, ctx.Config(), ""}}
|
||||
}
|
||||
|
||||
// PathsForOutput returns Paths rooted from buildDir
|
||||
func PathsForOutput(ctx PathContext, paths []string) WritablePaths {
|
||||
ret := make(WritablePaths, len(paths))
|
||||
|
@ -1118,12 +1107,14 @@ func PathForModuleRes(ctx ModuleContext, pathComponents ...string) ModuleResPath
|
|||
// InstallPath is a Path representing a installed file path rooted from the build directory
|
||||
type InstallPath struct {
|
||||
basePath
|
||||
|
||||
baseDir string // "../" for Make paths to convert "out/soong" to "out", "" for Soong paths
|
||||
}
|
||||
|
||||
func (p InstallPath) writablePath() {}
|
||||
|
||||
func (p InstallPath) String() string {
|
||||
return filepath.Join(p.config.buildDir, p.path)
|
||||
return filepath.Join(p.config.buildDir, p.baseDir, p.path)
|
||||
}
|
||||
|
||||
// Join creates a new InstallPath with paths... joined with the current path. The
|
||||
|
@ -1141,8 +1132,11 @@ func (p InstallPath) withRel(rel string) InstallPath {
|
|||
return p
|
||||
}
|
||||
|
||||
func (p InstallPath) RelPathString() string {
|
||||
return p.path
|
||||
// ToMakePath returns a new InstallPath that points to Make's install directory instead of Soong's,
|
||||
// i.e. out/ instead of out/soong/.
|
||||
func (p InstallPath) ToMakePath() InstallPath {
|
||||
p.baseDir = "../"
|
||||
return p
|
||||
}
|
||||
|
||||
// PathForModuleInstall returns a Path representing the install path for the
|
||||
|
@ -1167,15 +1161,18 @@ func PathForModuleInstall(ctx ModuleInstallPathContext, pathComponents ...string
|
|||
outPaths = append([]string{"debug"}, outPaths...)
|
||||
}
|
||||
outPaths = append(outPaths, pathComponents...)
|
||||
if ctx.InstallBypassMake() && ctx.Config().EmbeddedInMake() {
|
||||
return pathForInstallInMakeDir(ctx, outPaths...)
|
||||
}
|
||||
|
||||
path, err := validatePath(outPaths...)
|
||||
if err != nil {
|
||||
reportPathError(ctx, err)
|
||||
}
|
||||
return InstallPath{basePath{path, ctx.Config(), ""}}
|
||||
|
||||
ret := InstallPath{basePath{path, ctx.Config(), ""}, ""}
|
||||
if ctx.InstallBypassMake() && ctx.Config().EmbeddedInMake() {
|
||||
ret = ret.ToMakePath()
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func PathForNdkInstall(ctx PathContext, paths ...string) InstallPath {
|
||||
|
@ -1184,7 +1181,7 @@ func PathForNdkInstall(ctx PathContext, paths ...string) InstallPath {
|
|||
if err != nil {
|
||||
reportPathError(ctx, err)
|
||||
}
|
||||
return InstallPath{basePath{path, ctx.Config(), ""}}
|
||||
return InstallPath{basePath{path, ctx.Config(), ""}, ""}
|
||||
}
|
||||
|
||||
func InstallPathToOnDevicePath(ctx PathContext, path InstallPath) string {
|
||||
|
|
|
@ -158,7 +158,7 @@ func (p *PrebuiltEtc) AndroidMkEntries() AndroidMkEntries {
|
|||
ExtraEntries: []AndroidMkExtraEntriesFunc{
|
||||
func(entries *AndroidMkEntries) {
|
||||
entries.SetString("LOCAL_MODULE_TAGS", "optional")
|
||||
entries.SetString("LOCAL_MODULE_PATH", "$(OUT_DIR)/"+p.installDirPath.RelPathString())
|
||||
entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String())
|
||||
entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
|
||||
entries.SetString("LOCAL_UNINSTALLABLE_MODULE", strconv.FormatBool(!p.Installable()))
|
||||
if p.additionalDependencies != nil {
|
||||
|
|
|
@ -182,9 +182,9 @@ func TestPrebuiltUserShareInstallDirPath(t *testing.T) {
|
|||
`)
|
||||
|
||||
p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a_core").Module().(*PrebuiltEtc)
|
||||
expected := "target/product/test_device/system/usr/share/bar"
|
||||
if p.installDirPath.RelPathString() != expected {
|
||||
t.Errorf("expected %q, got %q", expected, p.installDirPath.RelPathString())
|
||||
expected := buildDir + "/target/product/test_device/system/usr/share/bar"
|
||||
if p.installDirPath.String() != expected {
|
||||
t.Errorf("expected %q, got %q", expected, p.installDirPath.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -199,9 +199,9 @@ func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) {
|
|||
|
||||
buildOS := BuildOs.String()
|
||||
p := ctx.ModuleForTests("foo.conf", buildOS+"_common").Module().(*PrebuiltEtc)
|
||||
expected := filepath.Join("host", config.PrebuiltOS(), "usr", "share", "bar")
|
||||
if p.installDirPath.RelPathString() != expected {
|
||||
t.Errorf("expected %q, got %q", expected, p.installDirPath.RelPathString())
|
||||
expected := filepath.Join(buildDir, "host", config.PrebuiltOS(), "usr", "share", "bar")
|
||||
if p.installDirPath.String() != expected {
|
||||
t.Errorf("expected %q, got %q", expected, p.installDirPath.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,14 +214,14 @@ func TestPrebuiltFontInstallDirPath(t *testing.T) {
|
|||
`)
|
||||
|
||||
p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a_core").Module().(*PrebuiltEtc)
|
||||
expected := "target/product/test_device/system/fonts"
|
||||
if p.installDirPath.RelPathString() != expected {
|
||||
t.Errorf("expected %q, got %q", expected, p.installDirPath.RelPathString())
|
||||
expected := buildDir + "/target/product/test_device/system/fonts"
|
||||
if p.installDirPath.String() != expected {
|
||||
t.Errorf("expected %q, got %q", expected, p.installDirPath.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrebuiltFirmwareDirPath(t *testing.T) {
|
||||
targetPath := "target/product/test_device"
|
||||
targetPath := buildDir + "/target/product/test_device"
|
||||
tests := []struct {
|
||||
description string
|
||||
config string
|
||||
|
@ -249,7 +249,7 @@ func TestPrebuiltFirmwareDirPath(t *testing.T) {
|
|||
t.Run(tt.description, func(t *testing.T) {
|
||||
ctx, _ := testPrebuiltEtc(t, tt.config)
|
||||
p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a_core").Module().(*PrebuiltEtc)
|
||||
if p.installDirPath.RelPathString() != tt.expectedPath {
|
||||
if p.installDirPath.String() != tt.expectedPath {
|
||||
t.Errorf("expected %q, got %q", tt.expectedPath, p.installDirPath)
|
||||
}
|
||||
})
|
||||
|
|
10
apex/apex.go
10
apex/apex.go
|
@ -1625,8 +1625,8 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, name, moduleDir string, apex
|
|||
proptools.StringDefault(a.properties.Apex_name, name), fi.installDir)
|
||||
if a.properties.Flattened && apexType.image() {
|
||||
// /system/apex/<name>/{lib|framework|...}
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)",
|
||||
a.installDir.RelPathString(), name, fi.installDir))
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join(a.installDir.ToMakePath().String(),
|
||||
name, fi.installDir))
|
||||
if !a.isFlattenedVariant() {
|
||||
fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
|
||||
}
|
||||
|
@ -1735,7 +1735,7 @@ func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkD
|
|||
fmt.Fprintln(w, "LOCAL_MODULE :=", name)
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
|
||||
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String())
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", a.installDir.RelPathString()))
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.ToMakePath().String())
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
|
||||
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
|
||||
if len(moduleNames) > 0 {
|
||||
|
@ -1746,7 +1746,7 @@ func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkD
|
|||
}
|
||||
if a.prebuiltFileToDelete != "" {
|
||||
fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", "rm -rf "+
|
||||
filepath.Join("$(OUT_DIR)", a.installDir.RelPathString(), a.prebuiltFileToDelete))
|
||||
filepath.Join(a.installDir.ToMakePath().String(), a.prebuiltFileToDelete))
|
||||
}
|
||||
fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
|
||||
|
||||
|
@ -1987,7 +1987,7 @@ func (p *Prebuilt) AndroidMkEntries() android.AndroidMkEntries {
|
|||
Include: "$(BUILD_PREBUILT)",
|
||||
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
||||
func(entries *android.AndroidMkEntries) {
|
||||
entries.SetString("LOCAL_MODULE_PATH", filepath.Join("$(OUT_DIR)", p.installDir.RelPathString()))
|
||||
entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String())
|
||||
entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
|
||||
entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
|
||||
entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...)
|
||||
|
|
|
@ -1382,6 +1382,7 @@ func TestVndkApexVersion(t *testing.T) {
|
|||
vndk: {
|
||||
enabled: true,
|
||||
},
|
||||
target_arch: "arm64",
|
||||
srcs: ["libvndk27.so"],
|
||||
}
|
||||
`, withFiles(map[string][]byte{
|
||||
|
@ -1864,8 +1865,8 @@ func TestApexInProductPartition(t *testing.T) {
|
|||
`)
|
||||
|
||||
apex := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle)
|
||||
expected := "target/product/test_device/product/apex"
|
||||
actual := apex.installDir.RelPathString()
|
||||
expected := buildDir + "/target/product/test_device/product/apex"
|
||||
actual := apex.installDir.String()
|
||||
if actual != expected {
|
||||
t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
|
||||
}
|
||||
|
|
|
@ -350,11 +350,10 @@ func (installer *baseInstaller) AndroidMk(ctx AndroidMkContext, ret *android.And
|
|||
}
|
||||
|
||||
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
|
||||
path := installer.path.RelPathString()
|
||||
dir, file := filepath.Split(path)
|
||||
path, file := filepath.Split(installer.path.ToMakePath().String())
|
||||
stem, suffix, _ := android.SplitFileExt(file)
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path)
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
|
||||
})
|
||||
}
|
||||
|
@ -395,12 +394,11 @@ func (c *vndkPrebuiltLibraryDecorator) AndroidMk(ctx AndroidMkContext, ret *andr
|
|||
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
|
||||
c.libraryDecorator.androidMkWriteExportedFlags(w)
|
||||
|
||||
path := c.path.RelPathString()
|
||||
dir, file := filepath.Split(path)
|
||||
path, file := filepath.Split(c.path.ToMakePath().String())
|
||||
stem, suffix, ext := android.SplitFileExt(file)
|
||||
fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext)
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path)
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -129,6 +129,18 @@ func (p *vndkPrebuiltLibraryDecorator) singleSourcePath(ctx ModuleContext) andro
|
|||
|
||||
func (p *vndkPrebuiltLibraryDecorator) link(ctx ModuleContext,
|
||||
flags Flags, deps PathDeps, objs Objects) android.Path {
|
||||
|
||||
arches := ctx.DeviceConfig().Arches()
|
||||
if len(arches) == 0 || arches[0].ArchType.String() != p.arch() {
|
||||
ctx.Module().SkipInstall()
|
||||
return nil
|
||||
}
|
||||
|
||||
if ctx.DeviceConfig().BinderBitness() != p.binderBit() {
|
||||
ctx.Module().SkipInstall()
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(p.properties.Srcs) > 0 && p.shared() {
|
||||
p.libraryDecorator.exportIncludes(ctx)
|
||||
p.libraryDecorator.reexportSystemDirs(p.properties.Export_system_include_dirs...)
|
||||
|
@ -136,6 +148,8 @@ func (p *vndkPrebuiltLibraryDecorator) link(ctx ModuleContext,
|
|||
// current VNDK prebuilts are only shared libs.
|
||||
return p.singleSourcePath(ctx)
|
||||
}
|
||||
|
||||
ctx.Module().SkipInstall()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ func (p *platformCompatConfig) AndroidMkEntries() android.AndroidMkEntries {
|
|||
Include: "$(BUILD_PREBUILT)",
|
||||
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
||||
func(entries *android.AndroidMkEntries) {
|
||||
entries.SetString("LOCAL_MODULE_PATH", "$(OUT_DIR)/"+p.installDirPath.RelPathString())
|
||||
entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String())
|
||||
entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.configFile.Base())
|
||||
},
|
||||
},
|
||||
|
|
|
@ -89,12 +89,11 @@ func (installer *pythonInstaller) AndroidMk(base *Module, ret *android.AndroidMk
|
|||
|
||||
ret.Required = append(ret.Required, "libc++")
|
||||
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
|
||||
path := installer.path.RelPathString()
|
||||
dir, file := filepath.Split(path)
|
||||
path, file := filepath.Split(installer.path.ToMakePath().String())
|
||||
stem := strings.TrimSuffix(file, filepath.Ext(file))
|
||||
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+filepath.Ext(file))
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path)
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
|
||||
fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(installer.androidMkSharedLibs, " "))
|
||||
})
|
||||
|
|
|
@ -116,11 +116,10 @@ func (compiler *baseCompiler) AndroidMk(ctx AndroidMkContext, ret *android.Andro
|
|||
ret.OutputFile = android.OptionalPathForPath(compiler.path)
|
||||
}
|
||||
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
|
||||
path := compiler.path.RelPathString()
|
||||
dir, file := filepath.Split(path)
|
||||
path, file := filepath.Split(compiler.path.ToMakePath().String())
|
||||
stem, suffix, _ := android.SplitFileExt(file)
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path)
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -15,15 +15,40 @@
|
|||
package xml
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
)
|
||||
|
||||
var buildDir string
|
||||
|
||||
func setUp() {
|
||||
var err error
|
||||
buildDir, err = ioutil.TempDir("", "soong_xml_test")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func tearDown() {
|
||||
os.RemoveAll(buildDir)
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
run := func() int {
|
||||
setUp()
|
||||
defer tearDown()
|
||||
|
||||
return m.Run()
|
||||
}
|
||||
|
||||
os.Exit(run())
|
||||
}
|
||||
|
||||
func testXml(t *testing.T, bp string) *android.TestContext {
|
||||
config, buildDir := setup(t)
|
||||
defer teardown(buildDir)
|
||||
config := android.TestArchConfig(buildDir, nil)
|
||||
ctx := android.NewTestArchContext()
|
||||
ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory))
|
||||
ctx.RegisterModuleType("prebuilt_etc_xml", android.ModuleFactoryAdaptor(PrebuiltEtcXmlFactory))
|
||||
|
@ -45,21 +70,6 @@ func testXml(t *testing.T, bp string) *android.TestContext {
|
|||
return ctx
|
||||
}
|
||||
|
||||
func setup(t *testing.T) (config android.Config, buildDir string) {
|
||||
buildDir, err := ioutil.TempDir("", "soong_xml_test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
config = android.TestArchConfig(buildDir, nil)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func teardown(buildDir string) {
|
||||
os.RemoveAll(buildDir)
|
||||
}
|
||||
|
||||
func assertEqual(t *testing.T, name, expected, actual string) {
|
||||
t.Helper()
|
||||
if expected != actual {
|
||||
|
@ -103,5 +113,5 @@ func TestPrebuiltEtcXml(t *testing.T) {
|
|||
}
|
||||
|
||||
m := ctx.ModuleForTests("foo.xml", "android_arm64_armv8-a").Module().(*prebuiltEtcXml)
|
||||
assertEqual(t, "installDir", "target/product/test_device/system/etc", m.InstallDirPath().RelPathString())
|
||||
assertEqual(t, "installDir", buildDir+"/target/product/test_device/system/etc", m.InstallDirPath().String())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue