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 ( |
| 18 | "path/filepath" |
| 19 | |
| 20 | "github.com/google/blueprint" |
| 21 | "github.com/google/blueprint/proptools" |
| 22 | |
| 23 | "android/soong/android" |
| 24 | "android/soong/java" |
| 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 | |
| 39 | xsdc = pctx.HostBinToolVariable("xsdcCmd", "xsdc") |
| 40 | xsdcRule = pctx.StaticRule("xsdcRule", blueprint.RuleParams{ |
| 41 | Command: `rm -rf "${out}.temp" && mkdir -p "${out}.temp" && ` + |
| 42 | `${xsdcCmd} $in $pkgName ${out}.temp && ` + |
| 43 | `${config.SoongZipCmd} -jar -o ${out} -C ${out}.temp -D ${out}.temp && ` + |
| 44 | `rm -rf ${out}.temp`, |
| 45 | Depfile: "${out}.d", |
| 46 | Deps: blueprint.DepsGCC, |
| 47 | CommandDeps: []string{"${xsdcCmd}", "${config.SoongZipCmd}"}, |
| 48 | Description: "xsdc Java ${in} => ${out}", |
| 49 | }, "pkgName") |
| 50 | ) |
| 51 | |
| 52 | type xsdConfigProperties struct { |
| 53 | Srcs []string |
| 54 | Package_name *string |
| 55 | } |
| 56 | |
| 57 | type xsdConfig struct { |
| 58 | android.ModuleBase |
| 59 | |
| 60 | properties xsdConfigProperties |
| 61 | |
| 62 | genOutputDir android.Path |
| 63 | genOutputs_j android.WritablePaths |
| 64 | genOutputs_c android.WritablePaths |
| 65 | genOutputs_h android.WritablePaths |
| 66 | } |
| 67 | |
| 68 | type ApiToCheck struct { |
| 69 | Api_file *string |
| 70 | Removed_api_file *string |
| 71 | Args *string |
| 72 | } |
| 73 | |
| 74 | type CheckApi struct { |
| 75 | Last_released ApiToCheck |
| 76 | Current ApiToCheck |
| 77 | } |
| 78 | type DroidstubsProperties struct { |
| 79 | Name *string |
| 80 | No_framework_libs *bool |
| 81 | Installable *bool |
| 82 | Srcs []string |
| 83 | Args *string |
| 84 | Api_filename *string |
| 85 | Removed_api_filename *string |
| 86 | Check_api CheckApi |
| 87 | } |
| 88 | |
| 89 | func (module *xsdConfig) GeneratedSourceFiles() android.Paths { |
| 90 | return module.genOutputs_c.Paths() |
| 91 | } |
| 92 | |
| 93 | func (module *xsdConfig) Srcs() android.Paths { |
| 94 | return module.genOutputs_j.Paths() |
| 95 | } |
| 96 | |
| 97 | func (module *xsdConfig) GeneratedDeps() android.Paths { |
| 98 | return module.genOutputs_h.Paths() |
| 99 | } |
| 100 | |
| 101 | func (module *xsdConfig) GeneratedHeaderDirs() android.Paths { |
| 102 | return android.Paths{module.genOutputDir} |
| 103 | } |
| 104 | |
| 105 | func (module *xsdConfig) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 106 | // no need to implement |
| 107 | } |
| 108 | |
| 109 | func (module *xsdConfig) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 110 | if len(module.properties.Srcs) != 1 { |
| 111 | ctx.PropertyErrorf("srcs", "xsd_config must be one src") |
| 112 | } |
| 113 | |
| 114 | xsdFile := module.properties.Srcs[0] |
| 115 | pkgName := *module.properties.Package_name |
| 116 | |
| 117 | module.genOutputs_j = append(module.genOutputs_j, android.PathForModuleGen(ctx, "xsdcgen.srcjar")) |
| 118 | |
| 119 | ctx.Build(pctx, android.BuildParams{ |
| 120 | Rule: xsdcRule, |
| 121 | Description: "xsdc " + xsdFile, |
| 122 | Input: android.PathForModuleSrc(ctx, xsdFile), |
| 123 | Output: module.genOutputs_j[0], |
| 124 | Args: map[string]string{ |
| 125 | "pkgName": pkgName, |
| 126 | }, |
| 127 | }) |
| 128 | } |
| 129 | |
| 130 | func xsdConfigMutator(mctx android.TopDownMutatorContext) { |
| 131 | if module, ok := mctx.Module().(*xsdConfig); ok { |
| 132 | name := module.BaseModuleName() |
| 133 | |
| 134 | args := " --stub-packages " + *module.properties.Package_name + |
| 135 | " --hide MissingPermission --hide BroadcastBehavior" + |
| 136 | " --hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol" + |
| 137 | " --hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo" |
| 138 | |
| 139 | currentApiFileName := filepath.Join("api", "current.txt") |
| 140 | removedApiFileName := filepath.Join("api", "removed.txt") |
| 141 | |
| 142 | check_api := CheckApi{} |
| 143 | |
| 144 | check_api.Current.Api_file = proptools.StringPtr(currentApiFileName) |
| 145 | check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName) |
| 146 | |
| 147 | check_api.Last_released.Api_file = proptools.StringPtr( |
| 148 | filepath.Join("api", "last_current.txt")) |
| 149 | check_api.Last_released.Removed_api_file = proptools.StringPtr( |
| 150 | filepath.Join("api", "last_removed.txt")) |
| 151 | |
| 152 | |
| 153 | mctx.CreateModule(android.ModuleFactoryAdaptor(java.DroidstubsFactory), &DroidstubsProperties{ |
| 154 | Name: proptools.StringPtr(name + "-docs"), |
| 155 | Srcs: []string{":" + name}, |
| 156 | Args: proptools.StringPtr(args), |
| 157 | Api_filename: proptools.StringPtr(currentApiFileName), |
| 158 | Removed_api_filename: proptools.StringPtr(removedApiFileName), |
| 159 | Check_api: check_api, |
| 160 | Installable: proptools.BoolPtr(false), |
| 161 | No_framework_libs: proptools.BoolPtr(true), |
| 162 | }) |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | func xsdConfigFactory() android.Module { |
| 167 | module := &xsdConfig{} |
| 168 | module.AddProperties(&module.properties) |
| 169 | android.InitAndroidModule(module) |
| 170 | |
| 171 | return module |
| 172 | } |
| 173 | |