1*333d2b36SAndroid Build Coastguard Worker// Copyright 2017 Google Inc. All rights reserved. 2*333d2b36SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License"); 3*333d2b36SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License. 4*333d2b36SAndroid Build Coastguard Worker// You may obtain a copy of the License at 5*333d2b36SAndroid Build Coastguard Worker// 6*333d2b36SAndroid Build Coastguard Worker// http://www.apache.org/licenses/LICENSE-2.0 7*333d2b36SAndroid Build Coastguard Worker// 8*333d2b36SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software 9*333d2b36SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS, 10*333d2b36SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11*333d2b36SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and 12*333d2b36SAndroid Build Coastguard Worker// limitations under the License. 13*333d2b36SAndroid Build Coastguard Worker 14*333d2b36SAndroid Build Coastguard Workerpackage java 15*333d2b36SAndroid Build Coastguard Worker 16*333d2b36SAndroid Build Coastguard Workerimport ( 17*333d2b36SAndroid Build Coastguard Worker "fmt" 18*333d2b36SAndroid Build Coastguard Worker "io" 19*333d2b36SAndroid Build Coastguard Worker "strings" 20*333d2b36SAndroid Build Coastguard Worker 21*333d2b36SAndroid Build Coastguard Worker "github.com/google/blueprint" 22*333d2b36SAndroid Build Coastguard Worker "github.com/google/blueprint/depset" 23*333d2b36SAndroid Build Coastguard Worker "github.com/google/blueprint/proptools" 24*333d2b36SAndroid Build Coastguard Worker 25*333d2b36SAndroid Build Coastguard Worker "android/soong/android" 26*333d2b36SAndroid Build Coastguard Worker) 27*333d2b36SAndroid Build Coastguard Worker 28*333d2b36SAndroid Build Coastguard Worker// OpenJDK 9 introduces the concept of "system modules", which replace the bootclasspath. This 29*333d2b36SAndroid Build Coastguard Worker// file will produce the rules necessary to convert each unique set of bootclasspath jars into 30*333d2b36SAndroid Build Coastguard Worker// system modules in a runtime image using the jmod and jlink tools. 31*333d2b36SAndroid Build Coastguard Worker 32*333d2b36SAndroid Build Coastguard Workerfunc init() { 33*333d2b36SAndroid Build Coastguard Worker RegisterSystemModulesBuildComponents(android.InitRegistrationContext) 34*333d2b36SAndroid Build Coastguard Worker 35*333d2b36SAndroid Build Coastguard Worker pctx.SourcePathVariable("moduleInfoJavaPath", "build/soong/scripts/jars-to-module-info-java.sh") 36*333d2b36SAndroid Build Coastguard Worker 37*333d2b36SAndroid Build Coastguard Worker // Register sdk member types. 38*333d2b36SAndroid Build Coastguard Worker android.RegisterSdkMemberType(&systemModulesSdkMemberType{ 39*333d2b36SAndroid Build Coastguard Worker android.SdkMemberTypeBase{ 40*333d2b36SAndroid Build Coastguard Worker PropertyName: "java_system_modules", 41*333d2b36SAndroid Build Coastguard Worker SupportsSdk: true, 42*333d2b36SAndroid Build Coastguard Worker }, 43*333d2b36SAndroid Build Coastguard Worker }) 44*333d2b36SAndroid Build Coastguard Worker} 45*333d2b36SAndroid Build Coastguard Worker 46*333d2b36SAndroid Build Coastguard Workerfunc RegisterSystemModulesBuildComponents(ctx android.RegistrationContext) { 47*333d2b36SAndroid Build Coastguard Worker ctx.RegisterModuleType("java_system_modules", SystemModulesFactory) 48*333d2b36SAndroid Build Coastguard Worker ctx.RegisterModuleType("java_system_modules_import", systemModulesImportFactory) 49*333d2b36SAndroid Build Coastguard Worker} 50*333d2b36SAndroid Build Coastguard Worker 51*333d2b36SAndroid Build Coastguard Workervar ( 52*333d2b36SAndroid Build Coastguard Worker jarsTosystemModules = pctx.AndroidStaticRule("jarsTosystemModules", blueprint.RuleParams{ 53*333d2b36SAndroid Build Coastguard Worker Command: `rm -rf ${outDir} ${workDir} && mkdir -p ${workDir}/jmod && ` + 54*333d2b36SAndroid Build Coastguard Worker `${moduleInfoJavaPath} java.base $in > ${workDir}/module-info.java && ` + 55*333d2b36SAndroid Build Coastguard Worker `${config.JavacCmd} --system=none --patch-module=java.base=${classpath} ${workDir}/module-info.java && ` + 56*333d2b36SAndroid Build Coastguard Worker `${config.SoongZipCmd} -jar -o ${workDir}/classes.jar -C ${workDir} -f ${workDir}/module-info.class && ` + 57*333d2b36SAndroid Build Coastguard Worker `${config.MergeZipsCmd} -j ${workDir}/module.jar ${workDir}/classes.jar $in && ` + 58*333d2b36SAndroid Build Coastguard Worker // Note: The version of the java.base module created must match the version 59*333d2b36SAndroid Build Coastguard Worker // of the jlink tool which consumes it. 60*333d2b36SAndroid Build Coastguard Worker // Use LINUX-OTHER to be compatible with JDK 21+ (b/294137077) 61*333d2b36SAndroid Build Coastguard Worker `${config.JmodCmd} create --module-version ${config.JlinkVersion} --target-platform LINUX-OTHER ` + 62*333d2b36SAndroid Build Coastguard Worker ` --class-path ${workDir}/module.jar ${workDir}/jmod/java.base.jmod && ` + 63*333d2b36SAndroid Build Coastguard Worker `${config.JlinkCmd} --module-path ${workDir}/jmod --add-modules java.base --output ${outDir} ` + 64*333d2b36SAndroid Build Coastguard Worker // Note: The system-modules jlink plugin is disabled because (a) it is not 65*333d2b36SAndroid Build Coastguard Worker // useful on Android, and (b) it causes errors with later versions of jlink 66*333d2b36SAndroid Build Coastguard Worker // when the jdk.internal.module is absent from java.base (as it is here). 67*333d2b36SAndroid Build Coastguard Worker ` --disable-plugin system-modules && ` + 68*333d2b36SAndroid Build Coastguard Worker `rm -rf ${workDir} && ` + 69*333d2b36SAndroid Build Coastguard Worker `cp ${config.JrtFsJar} ${outDir}/lib/`, 70*333d2b36SAndroid Build Coastguard Worker CommandDeps: []string{ 71*333d2b36SAndroid Build Coastguard Worker "${moduleInfoJavaPath}", 72*333d2b36SAndroid Build Coastguard Worker "${config.JavacCmd}", 73*333d2b36SAndroid Build Coastguard Worker "${config.SoongZipCmd}", 74*333d2b36SAndroid Build Coastguard Worker "${config.MergeZipsCmd}", 75*333d2b36SAndroid Build Coastguard Worker "${config.JmodCmd}", 76*333d2b36SAndroid Build Coastguard Worker "${config.JlinkCmd}", 77*333d2b36SAndroid Build Coastguard Worker "${config.JrtFsJar}", 78*333d2b36SAndroid Build Coastguard Worker }, 79*333d2b36SAndroid Build Coastguard Worker }, 80*333d2b36SAndroid Build Coastguard Worker "classpath", "outDir", "workDir") 81*333d2b36SAndroid Build Coastguard Worker 82*333d2b36SAndroid Build Coastguard Worker // Dependency tag that causes the added dependencies to be added as java_header_libs 83*333d2b36SAndroid Build Coastguard Worker // to the sdk/module_exports/snapshot. Dependencies that are added automatically via this tag are 84*333d2b36SAndroid Build Coastguard Worker // not automatically exported. 85*333d2b36SAndroid Build Coastguard Worker systemModulesLibsTag = android.DependencyTagForSdkMemberType(javaHeaderLibsSdkMemberType, false) 86*333d2b36SAndroid Build Coastguard Worker) 87*333d2b36SAndroid Build Coastguard Worker 88*333d2b36SAndroid Build Coastguard Workerfunc TransformJarsToSystemModules(ctx android.ModuleContext, jars android.Paths) (android.Path, android.Paths) { 89*333d2b36SAndroid Build Coastguard Worker outDir := android.PathForModuleOut(ctx, "system") 90*333d2b36SAndroid Build Coastguard Worker workDir := android.PathForModuleOut(ctx, "modules") 91*333d2b36SAndroid Build Coastguard Worker outputFile := android.PathForModuleOut(ctx, "system/lib/modules") 92*333d2b36SAndroid Build Coastguard Worker outputs := android.WritablePaths{ 93*333d2b36SAndroid Build Coastguard Worker outputFile, 94*333d2b36SAndroid Build Coastguard Worker android.PathForModuleOut(ctx, "system/lib/jrt-fs.jar"), 95*333d2b36SAndroid Build Coastguard Worker android.PathForModuleOut(ctx, "system/release"), 96*333d2b36SAndroid Build Coastguard Worker } 97*333d2b36SAndroid Build Coastguard Worker 98*333d2b36SAndroid Build Coastguard Worker ctx.Build(pctx, android.BuildParams{ 99*333d2b36SAndroid Build Coastguard Worker Rule: jarsTosystemModules, 100*333d2b36SAndroid Build Coastguard Worker Description: "system modules", 101*333d2b36SAndroid Build Coastguard Worker Outputs: outputs, 102*333d2b36SAndroid Build Coastguard Worker Inputs: jars, 103*333d2b36SAndroid Build Coastguard Worker Args: map[string]string{ 104*333d2b36SAndroid Build Coastguard Worker "classpath": strings.Join(jars.Strings(), ":"), 105*333d2b36SAndroid Build Coastguard Worker "workDir": workDir.String(), 106*333d2b36SAndroid Build Coastguard Worker "outDir": outDir.String(), 107*333d2b36SAndroid Build Coastguard Worker }, 108*333d2b36SAndroid Build Coastguard Worker }) 109*333d2b36SAndroid Build Coastguard Worker 110*333d2b36SAndroid Build Coastguard Worker return outDir, outputs.Paths() 111*333d2b36SAndroid Build Coastguard Worker} 112*333d2b36SAndroid Build Coastguard Worker 113*333d2b36SAndroid Build Coastguard Worker// java_system_modules creates a system module from a set of java libraries that can 114*333d2b36SAndroid Build Coastguard Worker// be referenced from the system_modules property. It must contain at a minimum the 115*333d2b36SAndroid Build Coastguard Worker// java.base module which must include classes from java.lang amongst other java packages. 116*333d2b36SAndroid Build Coastguard Workerfunc SystemModulesFactory() android.Module { 117*333d2b36SAndroid Build Coastguard Worker module := &SystemModules{} 118*333d2b36SAndroid Build Coastguard Worker module.AddProperties(&module.properties) 119*333d2b36SAndroid Build Coastguard Worker android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) 120*333d2b36SAndroid Build Coastguard Worker android.InitDefaultableModule(module) 121*333d2b36SAndroid Build Coastguard Worker return module 122*333d2b36SAndroid Build Coastguard Worker} 123*333d2b36SAndroid Build Coastguard Worker 124*333d2b36SAndroid Build Coastguard Workertype SystemModulesProviderInfo struct { 125*333d2b36SAndroid Build Coastguard Worker // The aggregated header jars from all jars specified in the libs property. 126*333d2b36SAndroid Build Coastguard Worker // Used when system module is added as a dependency to bootclasspath. 127*333d2b36SAndroid Build Coastguard Worker HeaderJars android.Paths 128*333d2b36SAndroid Build Coastguard Worker 129*333d2b36SAndroid Build Coastguard Worker OutputDir android.Path 130*333d2b36SAndroid Build Coastguard Worker OutputDirDeps android.Paths 131*333d2b36SAndroid Build Coastguard Worker 132*333d2b36SAndroid Build Coastguard Worker // depset of header jars for this module and all transitive static dependencies 133*333d2b36SAndroid Build Coastguard Worker TransitiveStaticLibsHeaderJars depset.DepSet[android.Path] 134*333d2b36SAndroid Build Coastguard Worker} 135*333d2b36SAndroid Build Coastguard Worker 136*333d2b36SAndroid Build Coastguard Workervar SystemModulesProvider = blueprint.NewProvider[*SystemModulesProviderInfo]() 137*333d2b36SAndroid Build Coastguard Worker 138*333d2b36SAndroid Build Coastguard Workertype SystemModules struct { 139*333d2b36SAndroid Build Coastguard Worker android.ModuleBase 140*333d2b36SAndroid Build Coastguard Worker android.DefaultableModuleBase 141*333d2b36SAndroid Build Coastguard Worker 142*333d2b36SAndroid Build Coastguard Worker properties SystemModulesProperties 143*333d2b36SAndroid Build Coastguard Worker 144*333d2b36SAndroid Build Coastguard Worker outputDir android.Path 145*333d2b36SAndroid Build Coastguard Worker outputDeps android.Paths 146*333d2b36SAndroid Build Coastguard Worker} 147*333d2b36SAndroid Build Coastguard Worker 148*333d2b36SAndroid Build Coastguard Workertype SystemModulesProperties struct { 149*333d2b36SAndroid Build Coastguard Worker // List of java library modules that should be included in the system modules 150*333d2b36SAndroid Build Coastguard Worker Libs []string 151*333d2b36SAndroid Build Coastguard Worker} 152*333d2b36SAndroid Build Coastguard Worker 153*333d2b36SAndroid Build Coastguard Workerfunc (system *SystemModules) GenerateAndroidBuildActions(ctx android.ModuleContext) { 154*333d2b36SAndroid Build Coastguard Worker var jars android.Paths 155*333d2b36SAndroid Build Coastguard Worker 156*333d2b36SAndroid Build Coastguard Worker var transitiveStaticLibsHeaderJars []depset.DepSet[android.Path] 157*333d2b36SAndroid Build Coastguard Worker ctx.VisitDirectDepsWithTag(systemModulesLibsTag, func(module android.Module) { 158*333d2b36SAndroid Build Coastguard Worker if dep, ok := android.OtherModuleProvider(ctx, module, JavaInfoProvider); ok { 159*333d2b36SAndroid Build Coastguard Worker jars = append(jars, dep.HeaderJars...) 160*333d2b36SAndroid Build Coastguard Worker transitiveStaticLibsHeaderJars = append(transitiveStaticLibsHeaderJars, dep.TransitiveStaticLibsHeaderJars) 161*333d2b36SAndroid Build Coastguard Worker } 162*333d2b36SAndroid Build Coastguard Worker }) 163*333d2b36SAndroid Build Coastguard Worker 164*333d2b36SAndroid Build Coastguard Worker system.outputDir, system.outputDeps = TransformJarsToSystemModules(ctx, jars) 165*333d2b36SAndroid Build Coastguard Worker 166*333d2b36SAndroid Build Coastguard Worker android.SetProvider(ctx, SystemModulesProvider, &SystemModulesProviderInfo{ 167*333d2b36SAndroid Build Coastguard Worker HeaderJars: jars, 168*333d2b36SAndroid Build Coastguard Worker OutputDir: system.outputDir, 169*333d2b36SAndroid Build Coastguard Worker OutputDirDeps: system.outputDeps, 170*333d2b36SAndroid Build Coastguard Worker TransitiveStaticLibsHeaderJars: depset.New(depset.PREORDER, nil, transitiveStaticLibsHeaderJars), 171*333d2b36SAndroid Build Coastguard Worker }) 172*333d2b36SAndroid Build Coastguard Worker} 173*333d2b36SAndroid Build Coastguard Worker 174*333d2b36SAndroid Build Coastguard Worker// ComponentDepsMutator is called before prebuilt modules without a corresponding source module are 175*333d2b36SAndroid Build Coastguard Worker// renamed so unless the supplied libs specifically includes the prebuilt_ prefix this is guaranteed 176*333d2b36SAndroid Build Coastguard Worker// to only add dependencies on source modules. 177*333d2b36SAndroid Build Coastguard Worker// 178*333d2b36SAndroid Build Coastguard Worker// The systemModuleLibsTag will prevent the prebuilt mutators from replacing this dependency so it 179*333d2b36SAndroid Build Coastguard Worker// will never be changed to depend on a prebuilt either. 180*333d2b36SAndroid Build Coastguard Workerfunc (system *SystemModules) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { 181*333d2b36SAndroid Build Coastguard Worker ctx.AddVariationDependencies(nil, systemModulesLibsTag, system.properties.Libs...) 182*333d2b36SAndroid Build Coastguard Worker} 183*333d2b36SAndroid Build Coastguard Worker 184*333d2b36SAndroid Build Coastguard Workerfunc (system *SystemModules) AndroidMk() android.AndroidMkData { 185*333d2b36SAndroid Build Coastguard Worker return android.AndroidMkData{ 186*333d2b36SAndroid Build Coastguard Worker Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { 187*333d2b36SAndroid Build Coastguard Worker fmt.Fprintln(w) 188*333d2b36SAndroid Build Coastguard Worker 189*333d2b36SAndroid Build Coastguard Worker makevar := "SOONG_SYSTEM_MODULES_" + name 190*333d2b36SAndroid Build Coastguard Worker fmt.Fprintln(w, makevar, ":=$=", system.outputDir.String()) 191*333d2b36SAndroid Build Coastguard Worker fmt.Fprintln(w) 192*333d2b36SAndroid Build Coastguard Worker 193*333d2b36SAndroid Build Coastguard Worker makevar = "SOONG_SYSTEM_MODULES_LIBS_" + name 194*333d2b36SAndroid Build Coastguard Worker fmt.Fprintln(w, makevar, ":=$=", strings.Join(system.properties.Libs, " ")) 195*333d2b36SAndroid Build Coastguard Worker fmt.Fprintln(w) 196*333d2b36SAndroid Build Coastguard Worker 197*333d2b36SAndroid Build Coastguard Worker makevar = "SOONG_SYSTEM_MODULES_DEPS_" + name 198*333d2b36SAndroid Build Coastguard Worker fmt.Fprintln(w, makevar, ":=$=", strings.Join(system.outputDeps.Strings(), " ")) 199*333d2b36SAndroid Build Coastguard Worker fmt.Fprintln(w) 200*333d2b36SAndroid Build Coastguard Worker 201*333d2b36SAndroid Build Coastguard Worker fmt.Fprintln(w, name+":", "$("+makevar+")") 202*333d2b36SAndroid Build Coastguard Worker fmt.Fprintln(w, ".PHONY:", name) 203*333d2b36SAndroid Build Coastguard Worker // TODO(b/151177513): Licenses: Doesn't go through base_rules. May have to generate meta_lic and meta_module here. 204*333d2b36SAndroid Build Coastguard Worker }, 205*333d2b36SAndroid Build Coastguard Worker } 206*333d2b36SAndroid Build Coastguard Worker} 207*333d2b36SAndroid Build Coastguard Worker 208*333d2b36SAndroid Build Coastguard Worker// A prebuilt version of java_system_modules. It does not import the 209*333d2b36SAndroid Build Coastguard Worker// generated system module, it generates the system module from imported 210*333d2b36SAndroid Build Coastguard Worker// java libraries in the same way that java_system_modules does. It just 211*333d2b36SAndroid Build Coastguard Worker// acts as a prebuilt, i.e. can have the same base name as another module 212*333d2b36SAndroid Build Coastguard Worker// type and the one to use is selected at runtime. 213*333d2b36SAndroid Build Coastguard Workerfunc systemModulesImportFactory() android.Module { 214*333d2b36SAndroid Build Coastguard Worker module := &systemModulesImport{} 215*333d2b36SAndroid Build Coastguard Worker module.AddProperties(&module.properties, &module.prebuiltProperties) 216*333d2b36SAndroid Build Coastguard Worker android.InitPrebuiltModule(module, &module.properties.Libs) 217*333d2b36SAndroid Build Coastguard Worker android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) 218*333d2b36SAndroid Build Coastguard Worker android.InitDefaultableModule(module) 219*333d2b36SAndroid Build Coastguard Worker return module 220*333d2b36SAndroid Build Coastguard Worker} 221*333d2b36SAndroid Build Coastguard Worker 222*333d2b36SAndroid Build Coastguard Workertype systemModulesImport struct { 223*333d2b36SAndroid Build Coastguard Worker SystemModules 224*333d2b36SAndroid Build Coastguard Worker prebuilt android.Prebuilt 225*333d2b36SAndroid Build Coastguard Worker prebuiltProperties prebuiltSystemModulesProperties 226*333d2b36SAndroid Build Coastguard Worker} 227*333d2b36SAndroid Build Coastguard Worker 228*333d2b36SAndroid Build Coastguard Workertype prebuiltSystemModulesProperties struct { 229*333d2b36SAndroid Build Coastguard Worker // Name of the source soong module that gets shadowed by this prebuilt 230*333d2b36SAndroid Build Coastguard Worker // If unspecified, follows the naming convention that the source module of 231*333d2b36SAndroid Build Coastguard Worker // the prebuilt is Name() without "prebuilt_" prefix 232*333d2b36SAndroid Build Coastguard Worker Source_module_name *string 233*333d2b36SAndroid Build Coastguard Worker} 234*333d2b36SAndroid Build Coastguard Worker 235*333d2b36SAndroid Build Coastguard Workerfunc (system *systemModulesImport) Name() string { 236*333d2b36SAndroid Build Coastguard Worker return system.prebuilt.Name(system.ModuleBase.Name()) 237*333d2b36SAndroid Build Coastguard Worker} 238*333d2b36SAndroid Build Coastguard Worker 239*333d2b36SAndroid Build Coastguard Worker// BaseModuleName returns the source module that will get shadowed by this prebuilt 240*333d2b36SAndroid Build Coastguard Worker// e.g. 241*333d2b36SAndroid Build Coastguard Worker// 242*333d2b36SAndroid Build Coastguard Worker// java_system_modules_import { 243*333d2b36SAndroid Build Coastguard Worker// name: "my_system_modules.v1", 244*333d2b36SAndroid Build Coastguard Worker// source_module_name: "my_system_modules", 245*333d2b36SAndroid Build Coastguard Worker// } 246*333d2b36SAndroid Build Coastguard Worker// 247*333d2b36SAndroid Build Coastguard Worker// java_system_modules_import { 248*333d2b36SAndroid Build Coastguard Worker// name: "my_system_modules.v2", 249*333d2b36SAndroid Build Coastguard Worker// source_module_name: "my_system_modules", 250*333d2b36SAndroid Build Coastguard Worker// } 251*333d2b36SAndroid Build Coastguard Worker// 252*333d2b36SAndroid Build Coastguard Worker// `BaseModuleName` for both will return `my_system_modules` 253*333d2b36SAndroid Build Coastguard Workerfunc (system *systemModulesImport) BaseModuleName() string { 254*333d2b36SAndroid Build Coastguard Worker return proptools.StringDefault(system.prebuiltProperties.Source_module_name, system.ModuleBase.Name()) 255*333d2b36SAndroid Build Coastguard Worker} 256*333d2b36SAndroid Build Coastguard Worker 257*333d2b36SAndroid Build Coastguard Workerfunc (system *systemModulesImport) Prebuilt() *android.Prebuilt { 258*333d2b36SAndroid Build Coastguard Worker return &system.prebuilt 259*333d2b36SAndroid Build Coastguard Worker} 260*333d2b36SAndroid Build Coastguard Worker 261*333d2b36SAndroid Build Coastguard Worker// ComponentDepsMutator is called before prebuilt modules without a corresponding source module are 262*333d2b36SAndroid Build Coastguard Worker// renamed so as this adds a prebuilt_ prefix this is guaranteed to only add dependencies on source 263*333d2b36SAndroid Build Coastguard Worker// modules. 264*333d2b36SAndroid Build Coastguard Workerfunc (system *systemModulesImport) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { 265*333d2b36SAndroid Build Coastguard Worker for _, lib := range system.properties.Libs { 266*333d2b36SAndroid Build Coastguard Worker ctx.AddVariationDependencies(nil, systemModulesLibsTag, android.PrebuiltNameFromSource(lib)) 267*333d2b36SAndroid Build Coastguard Worker } 268*333d2b36SAndroid Build Coastguard Worker} 269*333d2b36SAndroid Build Coastguard Worker 270*333d2b36SAndroid Build Coastguard Workertype systemModulesSdkMemberType struct { 271*333d2b36SAndroid Build Coastguard Worker android.SdkMemberTypeBase 272*333d2b36SAndroid Build Coastguard Worker} 273*333d2b36SAndroid Build Coastguard Worker 274*333d2b36SAndroid Build Coastguard Workerfunc (mt *systemModulesSdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { 275*333d2b36SAndroid Build Coastguard Worker ctx.AddVariationDependencies(nil, dependencyTag, names...) 276*333d2b36SAndroid Build Coastguard Worker} 277*333d2b36SAndroid Build Coastguard Worker 278*333d2b36SAndroid Build Coastguard Workerfunc (mt *systemModulesSdkMemberType) IsInstance(module android.Module) bool { 279*333d2b36SAndroid Build Coastguard Worker if _, ok := module.(*SystemModules); ok { 280*333d2b36SAndroid Build Coastguard Worker // A prebuilt system module cannot be added as a member of an sdk because the source and 281*333d2b36SAndroid Build Coastguard Worker // snapshot instances would conflict. 282*333d2b36SAndroid Build Coastguard Worker _, ok := module.(*systemModulesImport) 283*333d2b36SAndroid Build Coastguard Worker return !ok 284*333d2b36SAndroid Build Coastguard Worker } 285*333d2b36SAndroid Build Coastguard Worker return false 286*333d2b36SAndroid Build Coastguard Worker} 287*333d2b36SAndroid Build Coastguard Worker 288*333d2b36SAndroid Build Coastguard Workerfunc (mt *systemModulesSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { 289*333d2b36SAndroid Build Coastguard Worker return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_system_modules_import") 290*333d2b36SAndroid Build Coastguard Worker} 291*333d2b36SAndroid Build Coastguard Worker 292*333d2b36SAndroid Build Coastguard Workertype systemModulesInfoProperties struct { 293*333d2b36SAndroid Build Coastguard Worker android.SdkMemberPropertiesBase 294*333d2b36SAndroid Build Coastguard Worker 295*333d2b36SAndroid Build Coastguard Worker Libs []string 296*333d2b36SAndroid Build Coastguard Worker} 297*333d2b36SAndroid Build Coastguard Worker 298*333d2b36SAndroid Build Coastguard Workerfunc (mt *systemModulesSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { 299*333d2b36SAndroid Build Coastguard Worker return &systemModulesInfoProperties{} 300*333d2b36SAndroid Build Coastguard Worker} 301*333d2b36SAndroid Build Coastguard Worker 302*333d2b36SAndroid Build Coastguard Workerfunc (p *systemModulesInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { 303*333d2b36SAndroid Build Coastguard Worker systemModule := variant.(*SystemModules) 304*333d2b36SAndroid Build Coastguard Worker p.Libs = systemModule.properties.Libs 305*333d2b36SAndroid Build Coastguard Worker} 306*333d2b36SAndroid Build Coastguard Worker 307*333d2b36SAndroid Build Coastguard Workerfunc (p *systemModulesInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { 308*333d2b36SAndroid Build Coastguard Worker if len(p.Libs) > 0 { 309*333d2b36SAndroid Build Coastguard Worker // Add the references to the libraries that form the system module. 310*333d2b36SAndroid Build Coastguard Worker propertySet.AddPropertyWithTag("libs", p.Libs, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(true)) 311*333d2b36SAndroid Build Coastguard Worker } 312*333d2b36SAndroid Build Coastguard Worker} 313*333d2b36SAndroid Build Coastguard Worker 314*333d2b36SAndroid Build Coastguard Worker// implement the following interface for IDE completion. 315*333d2b36SAndroid Build Coastguard Workervar _ android.IDEInfo = (*SystemModules)(nil) 316*333d2b36SAndroid Build Coastguard Worker 317*333d2b36SAndroid Build Coastguard Workerfunc (s *SystemModules) IDEInfo(ctx android.BaseModuleContext, ideInfo *android.IdeInfo) { 318*333d2b36SAndroid Build Coastguard Worker ideInfo.Deps = append(ideInfo.Deps, s.properties.Libs...) 319*333d2b36SAndroid Build Coastguard Worker ideInfo.Libs = append(ideInfo.Libs, s.properties.Libs...) 320*333d2b36SAndroid Build Coastguard Worker} 321