Move first/last unique elements utility functions to android package
Move firstUniqueElements to android.FirstUniqueStrings,
lastUniqueElements to android.LastUniqueStrings, and lastUniquePaths
to android.LastUniquePaths.
Test: m checkbuild
Change-Id: Ieac840405126c7f8f98afb4a4ef35c01a18fe7fb
diff --git a/cc/cc.go b/cc/cc.go
index 7163696..36b97e1 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -561,7 +561,7 @@
orderedAllDeps = append(orderedAllDeps, transitiveDeps[dep]...)
}
- orderedAllDeps = lastUniquePaths(orderedAllDeps)
+ orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
// We don't want to add any new dependencies into directDeps (to allow the caller to
// intentionally exclude or replace any unwanted transitive dependencies), so we limit the
@@ -763,12 +763,12 @@
deps = feature.deps(ctx, deps)
}
- deps.WholeStaticLibs = lastUniqueElements(deps.WholeStaticLibs)
- deps.StaticLibs = lastUniqueElements(deps.StaticLibs)
- deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
- deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
- deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
- deps.HeaderLibs = lastUniqueElements(deps.HeaderLibs)
+ deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
+ deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
+ deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
+ deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
+ deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
+ deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
for _, lib := range deps.ReexportSharedLibHeaders {
if !inList(lib, deps.SharedLibs) {
@@ -1249,13 +1249,13 @@
depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps)...)
// Dedup exported flags from dependencies
- depPaths.Flags = firstUniqueElements(depPaths.Flags)
+ depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
- depPaths.ReexportedFlags = firstUniqueElements(depPaths.ReexportedFlags)
+ depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
if c.sabi != nil {
- c.sabi.Properties.ReexportedIncludeFlags = firstUniqueElements(c.sabi.Properties.ReexportedIncludeFlags)
+ c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
}
return depPaths
@@ -1438,58 +1438,6 @@
}
}
-// firstUniqueElements returns all unique elements of a slice, keeping the first copy of each
-// modifies the slice contents in place, and returns a subslice of the original slice
-func firstUniqueElements(list []string) []string {
- k := 0
-outer:
- for i := 0; i < len(list); i++ {
- for j := 0; j < k; j++ {
- if list[i] == list[j] {
- continue outer
- }
- }
- list[k] = list[i]
- k++
- }
- return list[:k]
-}
-
-// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each.
-// It modifies the slice contents in place, and returns a subslice of the original slice
-func lastUniqueElements(list []string) []string {
- totalSkip := 0
- for i := len(list) - 1; i >= totalSkip; i-- {
- skip := 0
- for j := i - 1; j >= totalSkip; j-- {
- if list[i] == list[j] {
- skip++
- } else {
- list[j+skip] = list[j]
- }
- }
- totalSkip += skip
- }
- return list[totalSkip:]
-}
-
-// lastUniquePaths is the same as lastUniqueElements but uses Path structs
-func lastUniquePaths(list []android.Path) []android.Path {
- totalSkip := 0
- for i := len(list) - 1; i >= totalSkip; i-- {
- skip := 0
- for j := i - 1; j >= totalSkip; j-- {
- if list[i] == list[j] {
- skip++
- } else {
- list[j+skip] = list[j]
- }
- }
- totalSkip += skip
- }
- return list[totalSkip:]
-}
-
func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
if ctx.AConfig().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)