Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 1 | // Copyright 2017 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 python |
| 16 | |
| 17 | // This file contains the "Base" module type for building Python program. |
| 18 | |
| 19 | import ( |
| 20 | "fmt" |
| 21 | "path/filepath" |
| 22 | "regexp" |
| 23 | "sort" |
| 24 | "strings" |
| 25 | |
| 26 | "github.com/google/blueprint" |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 27 | "github.com/google/blueprint/proptools" |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 28 | |
| 29 | "android/soong/android" |
| 30 | ) |
| 31 | |
| 32 | func init() { |
| 33 | android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 34 | ctx.BottomUp("version_split", versionSplitMutator()).Parallel() |
| 35 | }) |
| 36 | } |
| 37 | |
| 38 | // the version properties that apply to python libraries and binaries. |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 39 | type VersionProperties struct { |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 40 | // true, if the module is required to be built with this version. |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 41 | Enabled *bool `android:"arch_variant"` |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 42 | |
| 43 | // non-empty list of .py files under this strict Python version. |
| 44 | // srcs may reference the outputs of other modules that produce source files like genrule |
| 45 | // or filegroup using the syntax ":module". |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 46 | Srcs []string `android:"arch_variant"` |
| 47 | |
| 48 | // list of source files that should not be used to build the Python module. |
| 49 | // This is most useful in the arch/multilib variants to remove non-common files |
| 50 | Exclude_srcs []string `android:"arch_variant"` |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 51 | |
| 52 | // list of the Python libraries under this Python version. |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 53 | Libs []string `android:"arch_variant"` |
| 54 | |
| 55 | // true, if the binary is required to be built with embedded launcher. |
| 56 | // TODO(nanzhang): Remove this flag when embedded Python3 is supported later. |
| 57 | Embedded_launcher *bool `android:"arch_variant"` |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | // properties that apply to python libraries and binaries. |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 61 | type BaseProperties struct { |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 62 | // the package path prefix within the output artifact at which to place the source/data |
| 63 | // files of the current module. |
| 64 | // eg. Pkg_path = "a/b/c"; Other packages can reference this module by using |
| 65 | // (from a.b.c import ...) statement. |
| 66 | // if left unspecified, all the source/data files of current module are copied to |
| 67 | // "runfiles/" tree directory directly. |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 68 | Pkg_path *string `android:"arch_variant"` |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 69 | |
| 70 | // true, if the Python module is used internally, eg, Python std libs. |
| 71 | Is_internal *bool `android:"arch_variant"` |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 72 | |
| 73 | // list of source (.py) files compatible both with Python2 and Python3 used to compile the |
| 74 | // Python module. |
| 75 | // srcs may reference the outputs of other modules that produce source files like genrule |
| 76 | // or filegroup using the syntax ":module". |
| 77 | // Srcs has to be non-empty. |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 78 | Srcs []string `android:"arch_variant"` |
| 79 | |
| 80 | // list of source files that should not be used to build the C/C++ module. |
| 81 | // This is most useful in the arch/multilib variants to remove non-common files |
| 82 | Exclude_srcs []string `android:"arch_variant"` |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 83 | |
| 84 | // list of files or filegroup modules that provide data that should be installed alongside |
| 85 | // the test. the file extension can be arbitrary except for (.py). |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 86 | Data []string `android:"arch_variant"` |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 87 | |
| 88 | // list of the Python libraries compatible both with Python2 and Python3. |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 89 | Libs []string `android:"arch_variant"` |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 90 | |
| 91 | Version struct { |
| 92 | // all the "srcs" or Python dependencies that are to be used only for Python2. |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 93 | Py2 VersionProperties `android:"arch_variant"` |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 94 | |
| 95 | // all the "srcs" or Python dependencies that are to be used only for Python3. |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 96 | Py3 VersionProperties `android:"arch_variant"` |
| 97 | } `android:"arch_variant"` |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 98 | |
| 99 | // the actual version each module uses after variations created. |
| 100 | // this property name is hidden from users' perspectives, and soong will populate it during |
| 101 | // runtime. |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 102 | Actual_version string `blueprint:"mutated"` |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | type pathMapping struct { |
| 106 | dest string |
| 107 | src android.Path |
| 108 | } |
| 109 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 110 | type Module struct { |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 111 | android.ModuleBase |
Nan Zhang | a3fc4ba | 2017-07-20 17:43:37 -0700 | [diff] [blame] | 112 | android.DefaultableModuleBase |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 113 | |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 114 | properties BaseProperties |
| 115 | protoProperties android.ProtoProperties |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 116 | |
| 117 | // initialize before calling Init |
| 118 | hod android.HostOrDeviceSupported |
| 119 | multilib android.Multilib |
| 120 | |
| 121 | // the bootstrapper is used to bootstrap .par executable. |
| 122 | // bootstrapper might be nil (Python library module). |
| 123 | bootstrapper bootstrapper |
| 124 | |
| 125 | // the installer might be nil. |
| 126 | installer installer |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 127 | |
| 128 | // the Python files of current module after expanding source dependencies. |
| 129 | // pathMapping: <dest: runfile_path, src: source_path> |
| 130 | srcsPathMappings []pathMapping |
| 131 | |
| 132 | // the data files of current module after expanding source dependencies. |
| 133 | // pathMapping: <dest: runfile_path, src: source_path> |
| 134 | dataPathMappings []pathMapping |
| 135 | |
Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 136 | // the zip filepath for zipping current module source/data files. |
| 137 | srcsZip android.Path |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 138 | |
Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 139 | // dependency modules' zip filepath for zipping current module source/data files. |
| 140 | depsSrcsZips android.Paths |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 141 | |
| 142 | // (.intermediate) module output path as installation source. |
| 143 | installSource android.OptionalPath |
| 144 | |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 145 | subAndroidMkOnce map[subAndroidMkProvider]bool |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 146 | } |
| 147 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 148 | func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 149 | return &Module{ |
| 150 | hod: hod, |
| 151 | multilib: multilib, |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | type bootstrapper interface { |
| 156 | bootstrapperProps() []interface{} |
Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 157 | bootstrap(ctx android.ModuleContext, ActualVersion string, embeddedLauncher bool, |
| 158 | srcsPathMappings []pathMapping, srcsZip android.Path, |
| 159 | depsSrcsZips android.Paths) android.OptionalPath |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | type installer interface { |
| 163 | install(ctx android.ModuleContext, path android.Path) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | type PythonDependency interface { |
| 167 | GetSrcsPathMappings() []pathMapping |
| 168 | GetDataPathMappings() []pathMapping |
Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 169 | GetSrcsZip() android.Path |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 170 | } |
| 171 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 172 | func (p *Module) GetSrcsPathMappings() []pathMapping { |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 173 | return p.srcsPathMappings |
| 174 | } |
| 175 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 176 | func (p *Module) GetDataPathMappings() []pathMapping { |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 177 | return p.dataPathMappings |
| 178 | } |
| 179 | |
Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 180 | func (p *Module) GetSrcsZip() android.Path { |
| 181 | return p.srcsZip |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 182 | } |
| 183 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 184 | var _ PythonDependency = (*Module)(nil) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 185 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 186 | var _ android.AndroidMkDataProvider = (*Module)(nil) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 187 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 188 | func (p *Module) Init() android.Module { |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 189 | |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 190 | p.AddProperties(&p.properties, &p.protoProperties) |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 191 | if p.bootstrapper != nil { |
| 192 | p.AddProperties(p.bootstrapper.bootstrapperProps()...) |
| 193 | } |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 194 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 195 | android.InitAndroidArchModule(p, p.hod, p.multilib) |
Nan Zhang | a3fc4ba | 2017-07-20 17:43:37 -0700 | [diff] [blame] | 196 | android.InitDefaultableModule(p) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 197 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 198 | return p |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 199 | } |
| 200 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 201 | type dependencyTag struct { |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 202 | blueprint.BaseDependencyTag |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 203 | name string |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 204 | } |
| 205 | |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 206 | var ( |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 207 | pythonLibTag = dependencyTag{name: "pythonLib"} |
| 208 | launcherTag = dependencyTag{name: "launcher"} |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 209 | pyIdentifierRegexp = regexp.MustCompile(`^([a-z]|[A-Z]|_)([a-z]|[A-Z]|[0-9]|_)*$`) |
| 210 | pyExt = ".py" |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 211 | protoExt = ".proto" |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 212 | pyVersion2 = "PY2" |
| 213 | pyVersion3 = "PY3" |
| 214 | initFileName = "__init__.py" |
| 215 | mainFileName = "__main__.py" |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 216 | entryPointFile = "entry_point.txt" |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 217 | parFileExt = ".zip" |
| 218 | runFiles = "runfiles" |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 219 | internal = "internal" |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 220 | ) |
| 221 | |
| 222 | // create version variants for modules. |
| 223 | func versionSplitMutator() func(android.BottomUpMutatorContext) { |
| 224 | return func(mctx android.BottomUpMutatorContext) { |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 225 | if base, ok := mctx.Module().(*Module); ok { |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 226 | versionNames := []string{} |
| 227 | if base.properties.Version.Py2.Enabled != nil && |
| 228 | *(base.properties.Version.Py2.Enabled) == true { |
| 229 | versionNames = append(versionNames, pyVersion2) |
| 230 | } |
| 231 | if !(base.properties.Version.Py3.Enabled != nil && |
| 232 | *(base.properties.Version.Py3.Enabled) == false) { |
| 233 | versionNames = append(versionNames, pyVersion3) |
| 234 | } |
| 235 | modules := mctx.CreateVariations(versionNames...) |
| 236 | for i, v := range versionNames { |
| 237 | // set the actual version for Python module. |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 238 | modules[i].(*Module).properties.Actual_version = v |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
Nan Zhang | b8bdacf | 2017-12-06 15:13:10 -0800 | [diff] [blame] | 244 | func (p *Module) HostToolPath() android.OptionalPath { |
| 245 | if p.installer == nil { |
| 246 | // python_library is just meta module, and doesn't have any installer. |
| 247 | return android.OptionalPath{} |
| 248 | } |
| 249 | return android.OptionalPathForPath(p.installer.(*binaryDecorator).path) |
| 250 | } |
| 251 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 252 | func (p *Module) isEmbeddedLauncherEnabled(actual_version string) bool { |
| 253 | switch actual_version { |
| 254 | case pyVersion2: |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 255 | return Bool(p.properties.Version.Py2.Embedded_launcher) |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 256 | case pyVersion3: |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 257 | return Bool(p.properties.Version.Py3.Embedded_launcher) |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | return false |
| 261 | } |
| 262 | |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 263 | func hasSrcExt(srcs []string, ext string) bool { |
| 264 | for _, src := range srcs { |
| 265 | if filepath.Ext(src) == ext { |
| 266 | return true |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | return false |
| 271 | } |
| 272 | |
| 273 | func (p *Module) hasSrcExt(ctx android.BottomUpMutatorContext, ext string) bool { |
| 274 | if hasSrcExt(p.properties.Srcs, protoExt) { |
| 275 | return true |
| 276 | } |
| 277 | switch p.properties.Actual_version { |
| 278 | case pyVersion2: |
| 279 | return hasSrcExt(p.properties.Version.Py2.Srcs, protoExt) |
| 280 | case pyVersion3: |
| 281 | return hasSrcExt(p.properties.Version.Py3.Srcs, protoExt) |
| 282 | default: |
| 283 | panic(fmt.Errorf("unknown Python Actual_version: %q for module: %q.", |
| 284 | p.properties.Actual_version, ctx.ModuleName())) |
| 285 | } |
| 286 | } |
| 287 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 288 | func (p *Module) DepsMutator(ctx android.BottomUpMutatorContext) { |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 289 | // deps from "data". |
| 290 | android.ExtractSourcesDeps(ctx, p.properties.Data) |
| 291 | // deps from "srcs". |
| 292 | android.ExtractSourcesDeps(ctx, p.properties.Srcs) |
Nan Zhang | 27e284d | 2018-02-09 21:03:53 +0000 | [diff] [blame] | 293 | android.ExtractSourcesDeps(ctx, p.properties.Exclude_srcs) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 294 | |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 295 | if p.hasSrcExt(ctx, protoExt) && p.Name() != "libprotobuf-python" { |
| 296 | ctx.AddVariationDependencies(nil, pythonLibTag, "libprotobuf-python") |
| 297 | } |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 298 | switch p.properties.Actual_version { |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 299 | case pyVersion2: |
| 300 | // deps from "version.py2.srcs" property. |
| 301 | android.ExtractSourcesDeps(ctx, p.properties.Version.Py2.Srcs) |
Nan Zhang | 27e284d | 2018-02-09 21:03:53 +0000 | [diff] [blame] | 302 | android.ExtractSourcesDeps(ctx, p.properties.Version.Py2.Exclude_srcs) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 303 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 304 | ctx.AddVariationDependencies(nil, pythonLibTag, |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 305 | uniqueLibs(ctx, p.properties.Libs, "version.py2.libs", |
| 306 | p.properties.Version.Py2.Libs)...) |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 307 | |
| 308 | if p.bootstrapper != nil && p.isEmbeddedLauncherEnabled(pyVersion2) { |
| 309 | ctx.AddVariationDependencies(nil, pythonLibTag, "py2-stdlib") |
| 310 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 311 | {"arch", ctx.Target().String()}, |
| 312 | }, launcherTag, "py2-launcher") |
| 313 | } |
| 314 | |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 315 | case pyVersion3: |
| 316 | // deps from "version.py3.srcs" property. |
| 317 | android.ExtractSourcesDeps(ctx, p.properties.Version.Py3.Srcs) |
Nan Zhang | 27e284d | 2018-02-09 21:03:53 +0000 | [diff] [blame] | 318 | android.ExtractSourcesDeps(ctx, p.properties.Version.Py3.Exclude_srcs) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 319 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 320 | ctx.AddVariationDependencies(nil, pythonLibTag, |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 321 | uniqueLibs(ctx, p.properties.Libs, "version.py3.libs", |
| 322 | p.properties.Version.Py3.Libs)...) |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 323 | |
| 324 | if p.bootstrapper != nil && p.isEmbeddedLauncherEnabled(pyVersion3) { |
| 325 | //TODO(nanzhang): Add embedded launcher for Python3. |
| 326 | ctx.PropertyErrorf("version.py3.embedded_launcher", |
| 327 | "is not supported yet for Python3.") |
| 328 | } |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 329 | default: |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 330 | panic(fmt.Errorf("unknown Python Actual_version: %q for module: %q.", |
| 331 | p.properties.Actual_version, ctx.ModuleName())) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | |
| 335 | // check "libs" duplicates from current module dependencies. |
| 336 | func uniqueLibs(ctx android.BottomUpMutatorContext, |
| 337 | commonLibs []string, versionProp string, versionLibs []string) []string { |
| 338 | set := make(map[string]string) |
| 339 | ret := []string{} |
| 340 | |
| 341 | // deps from "libs" property. |
| 342 | for _, l := range commonLibs { |
| 343 | if _, found := set[l]; found { |
| 344 | ctx.PropertyErrorf("libs", "%q has duplicates within libs.", l) |
| 345 | } else { |
| 346 | set[l] = "libs" |
| 347 | ret = append(ret, l) |
| 348 | } |
| 349 | } |
| 350 | // deps from "version.pyX.libs" property. |
| 351 | for _, l := range versionLibs { |
| 352 | if _, found := set[l]; found { |
| 353 | ctx.PropertyErrorf(versionProp, "%q has duplicates within %q.", set[l]) |
| 354 | } else { |
| 355 | set[l] = versionProp |
| 356 | ret = append(ret, l) |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | return ret |
| 361 | } |
| 362 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 363 | func (p *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 364 | p.GeneratePythonBuildActions(ctx) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 365 | |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 366 | // Only Python binaries and test has non-empty bootstrapper. |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 367 | if p.bootstrapper != nil { |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 368 | p.walkTransitiveDeps(ctx) |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 369 | // TODO(nanzhang): Since embedded launcher is not supported for Python3 for now, |
| 370 | // so we initialize "embedded_launcher" to false. |
Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 371 | embeddedLauncher := false |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 372 | if p.properties.Actual_version == pyVersion2 { |
Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 373 | embeddedLauncher = p.isEmbeddedLauncherEnabled(pyVersion2) |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 374 | } |
| 375 | p.installSource = p.bootstrapper.bootstrap(ctx, p.properties.Actual_version, |
Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 376 | embeddedLauncher, p.srcsPathMappings, p.srcsZip, p.depsSrcsZips) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 377 | } |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 378 | |
| 379 | if p.installer != nil && p.installSource.Valid() { |
| 380 | p.installer.install(ctx, p.installSource.Path()) |
| 381 | } |
| 382 | |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 383 | } |
| 384 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 385 | func (p *Module) GeneratePythonBuildActions(ctx android.ModuleContext) { |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 386 | // expand python files from "srcs" property. |
| 387 | srcs := p.properties.Srcs |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 388 | exclude_srcs := p.properties.Exclude_srcs |
| 389 | switch p.properties.Actual_version { |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 390 | case pyVersion2: |
| 391 | srcs = append(srcs, p.properties.Version.Py2.Srcs...) |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 392 | exclude_srcs = append(exclude_srcs, p.properties.Version.Py2.Exclude_srcs...) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 393 | case pyVersion3: |
| 394 | srcs = append(srcs, p.properties.Version.Py3.Srcs...) |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 395 | exclude_srcs = append(exclude_srcs, p.properties.Version.Py3.Exclude_srcs...) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 396 | default: |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 397 | panic(fmt.Errorf("unknown Python Actual_version: %q for module: %q.", |
| 398 | p.properties.Actual_version, ctx.ModuleName())) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 399 | } |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 400 | expandedSrcs := ctx.ExpandSources(srcs, exclude_srcs) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 401 | if len(expandedSrcs) == 0 { |
| 402 | ctx.ModuleErrorf("doesn't have any source files!") |
| 403 | } |
| 404 | |
| 405 | // expand data files from "data" property. |
| 406 | expandedData := ctx.ExpandSources(p.properties.Data, nil) |
| 407 | |
| 408 | // sanitize pkg_path. |
Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 409 | pkgPath := String(p.properties.Pkg_path) |
| 410 | if pkgPath != "" { |
| 411 | pkgPath = filepath.Clean(String(p.properties.Pkg_path)) |
| 412 | if pkgPath == ".." || strings.HasPrefix(pkgPath, "../") || |
| 413 | strings.HasPrefix(pkgPath, "/") { |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 414 | ctx.PropertyErrorf("pkg_path", |
| 415 | "%q must be a relative path contained in par file.", |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 416 | String(p.properties.Pkg_path)) |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 417 | return |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 418 | } |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 419 | if p.properties.Is_internal != nil && *p.properties.Is_internal { |
| 420 | // pkg_path starts from "internal/" implicitly. |
Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 421 | pkgPath = filepath.Join(internal, pkgPath) |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 422 | } else { |
Nan Zhang | f0c4e43 | 2018-05-22 14:50:18 -0700 | [diff] [blame^] | 423 | if !p.isEmbeddedLauncherEnabled(p.properties.Actual_version) { |
| 424 | // pkg_path starts from "runfiles/" implicitly. |
| 425 | pkgPath = filepath.Join(runFiles, pkgPath) |
| 426 | } |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 427 | } |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 428 | } else { |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 429 | if p.properties.Is_internal != nil && *p.properties.Is_internal { |
| 430 | // pkg_path starts from "runfiles/" implicitly. |
Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 431 | pkgPath = internal |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 432 | } else { |
Nan Zhang | f0c4e43 | 2018-05-22 14:50:18 -0700 | [diff] [blame^] | 433 | if !p.isEmbeddedLauncherEnabled(p.properties.Actual_version) { |
| 434 | // pkg_path starts from "runfiles/" implicitly. |
| 435 | pkgPath = runFiles |
| 436 | } |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 437 | } |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 438 | } |
| 439 | |
Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 440 | p.genModulePathMappings(ctx, pkgPath, expandedSrcs, expandedData) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 441 | |
Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 442 | p.srcsZip = p.createSrcsZip(ctx, pkgPath) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | // generate current module unique pathMappings: <dest: runfiles_path, src: source_path> |
| 446 | // for python/data files. |
Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 447 | func (p *Module) genModulePathMappings(ctx android.ModuleContext, pkgPath string, |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 448 | expandedSrcs, expandedData android.Paths) { |
| 449 | // fetch <runfiles_path, source_path> pairs from "src" and "data" properties to |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 450 | // check current module duplicates. |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 451 | destToPySrcs := make(map[string]string) |
| 452 | destToPyData := make(map[string]string) |
| 453 | |
| 454 | for _, s := range expandedSrcs { |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 455 | if s.Ext() != pyExt && s.Ext() != protoExt { |
| 456 | ctx.PropertyErrorf("srcs", "found non (.py|.proto) file: %q!", s.String()) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 457 | continue |
| 458 | } |
Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 459 | runfilesPath := filepath.Join(pkgPath, s.Rel()) |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 460 | identifiers := strings.Split(strings.TrimSuffix(runfilesPath, |
| 461 | filepath.Ext(runfilesPath)), "/") |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 462 | for _, token := range identifiers { |
| 463 | if !pyIdentifierRegexp.MatchString(token) { |
| 464 | ctx.PropertyErrorf("srcs", "the path %q contains invalid token %q.", |
| 465 | runfilesPath, token) |
| 466 | } |
| 467 | } |
| 468 | if fillInMap(ctx, destToPySrcs, runfilesPath, s.String(), p.Name(), p.Name()) { |
| 469 | p.srcsPathMappings = append(p.srcsPathMappings, |
| 470 | pathMapping{dest: runfilesPath, src: s}) |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | for _, d := range expandedData { |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 475 | if d.Ext() == pyExt || d.Ext() == protoExt { |
| 476 | ctx.PropertyErrorf("data", "found (.py|.proto) file: %q!", d.String()) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 477 | continue |
| 478 | } |
Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 479 | runfilesPath := filepath.Join(pkgPath, d.Rel()) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 480 | if fillInMap(ctx, destToPyData, runfilesPath, d.String(), p.Name(), p.Name()) { |
| 481 | p.dataPathMappings = append(p.dataPathMappings, |
| 482 | pathMapping{dest: runfilesPath, src: d}) |
| 483 | } |
| 484 | } |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 485 | } |
| 486 | |
Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 487 | // register build actions to zip current module's sources. |
| 488 | func (p *Module) createSrcsZip(ctx android.ModuleContext, pkgPath string) android.Path { |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 489 | relativeRootMap := make(map[string]android.Paths) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 490 | pathMappings := append(p.srcsPathMappings, p.dataPathMappings...) |
| 491 | |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 492 | var protoSrcs android.Paths |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 493 | // "srcs" or "data" properties may have filegroup so it might happen that |
| 494 | // the relative root for each source path is different. |
| 495 | for _, path := range pathMappings { |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 496 | if path.src.Ext() == protoExt { |
| 497 | protoSrcs = append(protoSrcs, path.src) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 498 | } else { |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 499 | var relativeRoot string |
| 500 | relativeRoot = strings.TrimSuffix(path.src.String(), path.src.Rel()) |
| 501 | if v, found := relativeRootMap[relativeRoot]; found { |
| 502 | relativeRootMap[relativeRoot] = append(v, path.src) |
| 503 | } else { |
| 504 | relativeRootMap[relativeRoot] = android.Paths{path.src} |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | var zips android.Paths |
| 509 | if len(protoSrcs) > 0 { |
| 510 | for _, srcFile := range protoSrcs { |
| 511 | zip := genProto(ctx, &p.protoProperties, srcFile, |
| 512 | android.ProtoFlags(ctx, &p.protoProperties), pkgPath) |
| 513 | zips = append(zips, zip) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 517 | if len(relativeRootMap) > 0 { |
| 518 | var keys []string |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 519 | |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 520 | // in order to keep stable order of soong_zip params, we sort the keys here. |
| 521 | for k := range relativeRootMap { |
| 522 | keys = append(keys, k) |
Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 523 | } |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 524 | sort.Strings(keys) |
| 525 | |
| 526 | parArgs := []string{} |
Nan Zhang | f0c4e43 | 2018-05-22 14:50:18 -0700 | [diff] [blame^] | 527 | if pkgPath != "" { |
| 528 | parArgs = append(parArgs, `-P `+pkgPath) |
| 529 | } |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 530 | implicits := android.Paths{} |
| 531 | for _, k := range keys { |
| 532 | parArgs = append(parArgs, `-C `+k) |
| 533 | for _, path := range relativeRootMap[k] { |
| 534 | parArgs = append(parArgs, `-f `+path.String()) |
| 535 | implicits = append(implicits, path) |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | origSrcsZip := android.PathForModuleOut(ctx, ctx.ModuleName()+".py.srcszip") |
| 540 | ctx.Build(pctx, android.BuildParams{ |
| 541 | Rule: zip, |
| 542 | Description: "python library archive", |
| 543 | Output: origSrcsZip, |
| 544 | Implicits: implicits, |
| 545 | Args: map[string]string{ |
| 546 | "args": strings.Join(parArgs, " "), |
| 547 | }, |
| 548 | }) |
| 549 | zips = append(zips, origSrcsZip) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 550 | } |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 551 | if len(zips) == 1 { |
| 552 | return zips[0] |
| 553 | } else { |
| 554 | combinedSrcsZip := android.PathForModuleOut(ctx, ctx.ModuleName()+".srcszip") |
| 555 | ctx.Build(pctx, android.BuildParams{ |
| 556 | Rule: combineZip, |
| 557 | Description: "combine python library archive", |
| 558 | Output: combinedSrcsZip, |
| 559 | Inputs: zips, |
| 560 | }) |
| 561 | return combinedSrcsZip |
| 562 | } |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 563 | } |
| 564 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 565 | func isPythonLibModule(module blueprint.Module) bool { |
| 566 | if m, ok := module.(*Module); ok { |
| 567 | // Python library has no bootstrapper or installer. |
| 568 | if m.bootstrapper != nil || m.installer != nil { |
| 569 | return false |
| 570 | } |
| 571 | return true |
| 572 | } |
| 573 | return false |
| 574 | } |
| 575 | |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 576 | // check Python source/data files duplicates for whole runfiles tree since Python binary/test |
| 577 | // need collect and zip all srcs of whole transitive dependencies to a final par file. |
| 578 | func (p *Module) walkTransitiveDeps(ctx android.ModuleContext) { |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 579 | // fetch <runfiles_path, source_path> pairs from "src" and "data" properties to |
| 580 | // check duplicates. |
| 581 | destToPySrcs := make(map[string]string) |
| 582 | destToPyData := make(map[string]string) |
| 583 | |
| 584 | for _, path := range p.srcsPathMappings { |
| 585 | destToPySrcs[path.dest] = path.src.String() |
| 586 | } |
| 587 | for _, path := range p.dataPathMappings { |
| 588 | destToPyData[path.dest] = path.src.String() |
| 589 | } |
| 590 | |
| 591 | // visit all its dependencies in depth first. |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 592 | ctx.VisitDepsDepthFirst(func(module android.Module) { |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 593 | if ctx.OtherModuleDependencyTag(module) != pythonLibTag { |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 594 | return |
| 595 | } |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 596 | // Python modules only can depend on Python libraries. |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 597 | if !isPythonLibModule(module) { |
| 598 | panic(fmt.Errorf( |
| 599 | "the dependency %q of module %q is not Python library!", |
| 600 | ctx.ModuleName(), ctx.OtherModuleName(module))) |
| 601 | } |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 602 | if dep, ok := module.(PythonDependency); ok { |
| 603 | srcs := dep.GetSrcsPathMappings() |
| 604 | for _, path := range srcs { |
| 605 | if !fillInMap(ctx, destToPySrcs, |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 606 | path.dest, path.src.String(), ctx.ModuleName(), ctx.OtherModuleName(module)) { |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 607 | continue |
| 608 | } |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 609 | } |
| 610 | data := dep.GetDataPathMappings() |
| 611 | for _, path := range data { |
| 612 | fillInMap(ctx, destToPyData, |
Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 613 | path.dest, path.src.String(), ctx.ModuleName(), ctx.OtherModuleName(module)) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 614 | } |
Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 615 | p.depsSrcsZips = append(p.depsSrcsZips, dep.GetSrcsZip()) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 616 | } |
| 617 | }) |
| 618 | } |
| 619 | |
| 620 | func fillInMap(ctx android.ModuleContext, m map[string]string, |
| 621 | key, value, curModule, otherModule string) bool { |
| 622 | if oldValue, found := m[key]; found { |
| 623 | ctx.ModuleErrorf("found two files to be placed at the same runfiles location %q."+ |
| 624 | " First file: in module %s at path %q."+ |
| 625 | " Second file: in module %s at path %q.", |
| 626 | key, curModule, oldValue, otherModule, value) |
| 627 | return false |
| 628 | } else { |
| 629 | m[key] = value |
| 630 | } |
| 631 | |
| 632 | return true |
| 633 | } |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 634 | |
Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 635 | func (p *Module) InstallInData() bool { |
| 636 | return true |
| 637 | } |
| 638 | |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 639 | var Bool = proptools.Bool |
| 640 | var String = proptools.String |