platform_build/tools
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
..
aconfig Merge "aconfig: add storage api rust test on the host" into main 2024-02-09 21:00:16 +00:00
acp
apicheck
atree Fix uninitialized value warnings. 2022-12-20 16:51:53 -08:00
canoninja
compliance Update go.mod to 1.21 2023-12-14 15:37:35 +00:00
docker
droiddoc
finalization Add the next release to Class2NonSdkList. 2023-12-04 23:15:43 +00:00
fs_config
fs_get_stats
ide_query Create IDE query script 2024-02-12 13:57:59 +00:00
libhost
metadata Metadata tool correction: Output empty proto in case of no input 2024-01-11 11:15:23 +00:00
perf Store metrics for each run of a benchmark. 2024-01-31 09:49:47 -05:00
product_config
protos Support third_party.identifier in METADATA files of external packages. 2023-10-18 16:45:31 -07:00
rbcrun Raise go.mod version of build/make/tools/rbcrun 2023-12-14 12:05:03 -08:00
releasetools Allow merging target files without framework ab_partitions.txt 2024-02-06 14:40:57 +00:00
sbom Add a package in the SBOM of framework_res.jar. 2024-01-08 09:34:42 -08:00
signapk 16k: Sign the APKs to support 4k/16k page sizes 2023-10-20 03:13:39 +00:00
signtos
warn Make DeprecatedOrUnsafeBufferHandling not high severity 2023-01-09 14:19:11 -08:00
zipalign [zip] Set all entry times before 1980 to 1980-01-01 2023-09-06 21:44:40 +00:00
ziptime zipalign/ziptime: use ftello()/fseeko(). 2023-01-13 00:41:38 +00:00
Android.bp Determine GC type based on BUILT_KERNEL_VERSION_FILE. 2024-02-01 22:10:33 +08:00
auto_gen_test_config.py Move auto_gen_test_config.py to argparse. 2023-09-19 06:36:19 +00:00
auto_gen_test_config_test.py Remove EXTRA_TEST_RUNNER_CONFIGS option in template for autogen instrumentation test 2023-10-31 15:44:16 -07:00
brillo-clang-format
build-runfiles.cc
BUILD.bazel Make auto_gen_test_config available to Bazel. 2023-09-18 12:34:29 +00:00
buildinfo.sh Make common signature system property definitions optional 2023-07-11 22:40:19 +00:00
characteristics_rro_generator.py Add support for auto-generated characteristics RRO 2023-11-07 14:06:14 +09:00
check_elf_file.py
check_identical_lib.sh
check_radio_versions.py
compare_builds.py
event_log_tags.py
exercise_compare_builds
extract_kernel.py
fat16copy.py
fileslist_util.py
find_static_candidates.py find_static_candidates.py: protect against missing keys in module 2024-01-24 19:28:21 +00:00
findleaves.py
fixlinebreaks.sh
generate-enforce-rro-android-manifest.py
generate-notice-files.py
generate-self-extracting-archive.py
generate_gts_shared_report.py Remove GTS-Verifier license check 2023-05-19 10:38:55 +00:00
java-event-log-tags.py
list_files.py Add --classes optional flag in list_files 2023-06-27 04:46:50 +00:00
merge-event-log-tags.py
mk2bp_catalog.py
mk2bp_partition.py
normalize_path.py
overrideflags.sh change path to shell_utils.sh 2023-10-23 13:41:07 +00:00
post_process_props.py Determine GC type based on BUILT_KERNEL_VERSION_FILE. 2024-02-01 22:10:33 +08:00
post_process_props_unittest.xml
print_module_licenses.sh
soong_to_convert.py
stub_diff_analyzer.py
test_extract_kernel.py
test_post_process_props.py Define BOARD_API_LEVEL and BOARD_API_LEVEL_FROZEN 2023-11-10 16:31:04 +09:00
warn.py
whichgit