1package android 2 3import ( 4 "encoding/json" 5 "io" 6 "slices" 7 8 "github.com/google/blueprint" 9) 10 11type CoreModuleInfoJSON struct { 12 RegisterName string `json:"-"` 13 Path []string `json:"path,omitempty"` // $(sort $(ALL_MODULES.$(m).PATH)) 14 Installed []string `json:"installed,omitempty"` // $(sort $(ALL_MODULES.$(m).INSTALLED)) 15 ModuleName string `json:"module_name,omitempty"` // $(ALL_MODULES.$(m).MODULE_NAME) 16 SupportedVariants []string `json:"supported_variants,omitempty"` // $(sort $(ALL_MODULES.$(m).SUPPORTED_VARIANTS)) 17 HostDependencies []string `json:"host_dependencies,omitempty"` // $(sort $(ALL_MODULES.$(m).HOST_REQUIRED_FROM_TARGET)) 18 TargetDependencies []string `json:"target_dependencies,omitempty"` // $(sort $(ALL_MODULES.$(m).TARGET_REQUIRED_FROM_HOST)) 19 Data []string `json:"data,omitempty"` // $(sort $(ALL_MODULES.$(m).TEST_DATA)) 20 Required []string `json:"required,omitempty"` // $(sort $(ALL_MODULES.$(m).REQUIRED_FROM_TARGET)) 21} 22 23type ModuleInfoJSON struct { 24 core CoreModuleInfoJSON 25 SubName string `json:"-"` 26 Uninstallable bool `json:"-"` 27 Class []string `json:"class,omitempty"` // $(sort $(ALL_MODULES.$(m).CLASS)) 28 Tags []string `json:"tags,omitempty"` // $(sort $(ALL_MODULES.$(m).TAGS)) 29 Dependencies []string `json:"dependencies,omitempty"` // $(sort $(ALL_DEPS.$(m).ALL_DEPS)) 30 SharedLibs []string `json:"shared_libs,omitempty"` // $(sort $(ALL_MODULES.$(m).SHARED_LIBS)) 31 StaticLibs []string `json:"static_libs,omitempty"` // $(sort $(ALL_MODULES.$(m).STATIC_LIBS)) 32 SystemSharedLibs []string `json:"system_shared_libs,omitempty"` // $(sort $(ALL_MODULES.$(m).SYSTEM_SHARED_LIBS)) 33 Srcs []string `json:"srcs,omitempty"` // $(sort $(ALL_MODULES.$(m).SRCS)) 34 SrcJars []string `json:"srcjars,omitempty"` // $(sort $(ALL_MODULES.$(m).SRCJARS)) 35 ClassesJar []string `json:"classes_jar,omitempty"` // $(sort $(ALL_MODULES.$(m).CLASSES_JAR)) 36 TestMainlineModules []string `json:"test_mainline_modules,omitempty"` // $(sort $(ALL_MODULES.$(m).TEST_MAINLINE_MODULES)) 37 IsUnitTest bool `json:"is_unit_test,omitempty"` // $(ALL_MODULES.$(m).IS_UNIT_TEST) 38 TestOptionsTags []string `json:"test_options_tags,omitempty"` // $(sort $(ALL_MODULES.$(m).TEST_OPTIONS_TAGS)) 39 RuntimeDependencies []string `json:"runtime_dependencies,omitempty"` // $(sort $(ALL_MODULES.$(m).LOCAL_RUNTIME_LIBRARIES)) 40 StaticDependencies []string `json:"static_dependencies,omitempty"` // $(sort $(ALL_MODULES.$(m).LOCAL_STATIC_LIBRARIES)) 41 DataDependencies []string `json:"data_dependencies,omitempty"` // $(sort $(ALL_MODULES.$(m).TEST_DATA_BINS)) 42 43 CompatibilitySuites []string `json:"compatibility_suites,omitempty"` // $(sort $(ALL_MODULES.$(m).COMPATIBILITY_SUITES)) 44 AutoTestConfig []string `json:"auto_test_config,omitempty"` // $(ALL_MODULES.$(m).auto_test_config) 45 TestConfig []string `json:"test_config,omitempty"` // $(strip $(ALL_MODULES.$(m).TEST_CONFIG) $(ALL_MODULES.$(m).EXTRA_TEST_CONFIGS) 46} 47 48//ALL_DEPS.$(LOCAL_MODULE).ALL_DEPS := $(sort \ 49//$(ALL_DEPS.$(LOCAL_MODULE).ALL_DEPS) \ 50//$(LOCAL_STATIC_LIBRARIES) \ 51//$(LOCAL_WHOLE_STATIC_LIBRARIES) \ 52//$(LOCAL_SHARED_LIBRARIES) \ 53//$(LOCAL_DYLIB_LIBRARIES) \ 54//$(LOCAL_RLIB_LIBRARIES) \ 55//$(LOCAL_PROC_MACRO_LIBRARIES) \ 56//$(LOCAL_HEADER_LIBRARIES) \ 57//$(LOCAL_STATIC_JAVA_LIBRARIES) \ 58//$(LOCAL_JAVA_LIBRARIES) \ 59//$(LOCAL_JNI_SHARED_LIBRARIES)) 60 61type combinedModuleInfoJSON struct { 62 *CoreModuleInfoJSON 63 *ModuleInfoJSON 64} 65 66func encodeModuleInfoJSON(w io.Writer, moduleInfoJSON *ModuleInfoJSON) error { 67 moduleInfoJSONCopy := *moduleInfoJSON 68 69 sortAndUnique := func(s *[]string) { 70 *s = slices.Clone(*s) 71 slices.Sort(*s) 72 *s = slices.Compact(*s) 73 } 74 75 sortAndUnique(&moduleInfoJSONCopy.core.Path) 76 sortAndUnique(&moduleInfoJSONCopy.core.Installed) 77 sortAndUnique(&moduleInfoJSONCopy.core.SupportedVariants) 78 sortAndUnique(&moduleInfoJSONCopy.core.HostDependencies) 79 sortAndUnique(&moduleInfoJSONCopy.core.TargetDependencies) 80 sortAndUnique(&moduleInfoJSONCopy.core.Data) 81 sortAndUnique(&moduleInfoJSONCopy.core.Required) 82 83 sortAndUnique(&moduleInfoJSONCopy.Class) 84 sortAndUnique(&moduleInfoJSONCopy.Tags) 85 sortAndUnique(&moduleInfoJSONCopy.Dependencies) 86 sortAndUnique(&moduleInfoJSONCopy.SharedLibs) 87 sortAndUnique(&moduleInfoJSONCopy.StaticLibs) 88 sortAndUnique(&moduleInfoJSONCopy.SystemSharedLibs) 89 sortAndUnique(&moduleInfoJSONCopy.Srcs) 90 sortAndUnique(&moduleInfoJSONCopy.SrcJars) 91 sortAndUnique(&moduleInfoJSONCopy.ClassesJar) 92 sortAndUnique(&moduleInfoJSONCopy.TestMainlineModules) 93 sortAndUnique(&moduleInfoJSONCopy.TestOptionsTags) 94 sortAndUnique(&moduleInfoJSONCopy.RuntimeDependencies) 95 sortAndUnique(&moduleInfoJSONCopy.StaticDependencies) 96 sortAndUnique(&moduleInfoJSONCopy.DataDependencies) 97 sortAndUnique(&moduleInfoJSONCopy.CompatibilitySuites) 98 sortAndUnique(&moduleInfoJSONCopy.AutoTestConfig) 99 sortAndUnique(&moduleInfoJSONCopy.TestConfig) 100 101 encoder := json.NewEncoder(w) 102 return encoder.Encode(combinedModuleInfoJSON{&moduleInfoJSONCopy.core, &moduleInfoJSONCopy}) 103} 104 105var ModuleInfoJSONProvider = blueprint.NewProvider[*ModuleInfoJSON]() 106