| 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" | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 23 | "strings" | 
|  | 24 |  | 
|  | 25 | "github.com/google/blueprint" | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 26 | "github.com/google/blueprint/proptools" | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 27 |  | 
|  | 28 | "android/soong/android" | 
|  | 29 | ) | 
|  | 30 |  | 
|  | 31 | func init() { | 
| Paul Duffin | d089045 | 2021-03-17 21:57:08 +0000 | [diff] [blame] | 32 | registerPythonMutators(android.InitRegistrationContext) | 
|  | 33 | } | 
|  | 34 |  | 
|  | 35 | func registerPythonMutators(ctx android.RegistrationContext) { | 
|  | 36 | ctx.PreDepsMutators(RegisterPythonPreDepsMutators) | 
| Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 37 | } | 
|  | 38 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 39 | // Exported to support other packages using Python modules in tests. | 
| Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 40 | func RegisterPythonPreDepsMutators(ctx android.RegisterMutatorsContext) { | 
| Colin Cross | e20113d | 2020-11-22 19:37:44 -0800 | [diff] [blame] | 41 | ctx.BottomUp("python_version", versionSplitMutator()).Parallel() | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 42 | } | 
|  | 43 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 44 | // the version-specific properties that apply to python modules. | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 45 | type VersionProperties struct { | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 46 | // whether the module is required to be built with this version. | 
|  | 47 | // Defaults to true for Python 3, and false otherwise. | 
| Liz Kammer | 59c0eae | 2021-09-17 17:48:05 -0400 | [diff] [blame] | 48 | Enabled *bool | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 49 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 50 | // list of source files specific to this Python version. | 
|  | 51 | // Using the syntax ":module", srcs may reference the outputs of other modules that produce source files, | 
|  | 52 | // e.g. genrule or filegroup. | 
| Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 53 | Srcs []string `android:"path,arch_variant"` | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 54 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 55 | // list of source files that should not be used to build the Python module for this version. | 
|  | 56 | // This is most useful to remove files that are not common to all Python versions. | 
| Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 57 | Exclude_srcs []string `android:"path,arch_variant"` | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 58 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 59 | // list of the Python libraries used only for this Python version. | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 60 | Libs []string `android:"arch_variant"` | 
|  | 61 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 62 | // whether the binary is required to be built with embedded launcher for this version, defaults to false. | 
| Liz Kammer | 59c0eae | 2021-09-17 17:48:05 -0400 | [diff] [blame] | 63 | Embedded_launcher *bool // TODO(b/174041232): Remove this property | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 64 | } | 
|  | 65 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 66 | // properties that apply to all python modules | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 67 | type BaseProperties struct { | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 68 | // the package path prefix within the output artifact at which to place the source/data | 
|  | 69 | // files of the current module. | 
|  | 70 | // eg. Pkg_path = "a/b/c"; Other packages can reference this module by using | 
|  | 71 | // (from a.b.c import ...) statement. | 
| Nan Zhang | bea0975 | 2018-05-31 12:49:33 -0700 | [diff] [blame] | 72 | // if left unspecified, all the source/data files path is unchanged within zip file. | 
| Liz Kammer | 59c0eae | 2021-09-17 17:48:05 -0400 | [diff] [blame] | 73 | Pkg_path *string | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 74 |  | 
|  | 75 | // true, if the Python module is used internally, eg, Python std libs. | 
| Liz Kammer | 59c0eae | 2021-09-17 17:48:05 -0400 | [diff] [blame] | 76 | Is_internal *bool | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 77 |  | 
|  | 78 | // list of source (.py) files compatible both with Python2 and Python3 used to compile the | 
|  | 79 | // Python module. | 
|  | 80 | // srcs may reference the outputs of other modules that produce source files like genrule | 
|  | 81 | // or filegroup using the syntax ":module". | 
|  | 82 | // Srcs has to be non-empty. | 
| Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 83 | Srcs []string `android:"path,arch_variant"` | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 84 |  | 
|  | 85 | // list of source files that should not be used to build the C/C++ module. | 
|  | 86 | // This is most useful in the arch/multilib variants to remove non-common files | 
| Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 87 | Exclude_srcs []string `android:"path,arch_variant"` | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 88 |  | 
|  | 89 | // list of files or filegroup modules that provide data that should be installed alongside | 
|  | 90 | // the test. the file extension can be arbitrary except for (.py). | 
| Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 91 | Data []string `android:"path,arch_variant"` | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 92 |  | 
| Colin Cross | 1bc6393 | 2020-11-22 20:12:45 -0800 | [diff] [blame] | 93 | // list of java modules that provide data that should be installed alongside the test. | 
|  | 94 | Java_data []string | 
|  | 95 |  | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 96 | // list of the Python libraries compatible both with Python2 and Python3. | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 97 | Libs []string `android:"arch_variant"` | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 98 |  | 
|  | 99 | Version struct { | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 100 | // Python2-specific properties, including whether Python2 is supported for this module | 
|  | 101 | // and version-specific sources, exclusions and dependencies. | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 102 | Py2 VersionProperties `android:"arch_variant"` | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 103 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 104 | // Python3-specific properties, including whether Python3 is supported for this module | 
|  | 105 | // and version-specific sources, exclusions and dependencies. | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 106 | Py3 VersionProperties `android:"arch_variant"` | 
|  | 107 | } `android:"arch_variant"` | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 108 |  | 
|  | 109 | // the actual version each module uses after variations created. | 
|  | 110 | // this property name is hidden from users' perspectives, and soong will populate it during | 
|  | 111 | // runtime. | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 112 | Actual_version string `blueprint:"mutated"` | 
| Liz Kammer | 7e93e5b | 2020-10-30 15:44:09 -0700 | [diff] [blame] | 113 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 114 | // whether the module is required to be built with actual_version. | 
|  | 115 | // this is set by the python version mutator based on version-specific properties | 
| Liz Kammer | 7e93e5b | 2020-10-30 15:44:09 -0700 | [diff] [blame] | 116 | Enabled *bool `blueprint:"mutated"` | 
|  | 117 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 118 | // whether the binary is required to be built with embedded launcher for this actual_version. | 
|  | 119 | // this is set by the python version mutator based on version-specific properties | 
| Liz Kammer | 7e93e5b | 2020-10-30 15:44:09 -0700 | [diff] [blame] | 120 | Embedded_launcher *bool `blueprint:"mutated"` | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 121 | } | 
|  | 122 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 123 | // Used to store files of current module after expanding dependencies | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 124 | type pathMapping struct { | 
|  | 125 | dest string | 
|  | 126 | src  android.Path | 
|  | 127 | } | 
|  | 128 |  | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 129 | type PythonLibraryModule struct { | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 130 | android.ModuleBase | 
| Nan Zhang | a3fc4ba | 2017-07-20 17:43:37 -0700 | [diff] [blame] | 131 | android.DefaultableModuleBase | 
| Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 132 | android.BazelModuleBase | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 133 |  | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 134 | properties      BaseProperties | 
|  | 135 | protoProperties android.ProtoProperties | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 136 |  | 
|  | 137 | // initialize before calling Init | 
|  | 138 | hod      android.HostOrDeviceSupported | 
|  | 139 | multilib android.Multilib | 
|  | 140 |  | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 141 | // the Python files of current module after expanding source dependencies. | 
|  | 142 | // pathMapping: <dest: runfile_path, src: source_path> | 
|  | 143 | srcsPathMappings []pathMapping | 
|  | 144 |  | 
|  | 145 | // the data files of current module after expanding source dependencies. | 
|  | 146 | // pathMapping: <dest: runfile_path, src: source_path> | 
|  | 147 | dataPathMappings []pathMapping | 
|  | 148 |  | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 149 | // The zip file containing the current module's source/data files. | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 150 | srcsZip android.Path | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 151 |  | 
|  | 152 | // The zip file containing the current module's source/data files, with the | 
|  | 153 | // source files precompiled. | 
|  | 154 | precompiledSrcsZip android.Path | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 155 | } | 
|  | 156 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 157 | // newModule generates new Python base module | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 158 | func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *PythonLibraryModule { | 
|  | 159 | return &PythonLibraryModule{ | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 160 | hod:      hod, | 
|  | 161 | multilib: multilib, | 
|  | 162 | } | 
|  | 163 | } | 
|  | 164 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 165 | // interface implemented by Python modules to provide source and data mappings and zip to python | 
|  | 166 | // modules that depend on it | 
|  | 167 | type pythonDependency interface { | 
|  | 168 | getSrcsPathMappings() []pathMapping | 
|  | 169 | getDataPathMappings() []pathMapping | 
|  | 170 | getSrcsZip() android.Path | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 171 | getPrecompiledSrcsZip() android.Path | 
| Dan Willemsen | 339a63f | 2023-08-15 22:17:03 -0400 | [diff] [blame] | 172 | getPkgPath() string | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 173 | } | 
|  | 174 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 175 | // getSrcsPathMappings gets this module's path mapping of src source path : runfiles destination | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 176 | func (p *PythonLibraryModule) getSrcsPathMappings() []pathMapping { | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 177 | return p.srcsPathMappings | 
|  | 178 | } | 
|  | 179 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 180 | // getSrcsPathMappings gets this module's path mapping of data source path : runfiles destination | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 181 | func (p *PythonLibraryModule) getDataPathMappings() []pathMapping { | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 182 | return p.dataPathMappings | 
|  | 183 | } | 
|  | 184 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 185 | // getSrcsZip returns the filepath where the current module's source/data files are zipped. | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 186 | func (p *PythonLibraryModule) getSrcsZip() android.Path { | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 187 | return p.srcsZip | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 188 | } | 
|  | 189 |  | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 190 | // getSrcsZip returns the filepath where the current module's source/data files are zipped. | 
|  | 191 | func (p *PythonLibraryModule) getPrecompiledSrcsZip() android.Path { | 
|  | 192 | return p.precompiledSrcsZip | 
|  | 193 | } | 
|  | 194 |  | 
| Dan Willemsen | 339a63f | 2023-08-15 22:17:03 -0400 | [diff] [blame] | 195 | // getPkgPath returns the pkg_path value | 
|  | 196 | func (p *PythonLibraryModule) getPkgPath() string { | 
|  | 197 | return String(p.properties.Pkg_path) | 
|  | 198 | } | 
|  | 199 |  | 
| Spandan Das | cb84763 | 2023-08-22 19:24:07 +0000 | [diff] [blame] | 200 | // PkgPath is the "public" version of `getPkgPath` that is only available during bp2build | 
|  | 201 | func (p *PythonLibraryModule) PkgPath(ctx android.BazelConversionContext) *string { | 
|  | 202 | if ctx.Config().BuildMode != android.Bp2build { | 
|  | 203 | ctx.ModuleErrorf("PkgPath is only supported in bp2build mode") | 
|  | 204 | } | 
|  | 205 | return p.properties.Pkg_path | 
|  | 206 | } | 
|  | 207 |  | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 208 | func (p *PythonLibraryModule) getBaseProperties() *BaseProperties { | 
|  | 209 | return &p.properties | 
|  | 210 | } | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 211 |  | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 212 | var _ pythonDependency = (*PythonLibraryModule)(nil) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 213 |  | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 214 | func (p *PythonLibraryModule) init() android.Module { | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 215 | p.AddProperties(&p.properties, &p.protoProperties) | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 216 | android.InitAndroidArchModule(p, p.hod, p.multilib) | 
| Nan Zhang | a3fc4ba | 2017-07-20 17:43:37 -0700 | [diff] [blame] | 217 | android.InitDefaultableModule(p) | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 218 | android.InitBazelModule(p) | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 219 | return p | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 220 | } | 
|  | 221 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 222 | // Python-specific tag to transfer information on the purpose of a dependency. | 
|  | 223 | // This is used when adding a dependency on a module, which can later be accessed when visiting | 
|  | 224 | // dependencies. | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 225 | type dependencyTag struct { | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 226 | blueprint.BaseDependencyTag | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 227 | name string | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 228 | } | 
|  | 229 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 230 | // Python-specific tag that indicates that installed files of this module should depend on installed | 
|  | 231 | // files of the dependency | 
| Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 232 | type installDependencyTag struct { | 
|  | 233 | blueprint.BaseDependencyTag | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 234 | // embedding this struct provides the installation dependency requirement | 
| Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 235 | android.InstallAlwaysNeededDependencyTag | 
|  | 236 | name string | 
|  | 237 | } | 
|  | 238 |  | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 239 | var ( | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 240 | pythonLibTag = dependencyTag{name: "pythonLib"} | 
|  | 241 | javaDataTag  = dependencyTag{name: "javaData"} | 
|  | 242 | // The python interpreter, with soong module name "py3-launcher" or "py3-launcher-autorun". | 
| Cole Faust | 909d237 | 2023-02-13 23:17:40 +0000 | [diff] [blame] | 243 | launcherTag          = dependencyTag{name: "launcher"} | 
|  | 244 | launcherSharedLibTag = installDependencyTag{name: "launcherSharedLib"} | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 245 | // The python interpreter built for host so that we can precompile python sources. | 
|  | 246 | // This only works because the precompiled sources don't vary by architecture. | 
|  | 247 | // The soong module name is "py3-launcher". | 
| Cole Faust | 909d237 | 2023-02-13 23:17:40 +0000 | [diff] [blame] | 248 | hostLauncherTag          = dependencyTag{name: "hostLauncher"} | 
|  | 249 | hostlauncherSharedLibTag = dependencyTag{name: "hostlauncherSharedLib"} | 
|  | 250 | hostStdLibTag            = dependencyTag{name: "hostStdLib"} | 
|  | 251 | pathComponentRegexp      = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_-]*$`) | 
|  | 252 | pyExt                    = ".py" | 
|  | 253 | protoExt                 = ".proto" | 
|  | 254 | pyVersion2               = "PY2" | 
|  | 255 | pyVersion3               = "PY3" | 
| Cole Faust | d82f036 | 2023-04-12 17:32:19 -0700 | [diff] [blame] | 256 | pyVersion2And3           = "PY2ANDPY3" | 
| Cole Faust | 909d237 | 2023-02-13 23:17:40 +0000 | [diff] [blame] | 257 | internalPath             = "internal" | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 258 | ) | 
|  | 259 |  | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 260 | type basePropertiesProvider interface { | 
|  | 261 | getBaseProperties() *BaseProperties | 
|  | 262 | } | 
|  | 263 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 264 | // versionSplitMutator creates version variants for modules and appends the version-specific | 
|  | 265 | // properties for a given variant to the properties in the variant module | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 266 | func versionSplitMutator() func(android.BottomUpMutatorContext) { | 
|  | 267 | return func(mctx android.BottomUpMutatorContext) { | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 268 | if base, ok := mctx.Module().(basePropertiesProvider); ok { | 
|  | 269 | props := base.getBaseProperties() | 
|  | 270 | var versionNames []string | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 271 | // collect version specific properties, so that we can merge version-specific properties | 
|  | 272 | // into the module's overall properties | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 273 | var versionProps []VersionProperties | 
| Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 274 | // PY3 is first so that we alias the PY3 variant rather than PY2 if both | 
|  | 275 | // are available | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 276 | if proptools.BoolDefault(props.Version.Py3.Enabled, true) { | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 277 | versionNames = append(versionNames, pyVersion3) | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 278 | versionProps = append(versionProps, props.Version.Py3) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 279 | } | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 280 | if proptools.BoolDefault(props.Version.Py2.Enabled, false) { | 
| Cole Faust | edc4c50 | 2022-09-09 19:39:25 -0700 | [diff] [blame] | 281 | if !mctx.DeviceConfig().BuildBrokenUsesSoongPython2Modules() && | 
| Cole Faust | edc4c50 | 2022-09-09 19:39:25 -0700 | [diff] [blame] | 282 | mctx.ModuleName() != "py2-cmd" && | 
|  | 283 | mctx.ModuleName() != "py2-stdlib" { | 
|  | 284 | mctx.PropertyErrorf("version.py2.enabled", "Python 2 is no longer supported, please convert to python 3. This error can be temporarily overridden by setting BUILD_BROKEN_USES_SOONG_PYTHON2_MODULES := true in the product configuration") | 
|  | 285 | } | 
| Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 286 | versionNames = append(versionNames, pyVersion2) | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 287 | versionProps = append(versionProps, props.Version.Py2) | 
| Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 288 | } | 
| Colin Cross | e20113d | 2020-11-22 19:37:44 -0800 | [diff] [blame] | 289 | modules := mctx.CreateLocalVariations(versionNames...) | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 290 | // Alias module to the first variant | 
| Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 291 | if len(versionNames) > 0 { | 
|  | 292 | mctx.AliasVariation(versionNames[0]) | 
|  | 293 | } | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 294 | for i, v := range versionNames { | 
|  | 295 | // set the actual version for Python module. | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 296 | newProps := modules[i].(basePropertiesProvider).getBaseProperties() | 
|  | 297 | newProps.Actual_version = v | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 298 | // append versioned properties for the Python module to the overall properties | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 299 | err := proptools.AppendMatchingProperties([]interface{}{newProps}, &versionProps[i], nil) | 
| Liz Kammer | 7e93e5b | 2020-10-30 15:44:09 -0700 | [diff] [blame] | 300 | if err != nil { | 
|  | 301 | panic(err) | 
|  | 302 | } | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 303 | } | 
|  | 304 | } | 
|  | 305 | } | 
|  | 306 | } | 
|  | 307 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 308 | func anyHasExt(paths []string, ext string) bool { | 
|  | 309 | for _, p := range paths { | 
|  | 310 | if filepath.Ext(p) == ext { | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 311 | return true | 
|  | 312 | } | 
|  | 313 | } | 
|  | 314 |  | 
|  | 315 | return false | 
|  | 316 | } | 
|  | 317 |  | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 318 | func (p *PythonLibraryModule) anySrcHasExt(ctx android.BottomUpMutatorContext, ext string) bool { | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 319 | return anyHasExt(p.properties.Srcs, ext) | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 320 | } | 
|  | 321 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 322 | // DepsMutator mutates dependencies for this module: | 
| Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 323 | //   - handles proto dependencies, | 
|  | 324 | //   - if required, specifies launcher and adds launcher dependencies, | 
|  | 325 | //   - applies python version mutations to Python dependencies | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 326 | func (p *PythonLibraryModule) DepsMutator(ctx android.BottomUpMutatorContext) { | 
| Colin Cross | fe17f6f | 2019-03-28 19:30:56 -0700 | [diff] [blame] | 327 | android.ProtoDeps(ctx, &p.protoProperties) | 
|  | 328 |  | 
| Colin Cross | e20113d | 2020-11-22 19:37:44 -0800 | [diff] [blame] | 329 | versionVariation := []blueprint.Variation{ | 
|  | 330 | {"python_version", p.properties.Actual_version}, | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 331 | } | 
| Colin Cross | e20113d | 2020-11-22 19:37:44 -0800 | [diff] [blame] | 332 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 333 | // If sources contain a proto file, add dependency on libprotobuf-python | 
|  | 334 | if p.anySrcHasExt(ctx, protoExt) && p.Name() != "libprotobuf-python" { | 
| Colin Cross | e20113d | 2020-11-22 19:37:44 -0800 | [diff] [blame] | 335 | ctx.AddVariationDependencies(versionVariation, pythonLibTag, "libprotobuf-python") | 
|  | 336 | } | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 337 |  | 
|  | 338 | // Add python library dependencies for this python version variation | 
| Colin Cross | e20113d | 2020-11-22 19:37:44 -0800 | [diff] [blame] | 339 | ctx.AddVariationDependencies(versionVariation, pythonLibTag, android.LastUniqueStrings(p.properties.Libs)...) | 
| Liz Kammer | 7e93e5b | 2020-10-30 15:44:09 -0700 | [diff] [blame] | 340 |  | 
| Colin Cross | 1bc6393 | 2020-11-22 20:12:45 -0800 | [diff] [blame] | 341 | // Emulate the data property for java_data but with the arch variation overridden to "common" | 
|  | 342 | // so that it can point to java modules. | 
|  | 343 | javaDataVariation := []blueprint.Variation{{"arch", android.Common.String()}} | 
|  | 344 | ctx.AddVariationDependencies(javaDataVariation, javaDataTag, p.properties.Java_data...) | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 345 |  | 
| Cole Faust | 909d237 | 2023-02-13 23:17:40 +0000 | [diff] [blame] | 346 | p.AddDepsOnPythonLauncherAndStdlib(ctx, hostStdLibTag, hostLauncherTag, hostlauncherSharedLibTag, false, ctx.Config().BuildOSTarget) | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 347 | } | 
|  | 348 |  | 
| Cole Faust | 909d237 | 2023-02-13 23:17:40 +0000 | [diff] [blame] | 349 | // AddDepsOnPythonLauncherAndStdlib will make the current module depend on the python stdlib, | 
|  | 350 | // launcher (interpreter), and the launcher's shared libraries. If autorun is true, it will use | 
|  | 351 | // the autorun launcher instead of the regular one. This function acceps a targetForDeps argument | 
|  | 352 | // as the target to use for these dependencies. For embedded launcher python binaries, the launcher | 
|  | 353 | // that will be embedded will be under the same target as the python module itself. But when | 
|  | 354 | // precompiling python code, we need to get the python launcher built for host, even if we're | 
|  | 355 | // compiling the python module for device, so we pass a different target to this function. | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 356 | func (p *PythonLibraryModule) AddDepsOnPythonLauncherAndStdlib(ctx android.BottomUpMutatorContext, | 
| Cole Faust | 909d237 | 2023-02-13 23:17:40 +0000 | [diff] [blame] | 357 | stdLibTag, launcherTag, launcherSharedLibTag blueprint.DependencyTag, | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 358 | autorun bool, targetForDeps android.Target) { | 
|  | 359 | var stdLib string | 
|  | 360 | var launcherModule string | 
| Cole Faust | 909d237 | 2023-02-13 23:17:40 +0000 | [diff] [blame] | 361 | // Add launcher shared lib dependencies. Ideally, these should be | 
|  | 362 | // derived from the `shared_libs` property of the launcher. TODO: read these from | 
|  | 363 | // the python launcher itself using ctx.OtherModuleProvider() or similar on the result | 
|  | 364 | // of ctx.AddFarVariationDependencies() | 
|  | 365 | launcherSharedLibDeps := []string{ | 
|  | 366 | "libsqlite", | 
|  | 367 | } | 
|  | 368 | // Add launcher-specific dependencies for bionic | 
|  | 369 | if targetForDeps.Os.Bionic() { | 
|  | 370 | launcherSharedLibDeps = append(launcherSharedLibDeps, "libc", "libdl", "libm") | 
|  | 371 | } | 
|  | 372 | if targetForDeps.Os == android.LinuxMusl && !ctx.Config().HostStaticBinaries() { | 
|  | 373 | launcherSharedLibDeps = append(launcherSharedLibDeps, "libc_musl") | 
|  | 374 | } | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 375 |  | 
|  | 376 | switch p.properties.Actual_version { | 
|  | 377 | case pyVersion2: | 
|  | 378 | stdLib = "py2-stdlib" | 
|  | 379 |  | 
|  | 380 | launcherModule = "py2-launcher" | 
|  | 381 | if autorun { | 
|  | 382 | launcherModule = "py2-launcher-autorun" | 
|  | 383 | } | 
|  | 384 |  | 
| Cole Faust | 909d237 | 2023-02-13 23:17:40 +0000 | [diff] [blame] | 385 | launcherSharedLibDeps = append(launcherSharedLibDeps, "libc++") | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 386 | case pyVersion3: | 
| Dan Willemsen | 339a63f | 2023-08-15 22:17:03 -0400 | [diff] [blame] | 387 | var prebuiltStdLib bool | 
|  | 388 | if targetForDeps.Os.Bionic() { | 
|  | 389 | prebuiltStdLib = false | 
|  | 390 | } else if ctx.Config().VendorConfig("cpython3").Bool("force_build_host") { | 
|  | 391 | prebuiltStdLib = false | 
|  | 392 | } else { | 
|  | 393 | prebuiltStdLib = true | 
|  | 394 | } | 
|  | 395 |  | 
|  | 396 | if prebuiltStdLib { | 
|  | 397 | stdLib = "py3-stdlib-prebuilt" | 
|  | 398 | } else { | 
|  | 399 | stdLib = "py3-stdlib" | 
|  | 400 | } | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 401 |  | 
|  | 402 | launcherModule = "py3-launcher" | 
|  | 403 | if autorun { | 
|  | 404 | launcherModule = "py3-launcher-autorun" | 
|  | 405 | } | 
|  | 406 | if ctx.Config().HostStaticBinaries() && targetForDeps.Os == android.LinuxMusl { | 
|  | 407 | launcherModule += "-static" | 
|  | 408 | } | 
| Cole Faust | 909d237 | 2023-02-13 23:17:40 +0000 | [diff] [blame] | 409 | if ctx.Device() { | 
|  | 410 | launcherSharedLibDeps = append(launcherSharedLibDeps, "liblog") | 
|  | 411 | } | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 412 | default: | 
|  | 413 | panic(fmt.Errorf("unknown Python Actual_version: %q for module: %q.", | 
|  | 414 | p.properties.Actual_version, ctx.ModuleName())) | 
|  | 415 | } | 
|  | 416 | targetVariations := targetForDeps.Variations() | 
|  | 417 | if ctx.ModuleName() != stdLib { | 
|  | 418 | stdLibVariations := make([]blueprint.Variation, 0, len(targetVariations)+1) | 
|  | 419 | stdLibVariations = append(stdLibVariations, blueprint.Variation{Mutator: "python_version", Variation: p.properties.Actual_version}) | 
|  | 420 | stdLibVariations = append(stdLibVariations, targetVariations...) | 
|  | 421 | // Using AddFarVariationDependencies for all of these because they can be for a different | 
|  | 422 | // platform, like if the python module itself was being compiled for device, we may want | 
|  | 423 | // the python interpreter built for host so that we can precompile python sources. | 
|  | 424 | ctx.AddFarVariationDependencies(stdLibVariations, stdLibTag, stdLib) | 
|  | 425 | } | 
|  | 426 | ctx.AddFarVariationDependencies(targetVariations, launcherTag, launcherModule) | 
| Cole Faust | 909d237 | 2023-02-13 23:17:40 +0000 | [diff] [blame] | 427 | ctx.AddFarVariationDependencies(targetVariations, launcherSharedLibTag, launcherSharedLibDeps...) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 428 | } | 
|  | 429 |  | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 430 | // GenerateAndroidBuildActions performs build actions common to all Python modules | 
|  | 431 | func (p *PythonLibraryModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 432 | expandedSrcs := android.PathsForModuleSrcExcludes(ctx, p.properties.Srcs, p.properties.Exclude_srcs) | 
| Aditya Choudhary | 26df39f | 2023-11-29 16:42:42 +0000 | [diff] [blame] | 433 | ctx.SetProvider(blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: expandedSrcs.Strings()}) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 434 |  | 
|  | 435 | // expand data files from "data" property. | 
| Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 436 | expandedData := android.PathsForModuleSrc(ctx, p.properties.Data) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 437 |  | 
| Colin Cross | 1bc6393 | 2020-11-22 20:12:45 -0800 | [diff] [blame] | 438 | // Emulate the data property for java_data dependencies. | 
|  | 439 | for _, javaData := range ctx.GetDirectDepsWithTag(javaDataTag) { | 
|  | 440 | expandedData = append(expandedData, android.OutputFilesForModule(ctx, javaData, "")...) | 
|  | 441 | } | 
|  | 442 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 443 | // Validate pkg_path property | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 444 | pkgPath := String(p.properties.Pkg_path) | 
|  | 445 | if pkgPath != "" { | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 446 | // TODO: export validation from android/paths.go handling to replace this duplicated functionality | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 447 | pkgPath = filepath.Clean(String(p.properties.Pkg_path)) | 
|  | 448 | if pkgPath == ".." || strings.HasPrefix(pkgPath, "../") || | 
|  | 449 | strings.HasPrefix(pkgPath, "/") { | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 450 | ctx.PropertyErrorf("pkg_path", | 
|  | 451 | "%q must be a relative path contained in par file.", | 
| Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 452 | String(p.properties.Pkg_path)) | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 453 | return | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 454 | } | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 455 | } | 
|  | 456 | // If property Is_internal is set, prepend pkgPath with internalPath | 
|  | 457 | if proptools.BoolDefault(p.properties.Is_internal, false) { | 
|  | 458 | pkgPath = filepath.Join(internalPath, pkgPath) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 459 | } | 
|  | 460 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 461 | // generate src:destination path mappings for this module | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 462 | p.genModulePathMappings(ctx, pkgPath, expandedSrcs, expandedData) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 463 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 464 | // generate the zipfile of all source and data files | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 465 | p.srcsZip = p.createSrcsZip(ctx, pkgPath) | 
| Dan Willemsen | fe2dafc | 2023-08-24 22:59:16 +0000 | [diff] [blame] | 466 | p.precompiledSrcsZip = p.precompileSrcs(ctx) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 467 | } | 
|  | 468 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 469 | func isValidPythonPath(path string) error { | 
|  | 470 | identifiers := strings.Split(strings.TrimSuffix(path, filepath.Ext(path)), "/") | 
|  | 471 | for _, token := range identifiers { | 
|  | 472 | if !pathComponentRegexp.MatchString(token) { | 
|  | 473 | return fmt.Errorf("the path %q contains invalid subpath %q. "+ | 
|  | 474 | "Subpaths must be at least one character long. "+ | 
|  | 475 | "The first character must an underscore or letter. "+ | 
|  | 476 | "Following characters may be any of: letter, digit, underscore, hyphen.", | 
|  | 477 | path, token) | 
|  | 478 | } | 
|  | 479 | } | 
|  | 480 | return nil | 
|  | 481 | } | 
|  | 482 |  | 
|  | 483 | // For this module, generate unique pathMappings: <dest: runfiles_path, src: source_path> | 
|  | 484 | // for python/data files expanded from properties. | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 485 | func (p *PythonLibraryModule) genModulePathMappings(ctx android.ModuleContext, pkgPath string, | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 486 | expandedSrcs, expandedData android.Paths) { | 
|  | 487 | // fetch <runfiles_path, source_path> pairs from "src" and "data" properties to | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 488 | // check current module duplicates. | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 489 | destToPySrcs := make(map[string]string) | 
|  | 490 | destToPyData := make(map[string]string) | 
|  | 491 |  | 
| Dan Willemsen | 339a63f | 2023-08-15 22:17:03 -0400 | [diff] [blame] | 492 | // Disable path checks for the stdlib, as it includes a "." in the version string | 
|  | 493 | isInternal := proptools.BoolDefault(p.properties.Is_internal, false) | 
|  | 494 |  | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 495 | for _, s := range expandedSrcs { | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 496 | if s.Ext() != pyExt && s.Ext() != protoExt { | 
|  | 497 | ctx.PropertyErrorf("srcs", "found non (.py|.proto) file: %q!", s.String()) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 498 | continue | 
|  | 499 | } | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 500 | runfilesPath := filepath.Join(pkgPath, s.Rel()) | 
| Dan Willemsen | 339a63f | 2023-08-15 22:17:03 -0400 | [diff] [blame] | 501 | if !isInternal { | 
|  | 502 | if err := isValidPythonPath(runfilesPath); err != nil { | 
|  | 503 | ctx.PropertyErrorf("srcs", err.Error()) | 
|  | 504 | } | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 505 | } | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 506 | if !checkForDuplicateOutputPath(ctx, destToPySrcs, runfilesPath, s.String(), p.Name(), p.Name()) { | 
|  | 507 | p.srcsPathMappings = append(p.srcsPathMappings, pathMapping{dest: runfilesPath, src: s}) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 508 | } | 
|  | 509 | } | 
|  | 510 |  | 
|  | 511 | for _, d := range expandedData { | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 512 | if d.Ext() == pyExt || d.Ext() == protoExt { | 
|  | 513 | ctx.PropertyErrorf("data", "found (.py|.proto) file: %q!", d.String()) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 514 | continue | 
|  | 515 | } | 
| Nan Zhang | 1db8540 | 2017-12-18 13:20:23 -0800 | [diff] [blame] | 516 | runfilesPath := filepath.Join(pkgPath, d.Rel()) | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 517 | if !checkForDuplicateOutputPath(ctx, destToPyData, runfilesPath, d.String(), p.Name(), p.Name()) { | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 518 | p.dataPathMappings = append(p.dataPathMappings, | 
|  | 519 | pathMapping{dest: runfilesPath, src: d}) | 
|  | 520 | } | 
|  | 521 | } | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 522 | } | 
|  | 523 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 524 | // createSrcsZip registers build actions to zip current module's sources and data. | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 525 | func (p *PythonLibraryModule) createSrcsZip(ctx android.ModuleContext, pkgPath string) android.Path { | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 526 | relativeRootMap := make(map[string]android.Paths) | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 527 | var protoSrcs android.Paths | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 528 | addPathMapping := func(path pathMapping) { | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 529 | // handle proto sources separately | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 530 | if path.src.Ext() == protoExt { | 
|  | 531 | protoSrcs = append(protoSrcs, path.src) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 532 | } else { | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 533 | relativeRoot := strings.TrimSuffix(path.src.String(), path.src.Rel()) | 
|  | 534 | relativeRootMap[relativeRoot] = append(relativeRootMap[relativeRoot], path.src) | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 535 | } | 
|  | 536 | } | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 537 |  | 
|  | 538 | // "srcs" or "data" properties may contain filegroups so it might happen that | 
|  | 539 | // the root directory for each source path is different. | 
|  | 540 | for _, path := range p.srcsPathMappings { | 
|  | 541 | addPathMapping(path) | 
|  | 542 | } | 
|  | 543 | for _, path := range p.dataPathMappings { | 
|  | 544 | addPathMapping(path) | 
|  | 545 | } | 
|  | 546 |  | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 547 | var zips android.Paths | 
|  | 548 | if len(protoSrcs) > 0 { | 
| Colin Cross | 19878da | 2019-03-28 14:45:07 -0700 | [diff] [blame] | 549 | protoFlags := android.GetProtoFlags(ctx, &p.protoProperties) | 
|  | 550 | protoFlags.OutTypeFlag = "--python_out" | 
|  | 551 |  | 
| Cole Faust | caf766b | 2022-10-21 16:07:56 -0700 | [diff] [blame] | 552 | if pkgPath != "" { | 
| Cole Faust | 43ac21f | 2022-09-19 11:19:52 -0700 | [diff] [blame] | 553 | pkgPathStagingDir := android.PathForModuleGen(ctx, "protos_staged_for_pkg_path") | 
|  | 554 | rule := android.NewRuleBuilder(pctx, ctx) | 
|  | 555 | var stagedProtoSrcs android.Paths | 
|  | 556 | for _, srcFile := range protoSrcs { | 
|  | 557 | stagedProtoSrc := pkgPathStagingDir.Join(ctx, pkgPath, srcFile.Rel()) | 
|  | 558 | rule.Command().Text("mkdir -p").Flag(filepath.Base(stagedProtoSrc.String())) | 
|  | 559 | rule.Command().Text("cp -f").Input(srcFile).Output(stagedProtoSrc) | 
|  | 560 | stagedProtoSrcs = append(stagedProtoSrcs, stagedProtoSrc) | 
|  | 561 | } | 
|  | 562 | rule.Build("stage_protos_for_pkg_path", "Stage protos for pkg_path") | 
|  | 563 | protoSrcs = stagedProtoSrcs | 
| Cole Faust | 43ac21f | 2022-09-19 11:19:52 -0700 | [diff] [blame] | 564 | } | 
|  | 565 |  | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 566 | for _, srcFile := range protoSrcs { | 
| Cole Faust | caf766b | 2022-10-21 16:07:56 -0700 | [diff] [blame] | 567 | zip := genProto(ctx, srcFile, protoFlags) | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 568 | zips = append(zips, zip) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 569 | } | 
|  | 570 | } | 
|  | 571 |  | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 572 | if len(relativeRootMap) > 0 { | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 573 | // in order to keep stable order of soong_zip params, we sort the keys here. | 
| Cole Faust | 18994c7 | 2023-02-28 16:02:16 -0800 | [diff] [blame] | 574 | roots := android.SortedKeys(relativeRootMap) | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 575 |  | 
| Cole Faust | 0124336 | 2022-06-02 12:11:12 -0700 | [diff] [blame] | 576 | // Use -symlinks=false so that the symlinks in the bazel output directory are followed | 
|  | 577 | parArgs := []string{"-symlinks=false"} | 
| Nan Zhang | f0c4e43 | 2018-05-22 14:50:18 -0700 | [diff] [blame] | 578 | if pkgPath != "" { | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 579 | // use package path as path prefix | 
| Nan Zhang | f0c4e43 | 2018-05-22 14:50:18 -0700 | [diff] [blame] | 580 | parArgs = append(parArgs, `-P `+pkgPath) | 
|  | 581 | } | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 582 | paths := android.Paths{} | 
|  | 583 | for _, root := range roots { | 
|  | 584 | // specify relative root of file in following -f arguments | 
|  | 585 | parArgs = append(parArgs, `-C `+root) | 
|  | 586 | for _, path := range relativeRootMap[root] { | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 587 | parArgs = append(parArgs, `-f `+path.String()) | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 588 | paths = append(paths, path) | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 589 | } | 
|  | 590 | } | 
|  | 591 |  | 
|  | 592 | origSrcsZip := android.PathForModuleOut(ctx, ctx.ModuleName()+".py.srcszip") | 
|  | 593 | ctx.Build(pctx, android.BuildParams{ | 
|  | 594 | Rule:        zip, | 
|  | 595 | Description: "python library archive", | 
|  | 596 | Output:      origSrcsZip, | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 597 | // as zip rule does not use $in, there is no real need to distinguish between Inputs and Implicits | 
|  | 598 | Implicits: paths, | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 599 | Args: map[string]string{ | 
|  | 600 | "args": strings.Join(parArgs, " "), | 
|  | 601 | }, | 
|  | 602 | }) | 
|  | 603 | zips = append(zips, origSrcsZip) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 604 | } | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 605 | // we may have multiple zips due to separate handling of proto source files | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 606 | if len(zips) == 1 { | 
|  | 607 | return zips[0] | 
|  | 608 | } else { | 
|  | 609 | combinedSrcsZip := android.PathForModuleOut(ctx, ctx.ModuleName()+".srcszip") | 
|  | 610 | ctx.Build(pctx, android.BuildParams{ | 
|  | 611 | Rule:        combineZip, | 
|  | 612 | Description: "combine python library archive", | 
|  | 613 | Output:      combinedSrcsZip, | 
|  | 614 | Inputs:      zips, | 
|  | 615 | }) | 
|  | 616 | return combinedSrcsZip | 
|  | 617 | } | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 618 | } | 
|  | 619 |  | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 620 | func (p *PythonLibraryModule) precompileSrcs(ctx android.ModuleContext) android.Path { | 
|  | 621 | // To precompile the python sources, we need a python interpreter and stdlib built | 
|  | 622 | // for host. We then use those to compile the python sources, which may be used on either | 
|  | 623 | // host of device. Python bytecode is architecture agnostic, so we're essentially | 
|  | 624 | // "cross compiling" for device here purely by virtue of host and device python bytecode | 
|  | 625 | // being the same. | 
|  | 626 | var stdLib android.Path | 
| Dan Willemsen | 339a63f | 2023-08-15 22:17:03 -0400 | [diff] [blame] | 627 | var stdLibPkg string | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 628 | var launcher android.Path | 
| Dan Willemsen | 339a63f | 2023-08-15 22:17:03 -0400 | [diff] [blame] | 629 | if proptools.BoolDefault(p.properties.Is_internal, false) { | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 630 | stdLib = p.srcsZip | 
| Dan Willemsen | 339a63f | 2023-08-15 22:17:03 -0400 | [diff] [blame] | 631 | stdLibPkg = p.getPkgPath() | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 632 | } else { | 
|  | 633 | ctx.VisitDirectDepsWithTag(hostStdLibTag, func(module android.Module) { | 
|  | 634 | if dep, ok := module.(pythonDependency); ok { | 
|  | 635 | stdLib = dep.getPrecompiledSrcsZip() | 
| Dan Willemsen | 339a63f | 2023-08-15 22:17:03 -0400 | [diff] [blame] | 636 | stdLibPkg = dep.getPkgPath() | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 637 | } | 
|  | 638 | }) | 
|  | 639 | } | 
|  | 640 | ctx.VisitDirectDepsWithTag(hostLauncherTag, func(module android.Module) { | 
|  | 641 | if dep, ok := module.(IntermPathProvider); ok { | 
|  | 642 | optionalLauncher := dep.IntermPathForModuleOut() | 
|  | 643 | if optionalLauncher.Valid() { | 
|  | 644 | launcher = optionalLauncher.Path() | 
|  | 645 | } | 
| Cole Faust | 909d237 | 2023-02-13 23:17:40 +0000 | [diff] [blame] | 646 | } | 
|  | 647 | }) | 
|  | 648 | var launcherSharedLibs android.Paths | 
|  | 649 | var ldLibraryPath []string | 
|  | 650 | ctx.VisitDirectDepsWithTag(hostlauncherSharedLibTag, func(module android.Module) { | 
|  | 651 | if dep, ok := module.(IntermPathProvider); ok { | 
|  | 652 | optionalPath := dep.IntermPathForModuleOut() | 
|  | 653 | if optionalPath.Valid() { | 
|  | 654 | launcherSharedLibs = append(launcherSharedLibs, optionalPath.Path()) | 
|  | 655 | ldLibraryPath = append(ldLibraryPath, filepath.Dir(optionalPath.Path().String())) | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 656 | } | 
|  | 657 | } | 
|  | 658 | }) | 
|  | 659 |  | 
|  | 660 | out := android.PathForModuleOut(ctx, ctx.ModuleName()+".srcszipprecompiled") | 
|  | 661 | if stdLib == nil || launcher == nil { | 
|  | 662 | // This shouldn't happen in a real build because we'll error out when adding dependencies | 
|  | 663 | // on the stdlib and launcher if they don't exist. But some tests set | 
|  | 664 | // AllowMissingDependencies. | 
|  | 665 | return out | 
|  | 666 | } | 
|  | 667 | ctx.Build(pctx, android.BuildParams{ | 
|  | 668 | Rule:        precompile, | 
|  | 669 | Input:       p.srcsZip, | 
|  | 670 | Output:      out, | 
|  | 671 | Implicits:   launcherSharedLibs, | 
|  | 672 | Description: "Precompile the python sources of " + ctx.ModuleName(), | 
|  | 673 | Args: map[string]string{ | 
|  | 674 | "stdlibZip":     stdLib.String(), | 
| Dan Willemsen | 339a63f | 2023-08-15 22:17:03 -0400 | [diff] [blame] | 675 | "stdlibPkg":     stdLibPkg, | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 676 | "launcher":      launcher.String(), | 
|  | 677 | "ldLibraryPath": strings.Join(ldLibraryPath, ":"), | 
|  | 678 | }, | 
|  | 679 | }) | 
|  | 680 | return out | 
|  | 681 | } | 
|  | 682 |  | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 683 | // isPythonLibModule returns whether the given module is a Python library PythonLibraryModule or not | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 684 | func isPythonLibModule(module blueprint.Module) bool { | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 685 | if _, ok := module.(*PythonLibraryModule); ok { | 
|  | 686 | if _, ok := module.(*PythonBinaryModule); !ok { | 
|  | 687 | return true | 
|  | 688 | } | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 689 | } | 
|  | 690 | return false | 
|  | 691 | } | 
|  | 692 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 693 | // collectPathsFromTransitiveDeps checks for source/data files for duplicate paths | 
|  | 694 | // for module and its transitive dependencies and collects list of data/source file | 
|  | 695 | // zips for transitive dependencies. | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 696 | func (p *PythonLibraryModule) collectPathsFromTransitiveDeps(ctx android.ModuleContext, precompiled bool) android.Paths { | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 697 | // fetch <runfiles_path, source_path> pairs from "src" and "data" properties to | 
|  | 698 | // check duplicates. | 
|  | 699 | destToPySrcs := make(map[string]string) | 
|  | 700 | destToPyData := make(map[string]string) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 701 | for _, path := range p.srcsPathMappings { | 
|  | 702 | destToPySrcs[path.dest] = path.src.String() | 
|  | 703 | } | 
|  | 704 | for _, path := range p.dataPathMappings { | 
|  | 705 | destToPyData[path.dest] = path.src.String() | 
|  | 706 | } | 
|  | 707 |  | 
| Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 708 | seen := make(map[android.Module]bool) | 
|  | 709 |  | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 710 | var result android.Paths | 
|  | 711 |  | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 712 | // visit all its dependencies in depth first. | 
| Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 713 | ctx.WalkDeps(func(child, parent android.Module) bool { | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 714 | // we only collect dependencies tagged as python library deps | 
| Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 715 | if ctx.OtherModuleDependencyTag(child) != pythonLibTag { | 
|  | 716 | return false | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 717 | } | 
| Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 718 | if seen[child] { | 
|  | 719 | return false | 
|  | 720 | } | 
|  | 721 | seen[child] = true | 
| Nan Zhang | b8fa197 | 2017-12-22 16:12:00 -0800 | [diff] [blame] | 722 | // Python modules only can depend on Python libraries. | 
| Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 723 | if !isPythonLibModule(child) { | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 724 | ctx.PropertyErrorf("libs", | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 725 | "the dependency %q of module %q is not Python library!", | 
| Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | d75507f | 2021-08-20 21:02:43 +0000 | [diff] [blame] | 726 | ctx.OtherModuleName(child), ctx.ModuleName()) | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 727 | } | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 728 | // collect source and data paths, checking that there are no duplicate output file conflicts | 
|  | 729 | if dep, ok := child.(pythonDependency); ok { | 
|  | 730 | srcs := dep.getSrcsPathMappings() | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 731 | for _, path := range srcs { | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 732 | checkForDuplicateOutputPath(ctx, destToPySrcs, | 
| Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 733 | path.dest, path.src.String(), ctx.ModuleName(), ctx.OtherModuleName(child)) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 734 | } | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 735 | data := dep.getDataPathMappings() | 
|  | 736 | for _, path := range data { | 
|  | 737 | checkForDuplicateOutputPath(ctx, destToPyData, | 
|  | 738 | path.dest, path.src.String(), ctx.ModuleName(), ctx.OtherModuleName(child)) | 
|  | 739 | } | 
| Cole Faust | 5c503d1 | 2023-01-24 11:48:08 -0800 | [diff] [blame] | 740 | if precompiled { | 
|  | 741 | result = append(result, dep.getPrecompiledSrcsZip()) | 
|  | 742 | } else { | 
|  | 743 | result = append(result, dep.getSrcsZip()) | 
|  | 744 | } | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 745 | } | 
| Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 746 | return true | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 747 | }) | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 748 | return result | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 749 | } | 
|  | 750 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 751 | // chckForDuplicateOutputPath checks whether outputPath has already been included in map m, which | 
|  | 752 | // would result in two files being placed in the same location. | 
|  | 753 | // If there is a duplicate path, an error is thrown and true is returned | 
|  | 754 | // Otherwise, outputPath: srcPath is added to m and returns false | 
|  | 755 | func checkForDuplicateOutputPath(ctx android.ModuleContext, m map[string]string, outputPath, srcPath, curModule, otherModule string) bool { | 
|  | 756 | if oldSrcPath, found := m[outputPath]; found { | 
| Nan Zhang | bea0975 | 2018-05-31 12:49:33 -0700 | [diff] [blame] | 757 | ctx.ModuleErrorf("found two files to be placed at the same location within zip %q."+ | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 758 | " First file: in module %s at path %q."+ | 
|  | 759 | " Second file: in module %s at path %q.", | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 760 | outputPath, curModule, oldSrcPath, otherModule, srcPath) | 
|  | 761 | return true | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 762 | } | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 763 | m[outputPath] = srcPath | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 764 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 765 | return false | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 766 | } | 
| Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 767 |  | 
| Liz Kammer | d737d02 | 2020-11-16 15:42:51 -0800 | [diff] [blame] | 768 | // InstallInData returns true as Python is not supported in the system partition | 
| Cole Faust | 4d247e6 | 2023-01-23 10:14:58 -0800 | [diff] [blame] | 769 | func (p *PythonLibraryModule) InstallInData() bool { | 
| Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 770 | return true | 
|  | 771 | } | 
|  | 772 |  | 
| Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 773 | var Bool = proptools.Bool | 
| Dan Willemsen | 6ca390f | 2019-02-14 23:17:08 -0800 | [diff] [blame] | 774 | var BoolDefault = proptools.BoolDefault | 
| Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 775 | var String = proptools.String |