Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 1 | // Copyright 2018 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package xsdc |
| 16 | |
| 17 | import ( |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame^] | 18 | "strings" |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 19 | |
| 20 | "github.com/google/blueprint" |
| 21 | "github.com/google/blueprint/proptools" |
| 22 | |
| 23 | "android/soong/android" |
| 24 | "android/soong/java" |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame^] | 25 | "path/filepath" |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | func init() { |
| 29 | pctx.Import("android/soong/java/config") |
| 30 | android.RegisterModuleType("xsd_config", xsdConfigFactory) |
| 31 | |
| 32 | android.PreArchMutators(func(ctx android.RegisterMutatorsContext) { |
| 33 | ctx.TopDown("xsd_config", xsdConfigMutator).Parallel() |
| 34 | }) |
| 35 | } |
| 36 | |
| 37 | var ( |
| 38 | pctx = android.NewPackageContext("android/xsdc") |
| 39 | |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame^] | 40 | xsdc = pctx.HostBinToolVariable("xsdcCmd", "xsdc") |
| 41 | xsdcJavaRule = pctx.StaticRule("xsdcJavaRule", blueprint.RuleParams{ |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 42 | Command: `rm -rf "${out}.temp" && mkdir -p "${out}.temp" && ` + |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame^] | 43 | `${xsdcCmd} $in -p $pkgName -o ${out}.temp -j && ` + |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 44 | `${config.SoongZipCmd} -jar -o ${out} -C ${out}.temp -D ${out}.temp && ` + |
| 45 | `rm -rf ${out}.temp`, |
| 46 | Depfile: "${out}.d", |
| 47 | Deps: blueprint.DepsGCC, |
| 48 | CommandDeps: []string{"${xsdcCmd}", "${config.SoongZipCmd}"}, |
| 49 | Description: "xsdc Java ${in} => ${out}", |
| 50 | }, "pkgName") |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame^] | 51 | |
| 52 | xsdcCppRule = pctx.StaticRule("xsdcCppRule", blueprint.RuleParams{ |
| 53 | Command: `rm -rf "${outDir}" && ` + |
| 54 | `${xsdcCmd} $in -p $pkgName -o ${outDir} -c`, |
| 55 | Depfile: "${out}.d", |
| 56 | Deps: blueprint.DepsGCC, |
| 57 | CommandDeps: []string{"${xsdcCmd}", "${config.SoongZipCmd}"}, |
| 58 | Description: "xsdc Java ${in} => ${out}", |
| 59 | }, "pkgName", "outDir") |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 60 | ) |
| 61 | |
| 62 | type xsdConfigProperties struct { |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame^] | 63 | Srcs []string |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 64 | Package_name *string |
| 65 | } |
| 66 | |
| 67 | type xsdConfig struct { |
| 68 | android.ModuleBase |
| 69 | |
| 70 | properties xsdConfigProperties |
| 71 | |
| 72 | genOutputDir android.Path |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame^] | 73 | genOutputs_j android.WritablePath |
| 74 | genOutputs_c android.WritablePath |
| 75 | genOutputs_h android.WritablePath |
| 76 | |
| 77 | docsPath android.Path |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | type ApiToCheck struct { |
| 81 | Api_file *string |
| 82 | Removed_api_file *string |
| 83 | Args *string |
| 84 | } |
| 85 | |
| 86 | type CheckApi struct { |
| 87 | Last_released ApiToCheck |
| 88 | Current ApiToCheck |
| 89 | } |
| 90 | type DroidstubsProperties struct { |
| 91 | Name *string |
| 92 | No_framework_libs *bool |
| 93 | Installable *bool |
| 94 | Srcs []string |
| 95 | Args *string |
| 96 | Api_filename *string |
| 97 | Removed_api_filename *string |
| 98 | Check_api CheckApi |
| 99 | } |
| 100 | |
| 101 | func (module *xsdConfig) GeneratedSourceFiles() android.Paths { |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame^] | 102 | return android.Paths{module.genOutputs_c} |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | func (module *xsdConfig) Srcs() android.Paths { |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame^] | 106 | return android.Paths{module.genOutputs_j} |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | func (module *xsdConfig) GeneratedDeps() android.Paths { |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame^] | 110 | return android.Paths{module.genOutputs_h} |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | func (module *xsdConfig) GeneratedHeaderDirs() android.Paths { |
| 114 | return android.Paths{module.genOutputDir} |
| 115 | } |
| 116 | |
| 117 | func (module *xsdConfig) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 118 | // no need to implement |
| 119 | } |
| 120 | |
| 121 | func (module *xsdConfig) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 122 | if len(module.properties.Srcs) != 1 { |
| 123 | ctx.PropertyErrorf("srcs", "xsd_config must be one src") |
| 124 | } |
| 125 | |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame^] | 126 | ctx.VisitDirectDeps(func(to android.Module) { |
| 127 | if doc, ok := to.(java.ApiFilePath); ok { |
| 128 | module.docsPath = doc.ApiFilePath() |
| 129 | } |
| 130 | }) |
| 131 | |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 132 | xsdFile := module.properties.Srcs[0] |
| 133 | pkgName := *module.properties.Package_name |
| 134 | |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame^] | 135 | module.genOutputs_j = android.PathForModuleGen(ctx, "xsdcgen.srcjar") |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 136 | |
| 137 | ctx.Build(pctx, android.BuildParams{ |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame^] | 138 | Rule: xsdcJavaRule, |
| 139 | Description: "xsdc " + xsdFile, |
| 140 | Input: android.PathForModuleSrc(ctx, xsdFile), |
| 141 | Implicit: module.docsPath, |
| 142 | Output: module.genOutputs_j, |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 143 | Args: map[string]string{ |
| 144 | "pkgName": pkgName, |
| 145 | }, |
| 146 | }) |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame^] | 147 | |
| 148 | pkgName = strings.Replace(pkgName, ".", "_", -1) |
| 149 | module.genOutputs_c = android.PathForModuleGen(ctx, pkgName+".cpp") |
| 150 | module.genOutputs_h = android.PathForModuleGen(ctx, "include/"+pkgName+".h") |
| 151 | module.genOutputDir = android.PathForModuleGen(ctx, "include") |
| 152 | |
| 153 | ctx.Build(pctx, android.BuildParams{ |
| 154 | Rule: xsdcCppRule, |
| 155 | Description: "xsdc " + xsdFile, |
| 156 | Input: android.PathForModuleSrc(ctx, xsdFile), |
| 157 | Implicit: module.docsPath, |
| 158 | Output: module.genOutputs_c, |
| 159 | ImplicitOutput: module.genOutputs_h, |
| 160 | Args: map[string]string{ |
| 161 | "pkgName": pkgName, |
| 162 | "outDir": android.PathForModuleGen(ctx, "").String(), |
| 163 | }, |
| 164 | }) |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | func xsdConfigMutator(mctx android.TopDownMutatorContext) { |
| 168 | if module, ok := mctx.Module().(*xsdConfig); ok { |
| 169 | name := module.BaseModuleName() |
| 170 | |
| 171 | args := " --stub-packages " + *module.properties.Package_name + |
| 172 | " --hide MissingPermission --hide BroadcastBehavior" + |
| 173 | " --hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol" + |
| 174 | " --hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo" |
| 175 | |
| 176 | currentApiFileName := filepath.Join("api", "current.txt") |
| 177 | removedApiFileName := filepath.Join("api", "removed.txt") |
| 178 | |
| 179 | check_api := CheckApi{} |
| 180 | |
| 181 | check_api.Current.Api_file = proptools.StringPtr(currentApiFileName) |
| 182 | check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName) |
| 183 | |
| 184 | check_api.Last_released.Api_file = proptools.StringPtr( |
| 185 | filepath.Join("api", "last_current.txt")) |
| 186 | check_api.Last_released.Removed_api_file = proptools.StringPtr( |
| 187 | filepath.Join("api", "last_removed.txt")) |
| 188 | |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 189 | mctx.CreateModule(android.ModuleFactoryAdaptor(java.DroidstubsFactory), &DroidstubsProperties{ |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame^] | 190 | Name: proptools.StringPtr(name + ".docs"), |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 191 | Srcs: []string{":" + name}, |
| 192 | Args: proptools.StringPtr(args), |
| 193 | Api_filename: proptools.StringPtr(currentApiFileName), |
| 194 | Removed_api_filename: proptools.StringPtr(removedApiFileName), |
| 195 | Check_api: check_api, |
| 196 | Installable: proptools.BoolPtr(false), |
| 197 | No_framework_libs: proptools.BoolPtr(true), |
| 198 | }) |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | func xsdConfigFactory() android.Module { |
| 203 | module := &xsdConfig{} |
| 204 | module.AddProperties(&module.properties) |
| 205 | android.InitAndroidModule(module) |
| 206 | |
| 207 | return module |
| 208 | } |