summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Sean Hua <huasea@google.com> 2024-07-17 22:44:19 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2024-07-17 22:44:19 +0000
commitcd5c7d757aaba0717091fa1317f11669c8cd68f9 (patch)
treef1ad6d878a325a71a363c182c2b326bd32beb647
parent92b54c490704429be97d30baf4a9e69cb2273741 (diff)
parente783ed59a53149c5d098a0cedd4776905fde779a (diff)
Merge "Use default fallback when generating cc deps" into main
-rw-r--r--cc/ccdeps.go35
1 files changed, 19 insertions, 16 deletions
diff --git a/cc/ccdeps.go b/cc/ccdeps.go
index d30abbab7..469fe31fa 100644
--- a/cc/ccdeps.go
+++ b/cc/ccdeps.go
@@ -85,9 +85,8 @@ func (c *ccdepsGeneratorSingleton) GenerateBuildActions(ctx android.SingletonCon
moduleDeps := ccDeps{}
moduleInfos := map[string]ccIdeInfo{}
- // Track which projects have already had CMakeLists.txt generated to keep the first
- // variant for each project.
- seenProjects := map[string]bool{}
+ // Track if best variant (device arch match) has been found.
+ bestVariantFound := map[string]bool{}
pathToCC, _ := evalVariable(ctx, "${config.ClangBin}/")
moduleDeps.C_clang = fmt.Sprintf("%s%s", buildCMakePath(pathToCC), cClang)
@@ -96,7 +95,7 @@ func (c *ccdepsGeneratorSingleton) GenerateBuildActions(ctx android.SingletonCon
ctx.VisitAllModules(func(module android.Module) {
if ccModule, ok := module.(*Module); ok {
if compiledModule, ok := ccModule.compiler.(CompiledInterface); ok {
- generateCLionProjectData(ctx, compiledModule, ccModule, seenProjects, moduleInfos)
+ generateCLionProjectData(ctx, compiledModule, ccModule, bestVariantFound, moduleInfos)
}
}
})
@@ -180,26 +179,30 @@ func parseCompilerCCParameters(ctx android.SingletonContext, params []string) cc
}
func generateCLionProjectData(ctx android.SingletonContext, compiledModule CompiledInterface,
- ccModule *Module, seenProjects map[string]bool, moduleInfos map[string]ccIdeInfo) {
+ ccModule *Module, bestVariantFound map[string]bool, moduleInfos map[string]ccIdeInfo) {
+ moduleName := ccModule.ModuleBase.Name()
srcs := compiledModule.Srcs()
- if len(srcs) == 0 {
+
+ // Skip if best variant has already been found.
+ if bestVariantFound[moduleName] {
return
}
- // Only keep the DeviceArch variant module.
- if ctx.DeviceConfig().DeviceArch() != ccModule.ModuleBase.Arch().ArchType.Name {
+ // Skip if sources are empty.
+ if len(srcs) == 0 {
return
}
- clionProjectLocation := getCMakeListsForModule(ccModule, ctx)
- if seenProjects[clionProjectLocation] {
+ // Check if device arch matches, in which case this is the best variant and takes precedence.
+ if ccModule.Device() && ccModule.ModuleBase.Arch().ArchType.Name == ctx.DeviceConfig().DeviceArch() {
+ bestVariantFound[moduleName] = true
+ } else if _, ok := moduleInfos[moduleName]; ok {
+ // Skip because this isn't the best variant and a previous one has already been added.
+ // Heuristically, ones that appear first are likely to be more relevant.
return
}
- seenProjects[clionProjectLocation] = true
-
- name := ccModule.ModuleBase.Name()
- dpInfo := moduleInfos[name]
+ dpInfo := ccIdeInfo{}
dpInfo.Path = append(dpInfo.Path, path.Dir(ctx.BlueprintFile(ccModule)))
dpInfo.Srcs = append(dpInfo.Srcs, srcs.Strings()...)
@@ -216,9 +219,9 @@ func generateCLionProjectData(ctx android.SingletonContext, compiledModule Compi
dpInfo.Local_Cpp_flags = parseCompilerCCParameters(ctx, ccModule.flags.Local.CppFlags)
dpInfo.System_include_flags = parseCompilerCCParameters(ctx, ccModule.flags.SystemIncludeFlags)
- dpInfo.Module_name = name
+ dpInfo.Module_name = moduleName
- moduleInfos[name] = dpInfo
+ moduleInfos[moduleName] = dpInfo
}
type Deal struct {