platform_build/tools/ide_query/go.work.sum
Michael Merg 6bafd75d51 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 13:57:59 +00:00

5 lines
470 B
Text

github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1 h1:7QnIQpGRHE5RnLKnESfDoxm2dTapTZua5a0kS0A+VXQ=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=