Remove ExpandSourcesSubDir and ModuleSrcPath.WithSubDir

Replace ExpandSourcesSubDir with ExpandSources plus
PathsWithModuleSrcSubDir, which loops over the paths and uses
Join to create paths relative to subdir on any results that
are ModuleSrcPaths.

Test: All soong tests
Change-Id: I11a7face88641e2c26ccdca0a3117d5c38ab588e
diff --git a/android/paths.go b/android/paths.go
index afde55e..a0ea753 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -620,6 +620,15 @@
 	return p.withRel(path)
 }
 
+// join is like Join but does less path validation.
+func (p SourcePath) join(ctx PathContext, paths ...string) SourcePath {
+	path, err := validateSafePath(paths...)
+	if err != nil {
+		reportPathError(ctx, err)
+	}
+	return p.withRel(path)
+}
+
 // OverlayPath returns the overlay for `path' if it exists. This assumes that the
 // SourcePath is the path to a resource overlay directory.
 func (p SourcePath) OverlayPath(ctx ModuleContext, path Path) OptionalPath {
@@ -773,10 +782,30 @@
 	} else if !exists {
 		reportPathErrorf(ctx, "module source path %q does not exist", path)
 	}
-
 	return path
 }
 
+// PathsWithModuleSrcSubDir takes a list of Paths and returns a new list of Paths where Rel() on each path
+// will return the path relative to subDir in the module's source directory.  If any input paths are not located
+// inside subDir then a path error will be reported.
+func PathsWithModuleSrcSubDir(ctx ModuleContext, paths Paths, subDir string) Paths {
+	paths = append(Paths(nil), paths...)
+	subDirFullPath := PathForModuleSrc(ctx, subDir)
+	for i, path := range paths {
+		rel := Rel(ctx, subDirFullPath.String(), path.String())
+		paths[i] = subDirFullPath.join(ctx, rel)
+	}
+	return paths
+}
+
+// PathWithModuleSrcSubDir takes a Path and returns a Path where Rel() will return the path relative to subDir in the
+// module's source directory.  If the input path is not located inside subDir then a path error will be reported.
+func PathWithModuleSrcSubDir(ctx ModuleContext, path Path, subDir string) Path {
+	subDirFullPath := PathForModuleSrc(ctx, subDir)
+	rel := Rel(ctx, subDirFullPath.String(), path.String())
+	return subDirFullPath.Join(ctx, rel)
+}
+
 // OptionalPathForModuleSrc returns an OptionalPath. The OptionalPath contains a
 // valid path if p is non-nil.
 func OptionalPathForModuleSrc(ctx ModuleContext, p *string) OptionalPath {
@@ -799,12 +828,6 @@
 	return PathForModuleRes(ctx, p.path, name)
 }
 
-func (p ModuleSrcPath) WithSubDir(ctx ModuleContext, subdir string) ModuleSrcPath {
-	subdir = PathForModuleSrc(ctx, subdir).String()
-	p.rel = Rel(ctx, subdir, p.path)
-	return p
-}
-
 // ModuleOutPath is a Path representing a module's output directory.
 type ModuleOutPath struct {
 	OutputPath