From d442a0e882aa49edbb944e21eaca2fca20d61b98 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 16 Nov 2023 11:19:26 -0800 Subject: [PATCH] Add DataPath.ToRelativeInstallPath Add a method to DataPath that converts it to the relative install path in preparation for adding additional complexity to DataPath. Bug: 311428265 Test: builds Change-Id: I65b06238aafda2db72c6a253744a3087976451cd --- android/paths.go | 8 ++++++++ apex/builder.go | 12 ++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/android/paths.go b/android/paths.go index a6cda38f0..37504b62f 100644 --- a/android/paths.go +++ b/android/paths.go @@ -2210,6 +2210,14 @@ type DataPath struct { RelativeInstallPath string } +func (d *DataPath) ToRelativeInstallPath() string { + relPath := d.SrcPath.Rel() + if d.RelativeInstallPath != "" { + relPath = filepath.Join(d.RelativeInstallPath, relPath) + } + return relPath +} + // PathsIfNonNil returns a Paths containing only the non-nil input arguments. func PathsIfNonNil(paths ...Path) Paths { if len(paths) == 0 { diff --git a/apex/builder.go b/apex/builder.go index 909a4792a..9f9e486b7 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -563,13 +563,8 @@ func (a *apexBundle) buildApex(ctx android.ModuleContext) { // Copy the test files (if any) 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.SrcPath.Rel() - dataPath := d.SrcPath.String() - if !strings.HasSuffix(dataPath, relPath) { - panic(fmt.Errorf("path %q does not end with %q", dataPath, relPath)) - } - - dataDest := imageDir.Join(ctx, fi.apexRelativePath(relPath), d.RelativeInstallPath).String() + relPath := d.ToRelativeInstallPath() + dataDest := imageDir.Join(ctx, fi.apexRelativePath(relPath)).String() copyCommands = append(copyCommands, "cp -f "+d.SrcPath.String()+" "+dataDest) implicitInputs = append(implicitInputs, d.SrcPath) @@ -1095,7 +1090,8 @@ func (a *apexBundle) buildCannedFsConfig(ctx android.ModuleContext) android.Outp 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.RelativeInstallPath, d.SrcPath.Rel())) + rel := d.ToRelativeInstallPath() + readOnlyPaths = append(readOnlyPaths, filepath.Join(f.installDir, rel)) } for _, s := range f.symlinks { executablePaths = append(executablePaths, filepath.Join(f.installDir, s))