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 | 851ddf0 | 2018-10-31 21:42:10 +0900 | [diff] [blame] | 18 | "android/soong/android" |
| 19 | "android/soong/java" |
| 20 | "path/filepath" |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame] | 21 | "strings" |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 22 | |
| 23 | "github.com/google/blueprint" |
| 24 | "github.com/google/blueprint/proptools" |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 25 | ) |
| 26 | |
| 27 | func init() { |
| 28 | pctx.Import("android/soong/java/config") |
| 29 | android.RegisterModuleType("xsd_config", xsdConfigFactory) |
| 30 | |
| 31 | android.PreArchMutators(func(ctx android.RegisterMutatorsContext) { |
| 32 | ctx.TopDown("xsd_config", xsdConfigMutator).Parallel() |
| 33 | }) |
| 34 | } |
| 35 | |
| 36 | var ( |
| 37 | pctx = android.NewPackageContext("android/xsdc") |
| 38 | |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame] | 39 | xsdc = pctx.HostBinToolVariable("xsdcCmd", "xsdc") |
| 40 | xsdcJavaRule = pctx.StaticRule("xsdcJavaRule", blueprint.RuleParams{ |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 41 | Command: `rm -rf "${out}.temp" && mkdir -p "${out}.temp" && ` + |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame] | 42 | `${xsdcCmd} $in -p $pkgName -o ${out}.temp -j && ` + |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 43 | `${config.SoongZipCmd} -jar -o ${out} -C ${out}.temp -D ${out}.temp && ` + |
| 44 | `rm -rf ${out}.temp`, |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 45 | CommandDeps: []string{"${xsdcCmd}", "${config.SoongZipCmd}"}, |
| 46 | Description: "xsdc Java ${in} => ${out}", |
| 47 | }, "pkgName") |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame] | 48 | |
| 49 | xsdcCppRule = pctx.StaticRule("xsdcCppRule", blueprint.RuleParams{ |
| 50 | Command: `rm -rf "${outDir}" && ` + |
| 51 | `${xsdcCmd} $in -p $pkgName -o ${outDir} -c`, |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame] | 52 | CommandDeps: []string{"${xsdcCmd}", "${config.SoongZipCmd}"}, |
Yifan Hong | 70080b7 | 2019-02-01 12:10:06 -0800 | [diff] [blame^] | 53 | Description: "xsdc C++ ${in} => ${out}", |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame] | 54 | }, "pkgName", "outDir") |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 55 | ) |
| 56 | |
| 57 | type xsdConfigProperties struct { |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame] | 58 | Srcs []string |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 59 | Package_name *string |
| 60 | } |
| 61 | |
| 62 | type xsdConfig struct { |
| 63 | android.ModuleBase |
| 64 | |
| 65 | properties xsdConfigProperties |
| 66 | |
| 67 | genOutputDir android.Path |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame] | 68 | genOutputs_j android.WritablePath |
| 69 | genOutputs_c android.WritablePath |
| 70 | genOutputs_h android.WritablePath |
| 71 | |
| 72 | docsPath android.Path |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | type ApiToCheck struct { |
| 76 | Api_file *string |
| 77 | Removed_api_file *string |
| 78 | Args *string |
| 79 | } |
| 80 | |
| 81 | type CheckApi struct { |
| 82 | Last_released ApiToCheck |
| 83 | Current ApiToCheck |
| 84 | } |
| 85 | type DroidstubsProperties struct { |
| 86 | Name *string |
| 87 | No_framework_libs *bool |
| 88 | Installable *bool |
| 89 | Srcs []string |
| 90 | Args *string |
| 91 | Api_filename *string |
| 92 | Removed_api_filename *string |
| 93 | Check_api CheckApi |
| 94 | } |
| 95 | |
| 96 | func (module *xsdConfig) GeneratedSourceFiles() android.Paths { |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame] | 97 | return android.Paths{module.genOutputs_c} |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | func (module *xsdConfig) Srcs() android.Paths { |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame] | 101 | return android.Paths{module.genOutputs_j} |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | func (module *xsdConfig) GeneratedDeps() android.Paths { |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame] | 105 | return android.Paths{module.genOutputs_h} |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | func (module *xsdConfig) GeneratedHeaderDirs() android.Paths { |
| 109 | return android.Paths{module.genOutputDir} |
| 110 | } |
| 111 | |
| 112 | func (module *xsdConfig) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 113 | // no need to implement |
| 114 | } |
| 115 | |
| 116 | func (module *xsdConfig) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 117 | if len(module.properties.Srcs) != 1 { |
| 118 | ctx.PropertyErrorf("srcs", "xsd_config must be one src") |
| 119 | } |
| 120 | |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame] | 121 | ctx.VisitDirectDeps(func(to android.Module) { |
| 122 | if doc, ok := to.(java.ApiFilePath); ok { |
| 123 | module.docsPath = doc.ApiFilePath() |
| 124 | } |
| 125 | }) |
| 126 | |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 127 | xsdFile := module.properties.Srcs[0] |
| 128 | pkgName := *module.properties.Package_name |
| 129 | |
Sundong Ahn | 851ddf0 | 2018-10-31 21:42:10 +0900 | [diff] [blame] | 130 | module.genOutputs_j = android.PathForModuleGen(ctx, "java", "xsdcgen.srcjar") |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 131 | |
| 132 | ctx.Build(pctx, android.BuildParams{ |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame] | 133 | Rule: xsdcJavaRule, |
| 134 | Description: "xsdc " + xsdFile, |
| 135 | Input: android.PathForModuleSrc(ctx, xsdFile), |
| 136 | Implicit: module.docsPath, |
| 137 | Output: module.genOutputs_j, |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 138 | Args: map[string]string{ |
| 139 | "pkgName": pkgName, |
| 140 | }, |
| 141 | }) |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame] | 142 | |
| 143 | pkgName = strings.Replace(pkgName, ".", "_", -1) |
Sundong Ahn | 851ddf0 | 2018-10-31 21:42:10 +0900 | [diff] [blame] | 144 | module.genOutputs_c = android.PathForModuleGen(ctx, "cpp", pkgName+".cpp") |
| 145 | module.genOutputs_h = android.PathForModuleGen(ctx, "cpp", "include/"+pkgName+".h") |
| 146 | module.genOutputDir = android.PathForModuleGen(ctx, "cpp", "include") |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame] | 147 | |
| 148 | ctx.Build(pctx, android.BuildParams{ |
| 149 | Rule: xsdcCppRule, |
| 150 | Description: "xsdc " + xsdFile, |
| 151 | Input: android.PathForModuleSrc(ctx, xsdFile), |
| 152 | Implicit: module.docsPath, |
| 153 | Output: module.genOutputs_c, |
| 154 | ImplicitOutput: module.genOutputs_h, |
| 155 | Args: map[string]string{ |
| 156 | "pkgName": pkgName, |
Sundong Ahn | 851ddf0 | 2018-10-31 21:42:10 +0900 | [diff] [blame] | 157 | "outDir": android.PathForModuleGen(ctx, "cpp").String(), |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame] | 158 | }, |
| 159 | }) |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | func xsdConfigMutator(mctx android.TopDownMutatorContext) { |
| 163 | if module, ok := mctx.Module().(*xsdConfig); ok { |
| 164 | name := module.BaseModuleName() |
| 165 | |
| 166 | args := " --stub-packages " + *module.properties.Package_name + |
| 167 | " --hide MissingPermission --hide BroadcastBehavior" + |
| 168 | " --hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol" + |
| 169 | " --hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo" |
| 170 | |
| 171 | currentApiFileName := filepath.Join("api", "current.txt") |
| 172 | removedApiFileName := filepath.Join("api", "removed.txt") |
| 173 | |
| 174 | check_api := CheckApi{} |
| 175 | |
| 176 | check_api.Current.Api_file = proptools.StringPtr(currentApiFileName) |
| 177 | check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName) |
| 178 | |
| 179 | check_api.Last_released.Api_file = proptools.StringPtr( |
| 180 | filepath.Join("api", "last_current.txt")) |
| 181 | check_api.Last_released.Removed_api_file = proptools.StringPtr( |
| 182 | filepath.Join("api", "last_removed.txt")) |
| 183 | |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 184 | mctx.CreateModule(android.ModuleFactoryAdaptor(java.DroidstubsFactory), &DroidstubsProperties{ |
Sundong Ahn | f3eb83e | 2018-10-12 12:12:10 +0900 | [diff] [blame] | 185 | Name: proptools.StringPtr(name + ".docs"), |
Sundong Ahn | e1fe320 | 2018-10-05 18:21:15 +0900 | [diff] [blame] | 186 | Srcs: []string{":" + name}, |
| 187 | Args: proptools.StringPtr(args), |
| 188 | Api_filename: proptools.StringPtr(currentApiFileName), |
| 189 | Removed_api_filename: proptools.StringPtr(removedApiFileName), |
| 190 | Check_api: check_api, |
| 191 | Installable: proptools.BoolPtr(false), |
| 192 | No_framework_libs: proptools.BoolPtr(true), |
| 193 | }) |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | func xsdConfigFactory() android.Module { |
| 198 | module := &xsdConfig{} |
| 199 | module.AddProperties(&module.properties) |
| 200 | android.InitAndroidModule(module) |
| 201 | |
| 202 | return module |
| 203 | } |