blob: 957497f3a43bd7f6b80b1e626e40e054004535e6 [file] [log] [blame]
Sundong Ahne1fe3202018-10-05 18:21:15 +09001// 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
15package xsdc
16
17import (
Sundong Ahn851ddf02018-10-31 21:42:10 +090018 "android/soong/android"
19 "android/soong/java"
20 "path/filepath"
Sundong Ahnf3eb83e2018-10-12 12:12:10 +090021 "strings"
Sundong Ahne1fe3202018-10-05 18:21:15 +090022
23 "github.com/google/blueprint"
24 "github.com/google/blueprint/proptools"
Sundong Ahne1fe3202018-10-05 18:21:15 +090025)
26
27func 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
36var (
37 pctx = android.NewPackageContext("android/xsdc")
38
Sundong Ahnf3eb83e2018-10-12 12:12:10 +090039 xsdc = pctx.HostBinToolVariable("xsdcCmd", "xsdc")
40 xsdcJavaRule = pctx.StaticRule("xsdcJavaRule", blueprint.RuleParams{
Sundong Ahne1fe3202018-10-05 18:21:15 +090041 Command: `rm -rf "${out}.temp" && mkdir -p "${out}.temp" && ` +
Sundong Ahnf3eb83e2018-10-12 12:12:10 +090042 `${xsdcCmd} $in -p $pkgName -o ${out}.temp -j && ` +
Sundong Ahne1fe3202018-10-05 18:21:15 +090043 `${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")
Sundong Ahnf3eb83e2018-10-12 12:12:10 +090050
51 xsdcCppRule = pctx.StaticRule("xsdcCppRule", blueprint.RuleParams{
52 Command: `rm -rf "${outDir}" && ` +
53 `${xsdcCmd} $in -p $pkgName -o ${outDir} -c`,
54 Depfile: "${out}.d",
55 Deps: blueprint.DepsGCC,
56 CommandDeps: []string{"${xsdcCmd}", "${config.SoongZipCmd}"},
57 Description: "xsdc Java ${in} => ${out}",
58 }, "pkgName", "outDir")
Sundong Ahne1fe3202018-10-05 18:21:15 +090059)
60
61type xsdConfigProperties struct {
Sundong Ahnf3eb83e2018-10-12 12:12:10 +090062 Srcs []string
Sundong Ahne1fe3202018-10-05 18:21:15 +090063 Package_name *string
64}
65
66type xsdConfig struct {
67 android.ModuleBase
68
69 properties xsdConfigProperties
70
71 genOutputDir android.Path
Sundong Ahnf3eb83e2018-10-12 12:12:10 +090072 genOutputs_j android.WritablePath
73 genOutputs_c android.WritablePath
74 genOutputs_h android.WritablePath
75
76 docsPath android.Path
Sundong Ahne1fe3202018-10-05 18:21:15 +090077}
78
79type ApiToCheck struct {
80 Api_file *string
81 Removed_api_file *string
82 Args *string
83}
84
85type CheckApi struct {
86 Last_released ApiToCheck
87 Current ApiToCheck
88}
89type DroidstubsProperties struct {
90 Name *string
91 No_framework_libs *bool
92 Installable *bool
93 Srcs []string
94 Args *string
95 Api_filename *string
96 Removed_api_filename *string
97 Check_api CheckApi
98}
99
100func (module *xsdConfig) GeneratedSourceFiles() android.Paths {
Sundong Ahnf3eb83e2018-10-12 12:12:10 +0900101 return android.Paths{module.genOutputs_c}
Sundong Ahne1fe3202018-10-05 18:21:15 +0900102}
103
104func (module *xsdConfig) Srcs() android.Paths {
Sundong Ahnf3eb83e2018-10-12 12:12:10 +0900105 return android.Paths{module.genOutputs_j}
Sundong Ahne1fe3202018-10-05 18:21:15 +0900106}
107
108func (module *xsdConfig) GeneratedDeps() android.Paths {
Sundong Ahnf3eb83e2018-10-12 12:12:10 +0900109 return android.Paths{module.genOutputs_h}
Sundong Ahne1fe3202018-10-05 18:21:15 +0900110}
111
112func (module *xsdConfig) GeneratedHeaderDirs() android.Paths {
113 return android.Paths{module.genOutputDir}
114}
115
116func (module *xsdConfig) DepsMutator(ctx android.BottomUpMutatorContext) {
117 // no need to implement
118}
119
120func (module *xsdConfig) GenerateAndroidBuildActions(ctx android.ModuleContext) {
121 if len(module.properties.Srcs) != 1 {
122 ctx.PropertyErrorf("srcs", "xsd_config must be one src")
123 }
124
Sundong Ahnf3eb83e2018-10-12 12:12:10 +0900125 ctx.VisitDirectDeps(func(to android.Module) {
126 if doc, ok := to.(java.ApiFilePath); ok {
127 module.docsPath = doc.ApiFilePath()
128 }
129 })
130
Sundong Ahne1fe3202018-10-05 18:21:15 +0900131 xsdFile := module.properties.Srcs[0]
132 pkgName := *module.properties.Package_name
133
Sundong Ahn851ddf02018-10-31 21:42:10 +0900134 module.genOutputs_j = android.PathForModuleGen(ctx, "java", "xsdcgen.srcjar")
Sundong Ahne1fe3202018-10-05 18:21:15 +0900135
136 ctx.Build(pctx, android.BuildParams{
Sundong Ahnf3eb83e2018-10-12 12:12:10 +0900137 Rule: xsdcJavaRule,
138 Description: "xsdc " + xsdFile,
139 Input: android.PathForModuleSrc(ctx, xsdFile),
140 Implicit: module.docsPath,
141 Output: module.genOutputs_j,
Sundong Ahne1fe3202018-10-05 18:21:15 +0900142 Args: map[string]string{
143 "pkgName": pkgName,
144 },
145 })
Sundong Ahnf3eb83e2018-10-12 12:12:10 +0900146
147 pkgName = strings.Replace(pkgName, ".", "_", -1)
Sundong Ahn851ddf02018-10-31 21:42:10 +0900148 module.genOutputs_c = android.PathForModuleGen(ctx, "cpp", pkgName+".cpp")
149 module.genOutputs_h = android.PathForModuleGen(ctx, "cpp", "include/"+pkgName+".h")
150 module.genOutputDir = android.PathForModuleGen(ctx, "cpp", "include")
Sundong Ahnf3eb83e2018-10-12 12:12:10 +0900151
152 ctx.Build(pctx, android.BuildParams{
153 Rule: xsdcCppRule,
154 Description: "xsdc " + xsdFile,
155 Input: android.PathForModuleSrc(ctx, xsdFile),
156 Implicit: module.docsPath,
157 Output: module.genOutputs_c,
158 ImplicitOutput: module.genOutputs_h,
159 Args: map[string]string{
160 "pkgName": pkgName,
Sundong Ahn851ddf02018-10-31 21:42:10 +0900161 "outDir": android.PathForModuleGen(ctx, "cpp").String(),
Sundong Ahnf3eb83e2018-10-12 12:12:10 +0900162 },
163 })
Sundong Ahne1fe3202018-10-05 18:21:15 +0900164}
165
166func xsdConfigMutator(mctx android.TopDownMutatorContext) {
167 if module, ok := mctx.Module().(*xsdConfig); ok {
168 name := module.BaseModuleName()
169
170 args := " --stub-packages " + *module.properties.Package_name +
171 " --hide MissingPermission --hide BroadcastBehavior" +
172 " --hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol" +
173 " --hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo"
174
175 currentApiFileName := filepath.Join("api", "current.txt")
176 removedApiFileName := filepath.Join("api", "removed.txt")
177
178 check_api := CheckApi{}
179
180 check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
181 check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
182
183 check_api.Last_released.Api_file = proptools.StringPtr(
184 filepath.Join("api", "last_current.txt"))
185 check_api.Last_released.Removed_api_file = proptools.StringPtr(
186 filepath.Join("api", "last_removed.txt"))
187
Sundong Ahne1fe3202018-10-05 18:21:15 +0900188 mctx.CreateModule(android.ModuleFactoryAdaptor(java.DroidstubsFactory), &DroidstubsProperties{
Sundong Ahnf3eb83e2018-10-12 12:12:10 +0900189 Name: proptools.StringPtr(name + ".docs"),
Sundong Ahne1fe3202018-10-05 18:21:15 +0900190 Srcs: []string{":" + name},
191 Args: proptools.StringPtr(args),
192 Api_filename: proptools.StringPtr(currentApiFileName),
193 Removed_api_filename: proptools.StringPtr(removedApiFileName),
194 Check_api: check_api,
195 Installable: proptools.BoolPtr(false),
196 No_framework_libs: proptools.BoolPtr(true),
197 })
198 }
199}
200
201func xsdConfigFactory() android.Module {
202 module := &xsdConfig{}
203 module.AddProperties(&module.properties)
204 android.InitAndroidModule(module)
205
206 return module
207}