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