platform_build/tools/ide_query/ide_query.sh

13 lines
305 B
Bash
Raw Normal View History

Create IDE query script This will be the integration point to provide build artifacts to Cider G. NOTE FOR REVIEWERS - original patch and result patch are not identical. PLEASE REVIEW CAREFULLY. Diffs between the patches: files := flag.Args() > - > - if prev, ok := modules[f]; ok && !strings.HasSuffix(prev.Name, ".impl") { > - log.Printf("File %q found in module %q but is already part of module %q", f, m.Name, prev.Name) > + if modules[f] != nil { > + log.Printf("File %q found in module %q but is already covered by module %q", f, m.Name, modules[f].Name) > - var genFiles []*pb.GeneratedFile > + var generated []*pb.GeneratedFile > - // Note: Contents will be filled below. > - genFiles = append(genFiles, &pb.GeneratedFile{Path: relPath}) > + contents, err := os.ReadFile(d) > + if err != nil { > + fmt.Printf("Generated file %q not found - will be skipped.\n", d) > + continue > + } > + > + generated = append(generated, &pb.GeneratedFile{ > + Path: relPath, > + Contents: contents, > + }) > - file.Generated = genFiles > + file.Generated = generated > - for _, s := range sources { > - for _, g := range s.GetGenerated() { > - contents, err := os.ReadFile(path.Join(env.OutDir, g.GetPath())) > - if err != nil { > - fmt.Printf("Failed to read generated file %q: %v. File contents will be missing.\n", g.GetPath(), err) > - continue > - } > - g.Contents = contents > - } > - } > - > - if strings.HasSuffix(name, "-jarjar") { > + if strings.HasSuffix(name, "-jarjar") || strings.HasSuffix(name, ".impl") { Original patch: diff --git a/tools/ide_query/ide_query.go b/tools/ide_query/ide_query.go old mode 100644 new mode 100644 --- a/tools/ide_query/ide_query.go +++ b/tools/ide_query/ide_query.go @@ -1,3 +1,5 @@ +// Binary ide_query generates and analyzes build artifacts. +// The produced result can be consumed by IDEs to provide language features. package main import ( @@ -34,10 +36,10 @@ var _ flag.Value = (*LunchTarget)(nil) -// Get implements flag.Value. -func (l *LunchTarget) Get() any { - return l -} +// // Get implements flag.Value. +// func (l *LunchTarget) Get() any { +// return l +// } // Set implements flag.Value. func (l *LunchTarget) Set(s string) error { @@ -64,13 +66,12 @@ env.RepoDir = os.Getenv("TOP") flag.Var(&env.LunchTarget, "lunch_target", "The lunch target to query") flag.Parse() - if flag.NArg() == 0 { + files := flag.Args() + if len(files) == 0 { fmt.Println("No files provided.") os.Exit(1) return } - - files := flag.Args() ctx := context.Background() javaDepsPath := pa [[[Original patch trimmed due to size. Decoded string size: 2916. Decoded string SHA1: 5d8fd4a92cc403da51c9ddb8442da2e391e6fcb1.]]] Result patch: diff --git a/tools/ide_query/ide_query.go b/tools/ide_query/ide_query.go index 2e76738..0fdb6de 100644 --- a/tools/ide_query/ide_query.go +++ b/tools/ide_query/ide_query.go @@ -1,3 +1,5 @@ +// Binary ide_query generates and analyzes build artifacts. +// The produced result can be consumed by IDEs to provide language features. package main import ( @@ -34,10 +36,10 @@ var _ flag.Value = (*LunchTarget)(nil) -// Get implements flag.Value. -func (l *LunchTarget) Get() any { - return l -} +// // Get implements flag.Value. +// func (l *LunchTarget) Get() any { +// return l +// } // Set implements flag.Value. func (l *LunchTarget) Set(s string) error { @@ -64,14 +66,13 @@ env.RepoDir = os.Getenv("TOP") flag.Var(&env.LunchTarget, "lunch_target", "The lunch target to query") flag.Parse() - if flag.NArg() == 0 { + files := flag.Args() + if len(files) == 0 { fmt.Println("No files provided.") os.Exit(1) return } - files := flag.Args() - ctx := context.Background() javaDepsPath := path [[[Result patch trimmed due to size. Decoded string size: 3022. Decoded string SHA1: a8824749eafbbb8d09c4e95fe491a16e3ea82569.]]] NOTE FOR REVIEWERS - original patch and result patch are not identical. PLEASE REVIEW CAREFULLY. Diffs between the patches: var javaFiles []string > + for _, f := range files { > + switch { > + case strings.HasSuffix(f, ".java") || strings.HasSuffix(f, ".kt"): > + javaFiles = append(javaFiles, f) > + default: > + log.Printf("File %q is supported - will be skipped.", f) > + } > + } > + > - modules := make(map[string]*javaModule) // file path -> module > - for _, f := range files { > + fileToModule := make(map[string]*javaModule) // file path -> module > + for _, f := range javaFiles { > - if modules[f] != nil { > - log.Printf("File %q found in module %q but is already covered by module %q", f, m.Name, modules[f].Name) > + if fileToModule[f] != nil { > + // TODO(michaelmerg): Handle the case where a file is covered by multiple modules. > + log.Printf("File %q found in module %q but is already covered by module %q", f, m.Name, fileToModule[f].Name) > - modules[f] = m > + fileToModule[f] = m > - for _, m := range modules { > + for _, m := range fileToModule { > + type depsAndGenerated struct { > + Deps []string > + Generated []*pb.GeneratedFile > + } > + moduleToDeps := make(map[string]*depsAndGenerated) > - m := modules[f] > + m := fileToModule[f] > + file.Status = &pb.Status{Code: pb.Status_OK} > + if moduleToDeps[m.Name] != nil { > + file.Generated = moduleToDeps[m.Name].Generated > + file.Deps = moduleToDeps[m.Name].Deps > + continue > + } > + > - > + moduleToDeps[m.Name] = &depsAndGenerated{deps, generated} > - file.Status = &pb.Status{Code: pb.Status_OK} Original patch: diff --git a/tools/ide_query/ide_query.go b/tools/ide_query/ide_query.go old mode 100644 new mode 100644 --- a/tools/ide_query/ide_query.go +++ b/tools/ide_query/ide_query.go @@ -72,6 +72,16 @@ os.Exit(1) return } + + var javaFiles []string + for _, f := range files { + switch { + case strings.HasSuffix(f, ".java") || strings.HasSuffix(f, ".kt"): + javaFiles = append(javaFiles, f) + default: + log.Printf("File %q is supported - will be skipped.", f) + } + } ctx := context.Background() javaDepsPath := path.Join(env.RepoDir, env.OutDir, "soong/module_bp_java_deps.json") @@ -85,22 +95,23 @@ log.Fatalf("Failed to load java modules: %v", err) } - modules := make(map[string]*javaModule) // file path -> module - for _, f := range files { + fileToModule := make(map[string]*javaModule) // file path -> module + for _, f := range javaFiles { for _, m := range javaModules { if !slices.Contains(m.Srcs, f) { continue } - if modules[f] != nil { - log.Printf("File %q found in [[[Original patch trimmed due to size. Decoded string size: 2629. Decoded string SHA1: 4517ba713fdb898ba9d77c4acbe934c08a2d9fe0.]]] Result patch: diff --git a/tools/ide_query/ide_query.go b/tools/ide_query/ide_query.go index 0fdb6de..7335875 100644 --- a/tools/ide_query/ide_query.go +++ b/tools/ide_query/ide_query.go @@ -73,6 +73,16 @@ return } + var javaFiles []string + for _, f := range files { + switch { + case strings.HasSuffix(f, ".java") || strings.HasSuffix(f, ".kt"): + javaFiles = append(javaFiles, f) + default: + log.Printf("File %q is supported - will be skipped.", f) + } + } + ctx := context.Background() javaDepsPath := path.Join(env.RepoDir, env.OutDir, "soong/module_bp_java_deps.json") // TODO(michaelmerg): Figure out if module_bp_java_deps.json is outdated. @@ -85,22 +95,23 @@ log.Fatalf("Failed to load java modules: %v", err) } - modules := make(map[string]*javaModule) // file path -> module - for _, f := range files { + fileToModule := make(map[string]*javaModule) // file path -> module + for _, f := range javaFiles { for _, m := range javaModules { if !slices.Contains(m.Srcs, f) { continue } [[[Result patch trimmed due to size. Decoded string size: 2717. Decoded string SHA1: 5e5223251ebdc548258bc27daf3528d662c39410.]]] Change-Id: Ibe5d386399affd2951206bb5a714972e0e2fee92
2024-02-12 14:52:00 +01:00
#!/bin/bash -e
cd $(dirname $BASH_SOURCE)
source $(pwd)/../../shell_utils.sh
require_top
# Ensure cogsetup (out/ will be symlink outside the repo)
. ${TOP}/build/make/cogsetup.sh
export ANDROID_BUILD_TOP=$TOP
export OUT_DIR=${OUT_DIR}
exec "${TOP}/prebuilts/go/linux-x86/bin/go" "run" "ide_query" "$@"