casbin-async-django-orm-adapter 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. async_casbin_adapter/__init__.py +0 -0
  2. async_casbin_adapter/adapter.py +100 -0
  3. async_casbin_adapter/apps.py +24 -0
  4. async_casbin_adapter/enforcer.py +81 -0
  5. async_casbin_adapter/migrations/0001_initial.py +37 -0
  6. async_casbin_adapter/migrations/__init__.py +0 -0
  7. async_casbin_adapter/models.py +48 -0
  8. async_casbin_adapter/utils.py +25 -0
  9. casbin_async_django_orm_adapter-1.0.0.dist-info/METADATA +116 -0
  10. casbin_async_django_orm_adapter-1.0.0.dist-info/RECORD +74 -0
  11. casbin_async_django_orm_adapter-1.0.0.dist-info/WHEEL +5 -0
  12. casbin_async_django_orm_adapter-1.0.0.dist-info/licenses/LICENSE +201 -0
  13. casbin_async_django_orm_adapter-1.0.0.dist-info/top_level.txt +3 -0
  14. node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  15. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +365 -0
  16. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  17. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1272 -0
  18. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
  19. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  20. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +152 -0
  21. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +270 -0
  22. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
  23. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +704 -0
  24. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/common.py +709 -0
  25. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +173 -0
  26. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +169 -0
  27. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +113 -0
  28. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  29. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  30. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +805 -0
  31. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1172 -0
  32. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1319 -0
  33. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +128 -0
  34. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +104 -0
  35. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +462 -0
  36. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
  37. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +56 -0
  38. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2745 -0
  39. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3976 -0
  40. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  41. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2965 -0
  42. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +67 -0
  43. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1391 -0
  44. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +26 -0
  45. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input.py +3112 -0
  46. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +99 -0
  47. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +767 -0
  48. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1260 -0
  49. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  50. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  51. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +373 -0
  52. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1939 -0
  53. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation_test.py +54 -0
  54. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +303 -0
  55. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3196 -0
  56. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
  57. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/__init__.py +15 -0
  58. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_elffile.py +108 -0
  59. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_manylinux.py +252 -0
  60. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_musllinux.py +83 -0
  61. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_parser.py +359 -0
  62. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_structures.py +61 -0
  63. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_tokenizer.py +192 -0
  64. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/markers.py +252 -0
  65. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/metadata.py +825 -0
  66. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/py.typed +0 -0
  67. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/requirements.py +90 -0
  68. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/specifiers.py +1030 -0
  69. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/tags.py +553 -0
  70. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/utils.py +172 -0
  71. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/version.py +563 -0
  72. node_modules/npm/node_modules/node-gyp/gyp/test_gyp.py +261 -0
  73. node_modules/semantic-release-pypi/dist/py/set_version.py +32 -0
  74. node_modules/semantic-release-pypi/dist/py/verify_setup.py +24 -0
@@ -0,0 +1,1172 @@
1
+ # Copyright (c) 2012 Google Inc. All rights reserved.
2
+ # Use of this source code is governed by a BSD-style license that can be
3
+ # found in the LICENSE file.
4
+
5
+ # Notes:
6
+ #
7
+ # This generates makefiles suitable for inclusion into the Android build system
8
+ # via an Android.mk file. It is based on make.py, the standard makefile
9
+ # generator.
10
+ #
11
+ # The code below generates a separate .mk file for each target, but
12
+ # all are sourced by the top-level GypAndroid.mk. This means that all
13
+ # variables in .mk-files clobber one another, and furthermore that any
14
+ # variables set potentially clash with other Android build system variables.
15
+ # Try to avoid setting global variables where possible.
16
+
17
+
18
+ import os
19
+ import re
20
+ import subprocess
21
+
22
+ import gyp
23
+ import gyp.common
24
+ from gyp.generator import make # Reuse global functions from make backend.
25
+
26
+ generator_default_variables = {
27
+ "OS": "android",
28
+ "EXECUTABLE_PREFIX": "",
29
+ "EXECUTABLE_SUFFIX": "",
30
+ "STATIC_LIB_PREFIX": "lib",
31
+ "SHARED_LIB_PREFIX": "lib",
32
+ "STATIC_LIB_SUFFIX": ".a",
33
+ "SHARED_LIB_SUFFIX": ".so",
34
+ "INTERMEDIATE_DIR": "$(gyp_intermediate_dir)",
35
+ "SHARED_INTERMEDIATE_DIR": "$(gyp_shared_intermediate_dir)",
36
+ "PRODUCT_DIR": "$(gyp_shared_intermediate_dir)",
37
+ "SHARED_LIB_DIR": "$(builddir)/lib.$(TOOLSET)",
38
+ "LIB_DIR": "$(obj).$(TOOLSET)",
39
+ "RULE_INPUT_ROOT": "%(INPUT_ROOT)s", # This gets expanded by Python.
40
+ "RULE_INPUT_DIRNAME": "%(INPUT_DIRNAME)s", # This gets expanded by Python.
41
+ "RULE_INPUT_PATH": "$(RULE_SOURCES)",
42
+ "RULE_INPUT_EXT": "$(suffix $<)",
43
+ "RULE_INPUT_NAME": "$(notdir $<)",
44
+ "CONFIGURATION_NAME": "$(GYP_CONFIGURATION)",
45
+ }
46
+
47
+ # Make supports multiple toolsets
48
+ generator_supports_multiple_toolsets = True
49
+
50
+
51
+ # Generator-specific gyp specs.
52
+ generator_additional_non_configuration_keys = [
53
+ # Boolean to declare that this target does not want its name mangled.
54
+ "android_unmangled_name",
55
+ # Map of android build system variables to set.
56
+ "aosp_build_settings",
57
+ ]
58
+ generator_additional_path_sections = []
59
+ generator_extra_sources_for_rules = []
60
+
61
+
62
+ ALL_MODULES_FOOTER = """\
63
+ # "gyp_all_modules" is a concatenation of the "gyp_all_modules" targets from
64
+ # all the included sub-makefiles. This is just here to clarify.
65
+ gyp_all_modules:
66
+ """
67
+
68
+ header = """\
69
+ # This file is generated by gyp; do not edit.
70
+
71
+ """
72
+
73
+ # Map gyp target types to Android module classes.
74
+ MODULE_CLASSES = {
75
+ "static_library": "STATIC_LIBRARIES",
76
+ "shared_library": "SHARED_LIBRARIES",
77
+ "executable": "EXECUTABLES",
78
+ }
79
+
80
+
81
+ def IsCPPExtension(ext):
82
+ return make.COMPILABLE_EXTENSIONS.get(ext) == "cxx"
83
+
84
+
85
+ def Sourceify(path):
86
+ """Convert a path to its source directory form. The Android backend does not
87
+ support options.generator_output, so this function is a noop."""
88
+ return path
89
+
90
+
91
+ # Map from qualified target to path to output.
92
+ # For Android, the target of these maps is a tuple ('static', 'modulename'),
93
+ # ('dynamic', 'modulename'), or ('path', 'some/path') instead of a string,
94
+ # since we link by module.
95
+ target_outputs = {}
96
+ # Map from qualified target to any linkable output. A subset
97
+ # of target_outputs. E.g. when mybinary depends on liba, we want to
98
+ # include liba in the linker line; when otherbinary depends on
99
+ # mybinary, we just want to build mybinary first.
100
+ target_link_deps = {}
101
+
102
+
103
+ class AndroidMkWriter:
104
+ """AndroidMkWriter packages up the writing of one target-specific Android.mk.
105
+
106
+ Its only real entry point is Write(), and is mostly used for namespacing.
107
+ """
108
+
109
+ def __init__(self, android_top_dir):
110
+ self.android_top_dir = android_top_dir
111
+
112
+ def Write(
113
+ self,
114
+ qualified_target,
115
+ relative_target,
116
+ base_path,
117
+ output_filename,
118
+ spec,
119
+ configs,
120
+ part_of_all,
121
+ write_alias_target,
122
+ sdk_version,
123
+ ):
124
+ """The main entry point: writes a .mk file for a single target.
125
+
126
+ Arguments:
127
+ qualified_target: target we're generating
128
+ relative_target: qualified target name relative to the root
129
+ base_path: path relative to source root we're building in, used to resolve
130
+ target-relative paths
131
+ output_filename: output .mk file name to write
132
+ spec, configs: gyp info
133
+ part_of_all: flag indicating this target is part of 'all'
134
+ write_alias_target: flag indicating whether to create short aliases for
135
+ this target
136
+ sdk_version: what to emit for LOCAL_SDK_VERSION in output
137
+ """
138
+ gyp.common.EnsureDirExists(output_filename)
139
+
140
+ self.fp = open(output_filename, "w")
141
+
142
+ self.fp.write(header)
143
+
144
+ self.qualified_target = qualified_target
145
+ self.relative_target = relative_target
146
+ self.path = base_path
147
+ self.target = spec["target_name"]
148
+ self.type = spec["type"]
149
+ self.toolset = spec["toolset"]
150
+
151
+ deps, link_deps = self.ComputeDeps(spec)
152
+
153
+ # Some of the generation below can add extra output, sources, or
154
+ # link dependencies. All of the out params of the functions that
155
+ # follow use names like extra_foo.
156
+ extra_outputs = []
157
+ extra_sources = []
158
+
159
+ self.android_class = MODULE_CLASSES.get(self.type, "GYP")
160
+ self.android_module = self.ComputeAndroidModule(spec)
161
+ (self.android_stem, self.android_suffix) = self.ComputeOutputParts(spec)
162
+ self.output = self.output_binary = self.ComputeOutput(spec)
163
+
164
+ # Standard header.
165
+ self.WriteLn("include $(CLEAR_VARS)\n")
166
+
167
+ # Module class and name.
168
+ self.WriteLn("LOCAL_MODULE_CLASS := " + self.android_class)
169
+ self.WriteLn("LOCAL_MODULE := " + self.android_module)
170
+ # Only emit LOCAL_MODULE_STEM if it's different to LOCAL_MODULE.
171
+ # The library module classes fail if the stem is set. ComputeOutputParts
172
+ # makes sure that stem == modulename in these cases.
173
+ if self.android_stem != self.android_module:
174
+ self.WriteLn("LOCAL_MODULE_STEM := " + self.android_stem)
175
+ self.WriteLn("LOCAL_MODULE_SUFFIX := " + self.android_suffix)
176
+ if self.toolset == "host":
177
+ self.WriteLn("LOCAL_IS_HOST_MODULE := true")
178
+ self.WriteLn("LOCAL_MULTILIB := $(GYP_HOST_MULTILIB)")
179
+ elif sdk_version > 0:
180
+ self.WriteLn(
181
+ "LOCAL_MODULE_TARGET_ARCH := $(TARGET_$(GYP_VAR_PREFIX)ARCH)"
182
+ )
183
+ self.WriteLn("LOCAL_SDK_VERSION := %s" % sdk_version)
184
+
185
+ # Grab output directories; needed for Actions and Rules.
186
+ if self.toolset == "host":
187
+ self.WriteLn(
188
+ "gyp_intermediate_dir := "
189
+ "$(call local-intermediates-dir,,$(GYP_HOST_VAR_PREFIX))"
190
+ )
191
+ else:
192
+ self.WriteLn(
193
+ "gyp_intermediate_dir := "
194
+ "$(call local-intermediates-dir,,$(GYP_VAR_PREFIX))"
195
+ )
196
+ self.WriteLn(
197
+ "gyp_shared_intermediate_dir := "
198
+ "$(call intermediates-dir-for,GYP,shared,,,$(GYP_VAR_PREFIX))"
199
+ )
200
+ self.WriteLn()
201
+
202
+ # List files this target depends on so that actions/rules/copies/sources
203
+ # can depend on the list.
204
+ # TODO: doesn't pull in things through transitive link deps; needed?
205
+ target_dependencies = [x[1] for x in deps if x[0] == "path"]
206
+ self.WriteLn("# Make sure our deps are built first.")
207
+ self.WriteList(
208
+ target_dependencies, "GYP_TARGET_DEPENDENCIES", local_pathify=True
209
+ )
210
+
211
+ # Actions must come first, since they can generate more OBJs for use below.
212
+ if "actions" in spec:
213
+ self.WriteActions(spec["actions"], extra_sources, extra_outputs)
214
+
215
+ # Rules must be early like actions.
216
+ if "rules" in spec:
217
+ self.WriteRules(spec["rules"], extra_sources, extra_outputs)
218
+
219
+ if "copies" in spec:
220
+ self.WriteCopies(spec["copies"], extra_outputs)
221
+
222
+ # GYP generated outputs.
223
+ self.WriteList(extra_outputs, "GYP_GENERATED_OUTPUTS", local_pathify=True)
224
+
225
+ # Set LOCAL_ADDITIONAL_DEPENDENCIES so that Android's build rules depend
226
+ # on both our dependency targets and our generated files.
227
+ self.WriteLn("# Make sure our deps and generated files are built first.")
228
+ self.WriteLn(
229
+ "LOCAL_ADDITIONAL_DEPENDENCIES := $(GYP_TARGET_DEPENDENCIES) "
230
+ "$(GYP_GENERATED_OUTPUTS)"
231
+ )
232
+ self.WriteLn()
233
+
234
+ # Sources.
235
+ if spec.get("sources", []) or extra_sources:
236
+ self.WriteSources(spec, configs, extra_sources)
237
+
238
+ self.WriteTarget(
239
+ spec, configs, deps, link_deps, part_of_all, write_alias_target
240
+ )
241
+
242
+ # Update global list of target outputs, used in dependency tracking.
243
+ target_outputs[qualified_target] = ("path", self.output_binary)
244
+
245
+ # Update global list of link dependencies.
246
+ if self.type == "static_library":
247
+ target_link_deps[qualified_target] = ("static", self.android_module)
248
+ elif self.type == "shared_library":
249
+ target_link_deps[qualified_target] = ("shared", self.android_module)
250
+
251
+ self.fp.close()
252
+ return self.android_module
253
+
254
+ def WriteActions(self, actions, extra_sources, extra_outputs):
255
+ """Write Makefile code for any 'actions' from the gyp input.
256
+
257
+ extra_sources: a list that will be filled in with newly generated source
258
+ files, if any
259
+ extra_outputs: a list that will be filled in with any outputs of these
260
+ actions (used to make other pieces dependent on these
261
+ actions)
262
+ """
263
+ for action in actions:
264
+ name = make.StringToMakefileVariable(
265
+ "{}_{}".format(self.relative_target, action["action_name"])
266
+ )
267
+ self.WriteLn('### Rules for action "%s":' % action["action_name"])
268
+ inputs = action["inputs"]
269
+ outputs = action["outputs"]
270
+
271
+ # Build up a list of outputs.
272
+ # Collect the output dirs we'll need.
273
+ dirs = set()
274
+ for out in outputs:
275
+ if not out.startswith("$"):
276
+ print(
277
+ 'WARNING: Action for target "%s" writes output to local path '
278
+ '"%s".' % (self.target, out)
279
+ )
280
+ dir = os.path.split(out)[0]
281
+ if dir:
282
+ dirs.add(dir)
283
+ if int(action.get("process_outputs_as_sources", False)):
284
+ extra_sources += outputs
285
+
286
+ # Prepare the actual command.
287
+ command = gyp.common.EncodePOSIXShellList(action["action"])
288
+ if "message" in action:
289
+ quiet_cmd = "Gyp action: %s ($@)" % action["message"]
290
+ else:
291
+ quiet_cmd = "Gyp action: %s ($@)" % name
292
+ if len(dirs) > 0:
293
+ command = "mkdir -p %s" % " ".join(dirs) + "; " + command
294
+
295
+ cd_action = "cd $(gyp_local_path)/%s; " % self.path
296
+ command = cd_action + command
297
+
298
+ # The makefile rules are all relative to the top dir, but the gyp actions
299
+ # are defined relative to their containing dir. This replaces the gyp_*
300
+ # variables for the action rule with an absolute version so that the
301
+ # output goes in the right place.
302
+ # Only write the gyp_* rules for the "primary" output (:1);
303
+ # it's superfluous for the "extra outputs", and this avoids accidentally
304
+ # writing duplicate dummy rules for those outputs.
305
+ main_output = make.QuoteSpaces(self.LocalPathify(outputs[0]))
306
+ self.WriteLn("%s: gyp_local_path := $(LOCAL_PATH)" % main_output)
307
+ self.WriteLn("%s: gyp_var_prefix := $(GYP_VAR_PREFIX)" % main_output)
308
+ self.WriteLn(
309
+ "%s: gyp_intermediate_dir := "
310
+ "$(abspath $(gyp_intermediate_dir))" % main_output
311
+ )
312
+ self.WriteLn(
313
+ "%s: gyp_shared_intermediate_dir := "
314
+ "$(abspath $(gyp_shared_intermediate_dir))" % main_output
315
+ )
316
+
317
+ # Android's envsetup.sh adds a number of directories to the path including
318
+ # the built host binary directory. This causes actions/rules invoked by
319
+ # gyp to sometimes use these instead of system versions, e.g. bison.
320
+ # The built host binaries may not be suitable, and can cause errors.
321
+ # So, we remove them from the PATH using the ANDROID_BUILD_PATHS variable
322
+ # set by envsetup.
323
+ self.WriteLn(
324
+ "%s: export PATH := $(subst $(ANDROID_BUILD_PATHS),,$(PATH))"
325
+ % main_output
326
+ )
327
+
328
+ # Don't allow spaces in input/output filenames, but make an exception for
329
+ # filenames which start with '$(' since it's okay for there to be spaces
330
+ # inside of make function/macro invocations.
331
+ for input in inputs:
332
+ if not input.startswith("$(") and " " in input:
333
+ raise gyp.common.GypError(
334
+ 'Action input filename "%s" in target %s contains a space'
335
+ % (input, self.target)
336
+ )
337
+ for output in outputs:
338
+ if not output.startswith("$(") and " " in output:
339
+ raise gyp.common.GypError(
340
+ 'Action output filename "%s" in target %s contains a space'
341
+ % (output, self.target)
342
+ )
343
+
344
+ self.WriteLn(
345
+ "%s: %s $(GYP_TARGET_DEPENDENCIES)"
346
+ % (main_output, " ".join(map(self.LocalPathify, inputs)))
347
+ )
348
+ self.WriteLn('\t@echo "%s"' % quiet_cmd)
349
+ self.WriteLn("\t$(hide)%s\n" % command)
350
+ for output in outputs[1:]:
351
+ # Make each output depend on the main output, with an empty command
352
+ # to force make to notice that the mtime has changed.
353
+ self.WriteLn(f"{self.LocalPathify(output)}: {main_output} ;")
354
+
355
+ extra_outputs += outputs
356
+ self.WriteLn()
357
+
358
+ self.WriteLn()
359
+
360
+ def WriteRules(self, rules, extra_sources, extra_outputs):
361
+ """Write Makefile code for any 'rules' from the gyp input.
362
+
363
+ extra_sources: a list that will be filled in with newly generated source
364
+ files, if any
365
+ extra_outputs: a list that will be filled in with any outputs of these
366
+ rules (used to make other pieces dependent on these rules)
367
+ """
368
+ if len(rules) == 0:
369
+ return
370
+
371
+ for rule in rules:
372
+ if len(rule.get("rule_sources", [])) == 0:
373
+ continue
374
+ name = make.StringToMakefileVariable(
375
+ "{}_{}".format(self.relative_target, rule["rule_name"])
376
+ )
377
+ self.WriteLn('\n### Generated for rule "%s":' % name)
378
+ self.WriteLn('# "%s":' % rule)
379
+
380
+ inputs = rule.get("inputs")
381
+ for rule_source in rule.get("rule_sources", []):
382
+ (rule_source_dirname, rule_source_basename) = os.path.split(rule_source)
383
+ (rule_source_root, rule_source_ext) = os.path.splitext(
384
+ rule_source_basename
385
+ )
386
+
387
+ outputs = [
388
+ self.ExpandInputRoot(out, rule_source_root, rule_source_dirname)
389
+ for out in rule["outputs"]
390
+ ]
391
+
392
+ dirs = set()
393
+ for out in outputs:
394
+ if not out.startswith("$"):
395
+ print(
396
+ "WARNING: Rule for target %s writes output to local path %s"
397
+ % (self.target, out)
398
+ )
399
+ dir = os.path.dirname(out)
400
+ if dir:
401
+ dirs.add(dir)
402
+ extra_outputs += outputs
403
+ if int(rule.get("process_outputs_as_sources", False)):
404
+ extra_sources.extend(outputs)
405
+
406
+ components = []
407
+ for component in rule["action"]:
408
+ component = self.ExpandInputRoot(
409
+ component, rule_source_root, rule_source_dirname
410
+ )
411
+ if "$(RULE_SOURCES)" in component:
412
+ component = component.replace("$(RULE_SOURCES)", rule_source)
413
+ components.append(component)
414
+
415
+ command = gyp.common.EncodePOSIXShellList(components)
416
+ cd_action = "cd $(gyp_local_path)/%s; " % self.path
417
+ command = cd_action + command
418
+ if dirs:
419
+ command = "mkdir -p %s" % " ".join(dirs) + "; " + command
420
+
421
+ # We set up a rule to build the first output, and then set up
422
+ # a rule for each additional output to depend on the first.
423
+ outputs = map(self.LocalPathify, outputs)
424
+ main_output = outputs[0]
425
+ self.WriteLn("%s: gyp_local_path := $(LOCAL_PATH)" % main_output)
426
+ self.WriteLn("%s: gyp_var_prefix := $(GYP_VAR_PREFIX)" % main_output)
427
+ self.WriteLn(
428
+ "%s: gyp_intermediate_dir := "
429
+ "$(abspath $(gyp_intermediate_dir))" % main_output
430
+ )
431
+ self.WriteLn(
432
+ "%s: gyp_shared_intermediate_dir := "
433
+ "$(abspath $(gyp_shared_intermediate_dir))" % main_output
434
+ )
435
+
436
+ # See explanation in WriteActions.
437
+ self.WriteLn(
438
+ "%s: export PATH := "
439
+ "$(subst $(ANDROID_BUILD_PATHS),,$(PATH))" % main_output
440
+ )
441
+
442
+ main_output_deps = self.LocalPathify(rule_source)
443
+ if inputs:
444
+ main_output_deps += " "
445
+ main_output_deps += " ".join([self.LocalPathify(f) for f in inputs])
446
+
447
+ self.WriteLn(
448
+ "%s: %s $(GYP_TARGET_DEPENDENCIES)"
449
+ % (main_output, main_output_deps)
450
+ )
451
+ self.WriteLn("\t%s\n" % command)
452
+ for output in outputs[1:]:
453
+ # Make each output depend on the main output, with an empty command
454
+ # to force make to notice that the mtime has changed.
455
+ self.WriteLn(f"{output}: {main_output} ;")
456
+ self.WriteLn()
457
+
458
+ self.WriteLn()
459
+
460
+ def WriteCopies(self, copies, extra_outputs):
461
+ """Write Makefile code for any 'copies' from the gyp input.
462
+
463
+ extra_outputs: a list that will be filled in with any outputs of this action
464
+ (used to make other pieces dependent on this action)
465
+ """
466
+ self.WriteLn("### Generated for copy rule.")
467
+
468
+ variable = make.StringToMakefileVariable(self.relative_target + "_copies")
469
+ outputs = []
470
+ for copy in copies:
471
+ for path in copy["files"]:
472
+ # The Android build system does not allow generation of files into the
473
+ # source tree. The destination should start with a variable, which will
474
+ # typically be $(gyp_intermediate_dir) or
475
+ # $(gyp_shared_intermediate_dir). Note that we can't use an assertion
476
+ # because some of the gyp tests depend on this.
477
+ if not copy["destination"].startswith("$"):
478
+ print(
479
+ "WARNING: Copy rule for target %s writes output to "
480
+ "local path %s" % (self.target, copy["destination"])
481
+ )
482
+
483
+ # LocalPathify() calls normpath, stripping trailing slashes.
484
+ path = Sourceify(self.LocalPathify(path))
485
+ filename = os.path.split(path)[1]
486
+ output = Sourceify(
487
+ self.LocalPathify(os.path.join(copy["destination"], filename))
488
+ )
489
+
490
+ self.WriteLn(f"{output}: {path} $(GYP_TARGET_DEPENDENCIES) | $(ACP)")
491
+ self.WriteLn("\t@echo Copying: $@")
492
+ self.WriteLn("\t$(hide) mkdir -p $(dir $@)")
493
+ self.WriteLn("\t$(hide) $(ACP) -rpf $< $@")
494
+ self.WriteLn()
495
+ outputs.append(output)
496
+ self.WriteLn(
497
+ "{} = {}".format(variable, " ".join(map(make.QuoteSpaces, outputs)))
498
+ )
499
+ extra_outputs.append("$(%s)" % variable)
500
+ self.WriteLn()
501
+
502
+ def WriteSourceFlags(self, spec, configs):
503
+ """Write out the flags and include paths used to compile source files for
504
+ the current target.
505
+
506
+ Args:
507
+ spec, configs: input from gyp.
508
+ """
509
+ for configname, config in sorted(configs.items()):
510
+ extracted_includes = []
511
+
512
+ self.WriteLn("\n# Flags passed to both C and C++ files.")
513
+ cflags, includes_from_cflags = self.ExtractIncludesFromCFlags(
514
+ config.get("cflags", []) + config.get("cflags_c", [])
515
+ )
516
+ extracted_includes.extend(includes_from_cflags)
517
+ self.WriteList(cflags, "MY_CFLAGS_%s" % configname)
518
+
519
+ self.WriteList(
520
+ config.get("defines"),
521
+ "MY_DEFS_%s" % configname,
522
+ prefix="-D",
523
+ quoter=make.EscapeCppDefine,
524
+ )
525
+
526
+ self.WriteLn("\n# Include paths placed before CFLAGS/CPPFLAGS")
527
+ includes = list(config.get("include_dirs", []))
528
+ includes.extend(extracted_includes)
529
+ includes = map(Sourceify, map(self.LocalPathify, includes))
530
+ includes = self.NormalizeIncludePaths(includes)
531
+ self.WriteList(includes, "LOCAL_C_INCLUDES_%s" % configname)
532
+
533
+ self.WriteLn("\n# Flags passed to only C++ (and not C) files.")
534
+ self.WriteList(config.get("cflags_cc"), "LOCAL_CPPFLAGS_%s" % configname)
535
+
536
+ self.WriteLn(
537
+ "\nLOCAL_CFLAGS := $(MY_CFLAGS_$(GYP_CONFIGURATION)) "
538
+ "$(MY_DEFS_$(GYP_CONFIGURATION))"
539
+ )
540
+ # Undefine ANDROID for host modules
541
+ # TODO: the source code should not use macro ANDROID to tell if it's host
542
+ # or target module.
543
+ if self.toolset == "host":
544
+ self.WriteLn("# Undefine ANDROID for host modules")
545
+ self.WriteLn("LOCAL_CFLAGS += -UANDROID")
546
+ self.WriteLn(
547
+ "LOCAL_C_INCLUDES := $(GYP_COPIED_SOURCE_ORIGIN_DIRS) "
548
+ "$(LOCAL_C_INCLUDES_$(GYP_CONFIGURATION))"
549
+ )
550
+ self.WriteLn("LOCAL_CPPFLAGS := $(LOCAL_CPPFLAGS_$(GYP_CONFIGURATION))")
551
+ # Android uses separate flags for assembly file invocations, but gyp expects
552
+ # the same CFLAGS to be applied:
553
+ self.WriteLn("LOCAL_ASFLAGS := $(LOCAL_CFLAGS)")
554
+
555
+ def WriteSources(self, spec, configs, extra_sources):
556
+ """Write Makefile code for any 'sources' from the gyp input.
557
+ These are source files necessary to build the current target.
558
+ We need to handle shared_intermediate directory source files as
559
+ a special case by copying them to the intermediate directory and
560
+ treating them as a generated sources. Otherwise the Android build
561
+ rules won't pick them up.
562
+
563
+ Args:
564
+ spec, configs: input from gyp.
565
+ extra_sources: Sources generated from Actions or Rules.
566
+ """
567
+ sources = filter(make.Compilable, spec.get("sources", []))
568
+ generated_not_sources = [x for x in extra_sources if not make.Compilable(x)]
569
+ extra_sources = filter(make.Compilable, extra_sources)
570
+
571
+ # Determine and output the C++ extension used by these sources.
572
+ # We simply find the first C++ file and use that extension.
573
+ all_sources = sources + extra_sources
574
+ local_cpp_extension = ".cpp"
575
+ for source in all_sources:
576
+ (root, ext) = os.path.splitext(source)
577
+ if IsCPPExtension(ext):
578
+ local_cpp_extension = ext
579
+ break
580
+ if local_cpp_extension != ".cpp":
581
+ self.WriteLn("LOCAL_CPP_EXTENSION := %s" % local_cpp_extension)
582
+
583
+ # We need to move any non-generated sources that are coming from the
584
+ # shared intermediate directory out of LOCAL_SRC_FILES and put them
585
+ # into LOCAL_GENERATED_SOURCES. We also need to move over any C++ files
586
+ # that don't match our local_cpp_extension, since Android will only
587
+ # generate Makefile rules for a single LOCAL_CPP_EXTENSION.
588
+ local_files = []
589
+ for source in sources:
590
+ (root, ext) = os.path.splitext(source)
591
+ if ("$(gyp_shared_intermediate_dir)" in source
592
+ or "$(gyp_intermediate_dir)" in source
593
+ or (IsCPPExtension(ext) and ext != local_cpp_extension)
594
+ ):
595
+ extra_sources.append(source)
596
+ else:
597
+ local_files.append(os.path.normpath(os.path.join(self.path, source)))
598
+
599
+ # For any generated source, if it is coming from the shared intermediate
600
+ # directory then we add a Make rule to copy them to the local intermediate
601
+ # directory first. This is because the Android LOCAL_GENERATED_SOURCES
602
+ # must be in the local module intermediate directory for the compile rules
603
+ # to work properly. If the file has the wrong C++ extension, then we add
604
+ # a rule to copy that to intermediates and use the new version.
605
+ final_generated_sources = []
606
+ # If a source file gets copied, we still need to add the original source
607
+ # directory as header search path, for GCC searches headers in the
608
+ # directory that contains the source file by default.
609
+ origin_src_dirs = []
610
+ for source in extra_sources:
611
+ local_file = source
612
+ if "$(gyp_intermediate_dir)/" not in local_file:
613
+ basename = os.path.basename(local_file)
614
+ local_file = "$(gyp_intermediate_dir)/" + basename
615
+ (root, ext) = os.path.splitext(local_file)
616
+ if IsCPPExtension(ext) and ext != local_cpp_extension:
617
+ local_file = root + local_cpp_extension
618
+ if local_file != source:
619
+ self.WriteLn(f"{local_file}: {self.LocalPathify(source)}")
620
+ self.WriteLn("\tmkdir -p $(@D); cp $< $@")
621
+ origin_src_dirs.append(os.path.dirname(source))
622
+ final_generated_sources.append(local_file)
623
+
624
+ # We add back in all of the non-compilable stuff to make sure that the
625
+ # make rules have dependencies on them.
626
+ final_generated_sources.extend(generated_not_sources)
627
+ self.WriteList(final_generated_sources, "LOCAL_GENERATED_SOURCES")
628
+
629
+ origin_src_dirs = gyp.common.uniquer(origin_src_dirs)
630
+ origin_src_dirs = map(Sourceify, map(self.LocalPathify, origin_src_dirs))
631
+ self.WriteList(origin_src_dirs, "GYP_COPIED_SOURCE_ORIGIN_DIRS")
632
+
633
+ self.WriteList(local_files, "LOCAL_SRC_FILES")
634
+
635
+ # Write out the flags used to compile the source; this must be done last
636
+ # so that GYP_COPIED_SOURCE_ORIGIN_DIRS can be used as an include path.
637
+ self.WriteSourceFlags(spec, configs)
638
+
639
+ def ComputeAndroidModule(self, spec):
640
+ """Return the Android module name used for a gyp spec.
641
+
642
+ We use the complete qualified target name to avoid collisions between
643
+ duplicate targets in different directories. We also add a suffix to
644
+ distinguish gyp-generated module names.
645
+ """
646
+
647
+ if int(spec.get("android_unmangled_name", 0)):
648
+ assert self.type != "shared_library" or self.target.startswith("lib")
649
+ return self.target
650
+
651
+ if self.type == "shared_library":
652
+ # For reasons of convention, the Android build system requires that all
653
+ # shared library modules are named 'libfoo' when generating -l flags.
654
+ prefix = "lib_"
655
+ else:
656
+ prefix = ""
657
+
658
+ if spec["toolset"] == "host":
659
+ suffix = "_$(TARGET_$(GYP_VAR_PREFIX)ARCH)_host_gyp"
660
+ else:
661
+ suffix = "_gyp"
662
+
663
+ if self.path:
664
+ middle = make.StringToMakefileVariable(f"{self.path}_{self.target}")
665
+ else:
666
+ middle = make.StringToMakefileVariable(self.target)
667
+
668
+ return "".join([prefix, middle, suffix])
669
+
670
+ def ComputeOutputParts(self, spec):
671
+ """Return the 'output basename' of a gyp spec, split into filename + ext.
672
+
673
+ Android libraries must be named the same thing as their module name,
674
+ otherwise the linker can't find them, so product_name and so on must be
675
+ ignored if we are building a library, and the "lib" prepending is
676
+ not done for Android.
677
+ """
678
+ assert self.type != "loadable_module" # TODO: not supported?
679
+
680
+ target = spec["target_name"]
681
+ target_prefix = ""
682
+ target_ext = ""
683
+ if self.type == "static_library":
684
+ target = self.ComputeAndroidModule(spec)
685
+ target_ext = ".a"
686
+ elif self.type == "shared_library":
687
+ target = self.ComputeAndroidModule(spec)
688
+ target_ext = ".so"
689
+ elif self.type == "none":
690
+ target_ext = ".stamp"
691
+ elif self.type != "executable":
692
+ print(
693
+ "ERROR: What output file should be generated?",
694
+ "type",
695
+ self.type,
696
+ "target",
697
+ target,
698
+ )
699
+
700
+ if self.type not in {"static_library", "shared_library"}:
701
+ target_prefix = spec.get("product_prefix", target_prefix)
702
+ target = spec.get("product_name", target)
703
+ product_ext = spec.get("product_extension")
704
+ if product_ext:
705
+ target_ext = "." + product_ext
706
+
707
+ target_stem = target_prefix + target
708
+ return (target_stem, target_ext)
709
+
710
+ def ComputeOutputBasename(self, spec):
711
+ """Return the 'output basename' of a gyp spec.
712
+
713
+ E.g., the loadable module 'foobar' in directory 'baz' will produce
714
+ 'libfoobar.so'
715
+ """
716
+ return "".join(self.ComputeOutputParts(spec))
717
+
718
+ def ComputeOutput(self, spec):
719
+ """Return the 'output' (full output path) of a gyp spec.
720
+
721
+ E.g., the loadable module 'foobar' in directory 'baz' will produce
722
+ '$(obj)/baz/libfoobar.so'
723
+ """
724
+ if self.type == "executable":
725
+ # We install host executables into shared_intermediate_dir so they can be
726
+ # run by gyp rules that refer to PRODUCT_DIR.
727
+ path = "$(gyp_shared_intermediate_dir)"
728
+ elif self.type == "shared_library":
729
+ if self.toolset == "host":
730
+ path = "$($(GYP_HOST_VAR_PREFIX)HOST_OUT_INTERMEDIATE_LIBRARIES)"
731
+ else:
732
+ path = "$($(GYP_VAR_PREFIX)TARGET_OUT_INTERMEDIATE_LIBRARIES)"
733
+ # Other targets just get built into their intermediate dir.
734
+ elif self.toolset == "host":
735
+ path = (
736
+ "$(call intermediates-dir-for,%s,%s,true,,"
737
+ "$(GYP_HOST_VAR_PREFIX))"
738
+ % (self.android_class, self.android_module)
739
+ )
740
+ else:
741
+ path = (
742
+ f"$(call intermediates-dir-for,{self.android_class},"
743
+ f"{self.android_module},,,$(GYP_VAR_PREFIX))"
744
+ )
745
+
746
+ assert spec.get("product_dir") is None # TODO: not supported?
747
+ return os.path.join(path, self.ComputeOutputBasename(spec))
748
+
749
+ def NormalizeIncludePaths(self, include_paths):
750
+ """Normalize include_paths.
751
+ Convert absolute paths to relative to the Android top directory.
752
+
753
+ Args:
754
+ include_paths: A list of unprocessed include paths.
755
+ Returns:
756
+ A list of normalized include paths.
757
+ """
758
+ normalized = []
759
+ for path in include_paths:
760
+ if path[0] == "/":
761
+ path = gyp.common.RelativePath(path, self.android_top_dir)
762
+ normalized.append(path)
763
+ return normalized
764
+
765
+ def ExtractIncludesFromCFlags(self, cflags):
766
+ """Extract includes "-I..." out from cflags
767
+
768
+ Args:
769
+ cflags: A list of compiler flags, which may be mixed with "-I.."
770
+ Returns:
771
+ A tuple of lists: (clean_cflags, include_paths). "-I.." is trimmed.
772
+ """
773
+ clean_cflags = []
774
+ include_paths = []
775
+ for flag in cflags:
776
+ if flag.startswith("-I"):
777
+ include_paths.append(flag[2:])
778
+ else:
779
+ clean_cflags.append(flag)
780
+
781
+ return (clean_cflags, include_paths)
782
+
783
+ def FilterLibraries(self, libraries):
784
+ """Filter the 'libraries' key to separate things that shouldn't be ldflags.
785
+
786
+ Library entries that look like filenames should be converted to android
787
+ module names instead of being passed to the linker as flags.
788
+
789
+ Args:
790
+ libraries: the value of spec.get('libraries')
791
+ Returns:
792
+ A tuple (static_lib_modules, dynamic_lib_modules, ldflags)
793
+ """
794
+ static_lib_modules = []
795
+ dynamic_lib_modules = []
796
+ ldflags = []
797
+ for libs in libraries:
798
+ # Libs can have multiple words.
799
+ for lib in libs.split():
800
+ # Filter the system libraries, which are added by default by the Android
801
+ # build system.
802
+ if (
803
+ lib == "-lc"
804
+ or lib == "-lstdc++"
805
+ or lib == "-lm"
806
+ or lib.endswith("libgcc.a")
807
+ ):
808
+ continue
809
+ match = re.search(r"([^/]+)\.a$", lib)
810
+ if match:
811
+ static_lib_modules.append(match.group(1))
812
+ continue
813
+ match = re.search(r"([^/]+)\.so$", lib)
814
+ if match:
815
+ dynamic_lib_modules.append(match.group(1))
816
+ continue
817
+ if lib.startswith("-l"):
818
+ ldflags.append(lib)
819
+ return (static_lib_modules, dynamic_lib_modules, ldflags)
820
+
821
+ def ComputeDeps(self, spec):
822
+ """Compute the dependencies of a gyp spec.
823
+
824
+ Returns a tuple (deps, link_deps), where each is a list of
825
+ filenames that will need to be put in front of make for either
826
+ building (deps) or linking (link_deps).
827
+ """
828
+ deps = []
829
+ link_deps = []
830
+ if "dependencies" in spec:
831
+ deps.extend(
832
+ [
833
+ target_outputs[dep]
834
+ for dep in spec["dependencies"]
835
+ if target_outputs[dep]
836
+ ]
837
+ )
838
+ for dep in spec["dependencies"]:
839
+ if dep in target_link_deps:
840
+ link_deps.append(target_link_deps[dep])
841
+ deps.extend(link_deps)
842
+ return (gyp.common.uniquer(deps), gyp.common.uniquer(link_deps))
843
+
844
+ def WriteTargetFlags(self, spec, configs, link_deps):
845
+ """Write Makefile code to specify the link flags and library dependencies.
846
+
847
+ spec, configs: input from gyp.
848
+ link_deps: link dependency list; see ComputeDeps()
849
+ """
850
+ # Libraries (i.e. -lfoo)
851
+ # These must be included even for static libraries as some of them provide
852
+ # implicit include paths through the build system.
853
+ libraries = gyp.common.uniquer(spec.get("libraries", []))
854
+ static_libs, dynamic_libs, ldflags_libs = self.FilterLibraries(libraries)
855
+
856
+ if self.type != "static_library":
857
+ for configname, config in sorted(configs.items()):
858
+ ldflags = list(config.get("ldflags", []))
859
+ self.WriteLn("")
860
+ self.WriteList(ldflags, "LOCAL_LDFLAGS_%s" % configname)
861
+ self.WriteList(ldflags_libs, "LOCAL_GYP_LIBS")
862
+ self.WriteLn(
863
+ "LOCAL_LDFLAGS := $(LOCAL_LDFLAGS_$(GYP_CONFIGURATION)) "
864
+ "$(LOCAL_GYP_LIBS)"
865
+ )
866
+
867
+ # Link dependencies (i.e. other gyp targets this target depends on)
868
+ # These need not be included for static libraries as within the gyp build
869
+ # we do not use the implicit include path mechanism.
870
+ if self.type != "static_library":
871
+ static_link_deps = [x[1] for x in link_deps if x[0] == "static"]
872
+ shared_link_deps = [x[1] for x in link_deps if x[0] == "shared"]
873
+ else:
874
+ static_link_deps = []
875
+ shared_link_deps = []
876
+
877
+ # Only write the lists if they are non-empty.
878
+ if static_libs or static_link_deps:
879
+ self.WriteLn("")
880
+ self.WriteList(static_libs + static_link_deps, "LOCAL_STATIC_LIBRARIES")
881
+ self.WriteLn("# Enable grouping to fix circular references")
882
+ self.WriteLn("LOCAL_GROUP_STATIC_LIBRARIES := true")
883
+ if dynamic_libs or shared_link_deps:
884
+ self.WriteLn("")
885
+ self.WriteList(dynamic_libs + shared_link_deps, "LOCAL_SHARED_LIBRARIES")
886
+
887
+ def WriteTarget(
888
+ self, spec, configs, deps, link_deps, part_of_all, write_alias_target
889
+ ):
890
+ """Write Makefile code to produce the final target of the gyp spec.
891
+
892
+ spec, configs: input from gyp.
893
+ deps, link_deps: dependency lists; see ComputeDeps()
894
+ part_of_all: flag indicating this target is part of 'all'
895
+ write_alias_target: flag indicating whether to create short aliases for this
896
+ target
897
+ """
898
+ self.WriteLn("### Rules for final target.")
899
+
900
+ if self.type != "none":
901
+ self.WriteTargetFlags(spec, configs, link_deps)
902
+
903
+ settings = spec.get("aosp_build_settings", {})
904
+ if settings:
905
+ self.WriteLn("### Set directly by aosp_build_settings.")
906
+ for k, v in settings.items():
907
+ if isinstance(v, list):
908
+ self.WriteList(v, k)
909
+ else:
910
+ self.WriteLn(f"{k} := {make.QuoteIfNecessary(v)}")
911
+ self.WriteLn("")
912
+
913
+ # Add to the set of targets which represent the gyp 'all' target. We use the
914
+ # name 'gyp_all_modules' as the Android build system doesn't allow the use
915
+ # of the Make target 'all' and because 'all_modules' is the equivalent of
916
+ # the Make target 'all' on Android.
917
+ if part_of_all and write_alias_target:
918
+ self.WriteLn('# Add target alias to "gyp_all_modules" target.')
919
+ self.WriteLn(".PHONY: gyp_all_modules")
920
+ self.WriteLn("gyp_all_modules: %s" % self.android_module)
921
+ self.WriteLn("")
922
+
923
+ # Add an alias from the gyp target name to the Android module name. This
924
+ # simplifies manual builds of the target, and is required by the test
925
+ # framework.
926
+ if self.target != self.android_module and write_alias_target:
927
+ self.WriteLn("# Alias gyp target name.")
928
+ self.WriteLn(".PHONY: %s" % self.target)
929
+ self.WriteLn(f"{self.target}: {self.android_module}")
930
+ self.WriteLn("")
931
+
932
+ # Add the command to trigger build of the target type depending
933
+ # on the toolset. Ex: BUILD_STATIC_LIBRARY vs. BUILD_HOST_STATIC_LIBRARY
934
+ # NOTE: This has to come last!
935
+ modifier = ""
936
+ if self.toolset == "host":
937
+ modifier = "HOST_"
938
+ if self.type == "static_library":
939
+ self.WriteLn("include $(BUILD_%sSTATIC_LIBRARY)" % modifier)
940
+ elif self.type == "shared_library":
941
+ self.WriteLn("LOCAL_PRELINK_MODULE := false")
942
+ self.WriteLn("include $(BUILD_%sSHARED_LIBRARY)" % modifier)
943
+ elif self.type == "executable":
944
+ self.WriteLn("LOCAL_CXX_STL := libc++_static")
945
+ # Executables are for build and test purposes only, so they're installed
946
+ # to a directory that doesn't get included in the system image.
947
+ self.WriteLn("LOCAL_MODULE_PATH := $(gyp_shared_intermediate_dir)")
948
+ self.WriteLn("include $(BUILD_%sEXECUTABLE)" % modifier)
949
+ else:
950
+ self.WriteLn("LOCAL_MODULE_PATH := $(PRODUCT_OUT)/gyp_stamp")
951
+ self.WriteLn("LOCAL_UNINSTALLABLE_MODULE := true")
952
+ if self.toolset == "target":
953
+ self.WriteLn("LOCAL_2ND_ARCH_VAR_PREFIX := $(GYP_VAR_PREFIX)")
954
+ else:
955
+ self.WriteLn("LOCAL_2ND_ARCH_VAR_PREFIX := $(GYP_HOST_VAR_PREFIX)")
956
+ self.WriteLn()
957
+ self.WriteLn("include $(BUILD_SYSTEM)/base_rules.mk")
958
+ self.WriteLn()
959
+ self.WriteLn("$(LOCAL_BUILT_MODULE): $(LOCAL_ADDITIONAL_DEPENDENCIES)")
960
+ self.WriteLn('\t$(hide) echo "Gyp timestamp: $@"')
961
+ self.WriteLn("\t$(hide) mkdir -p $(dir $@)")
962
+ self.WriteLn("\t$(hide) touch $@")
963
+ self.WriteLn()
964
+ self.WriteLn("LOCAL_2ND_ARCH_VAR_PREFIX :=")
965
+
966
+ def WriteList(
967
+ self,
968
+ value_list,
969
+ variable=None,
970
+ prefix="",
971
+ quoter=make.QuoteIfNecessary,
972
+ local_pathify=False,
973
+ ):
974
+ """Write a variable definition that is a list of values.
975
+
976
+ E.g. WriteList(['a','b'], 'foo', prefix='blah') writes out
977
+ foo = blaha blahb
978
+ but in a pretty-printed style.
979
+ """
980
+ values = ""
981
+ if value_list:
982
+ value_list = [quoter(prefix + value) for value in value_list]
983
+ if local_pathify:
984
+ value_list = [self.LocalPathify(value) for value in value_list]
985
+ values = " \\\n\t" + " \\\n\t".join(value_list)
986
+ self.fp.write(f"{variable} :={values}\n\n")
987
+
988
+ def WriteLn(self, text=""):
989
+ self.fp.write(text + "\n")
990
+
991
+ def LocalPathify(self, path):
992
+ """Convert a subdirectory-relative path into a normalized path which starts
993
+ with the make variable $(LOCAL_PATH) (i.e. the top of the project tree).
994
+ Absolute paths, or paths that contain variables, are just normalized."""
995
+ if "$(" in path or os.path.isabs(path):
996
+ # path is not a file in the project tree in this case, but calling
997
+ # normpath is still important for trimming trailing slashes.
998
+ return os.path.normpath(path)
999
+ local_path = os.path.join("$(LOCAL_PATH)", self.path, path)
1000
+ local_path = os.path.normpath(local_path)
1001
+ # Check that normalizing the path didn't ../ itself out of $(LOCAL_PATH)
1002
+ # - i.e. that the resulting path is still inside the project tree. The
1003
+ # path may legitimately have ended up containing just $(LOCAL_PATH), though,
1004
+ # so we don't look for a slash.
1005
+ assert local_path.startswith(
1006
+ "$(LOCAL_PATH)"
1007
+ ), f"Path {path} attempts to escape from gyp path {self.path} !)"
1008
+ return local_path
1009
+
1010
+ def ExpandInputRoot(self, template, expansion, dirname):
1011
+ if "%(INPUT_ROOT)s" not in template and "%(INPUT_DIRNAME)s" not in template:
1012
+ return template
1013
+ path = template % {
1014
+ "INPUT_ROOT": expansion,
1015
+ "INPUT_DIRNAME": dirname,
1016
+ }
1017
+ return os.path.normpath(path)
1018
+
1019
+
1020
+ def PerformBuild(data, configurations, params):
1021
+ # The android backend only supports the default configuration.
1022
+ options = params["options"]
1023
+ makefile = os.path.abspath(os.path.join(options.toplevel_dir, "GypAndroid.mk"))
1024
+ env = dict(os.environ)
1025
+ env["ONE_SHOT_MAKEFILE"] = makefile
1026
+ arguments = ["make", "-C", os.environ["ANDROID_BUILD_TOP"], "gyp_all_modules"]
1027
+ print("Building: %s" % arguments)
1028
+ subprocess.check_call(arguments, env=env)
1029
+
1030
+
1031
+ def GenerateOutput(target_list, target_dicts, data, params):
1032
+ options = params["options"]
1033
+ generator_flags = params.get("generator_flags", {})
1034
+ limit_to_target_all = generator_flags.get("limit_to_target_all", False)
1035
+ write_alias_targets = generator_flags.get("write_alias_targets", True)
1036
+ sdk_version = generator_flags.get("aosp_sdk_version", 0)
1037
+ android_top_dir = os.environ.get("ANDROID_BUILD_TOP")
1038
+ assert android_top_dir, "$ANDROID_BUILD_TOP not set; you need to run lunch."
1039
+
1040
+ def CalculateMakefilePath(build_file, base_name):
1041
+ """Determine where to write a Makefile for a given gyp file."""
1042
+ # Paths in gyp files are relative to the .gyp file, but we want
1043
+ # paths relative to the source root for the master makefile. Grab
1044
+ # the path of the .gyp file as the base to relativize against.
1045
+ # E.g. "foo/bar" when we're constructing targets for "foo/bar/baz.gyp".
1046
+ base_path = gyp.common.RelativePath(os.path.dirname(build_file), options.depth)
1047
+ # We write the file in the base_path directory.
1048
+ output_file = os.path.join(options.depth, base_path, base_name)
1049
+ assert (
1050
+ not options.generator_output
1051
+ ), "The Android backend does not support options.generator_output."
1052
+ base_path = gyp.common.RelativePath(
1053
+ os.path.dirname(build_file), options.toplevel_dir
1054
+ )
1055
+ return base_path, output_file
1056
+
1057
+ # TODO: search for the first non-'Default' target. This can go
1058
+ # away when we add verification that all targets have the
1059
+ # necessary configurations.
1060
+ default_configuration = None
1061
+ for target in target_list:
1062
+ spec = target_dicts[target]
1063
+ if spec["default_configuration"] != "Default":
1064
+ default_configuration = spec["default_configuration"]
1065
+ break
1066
+ if not default_configuration:
1067
+ default_configuration = "Default"
1068
+
1069
+ makefile_name = "GypAndroid" + options.suffix + ".mk"
1070
+ makefile_path = os.path.join(options.toplevel_dir, makefile_name)
1071
+ assert (
1072
+ not options.generator_output
1073
+ ), "The Android backend does not support options.generator_output."
1074
+ gyp.common.EnsureDirExists(makefile_path)
1075
+ root_makefile = open(makefile_path, "w")
1076
+
1077
+ root_makefile.write(header)
1078
+
1079
+ # We set LOCAL_PATH just once, here, to the top of the project tree. This
1080
+ # allows all the other paths we use to be relative to the Android.mk file,
1081
+ # as the Android build system expects.
1082
+ root_makefile.write("\nLOCAL_PATH := $(call my-dir)\n")
1083
+
1084
+ # Find the list of targets that derive from the gyp file(s) being built.
1085
+ needed_targets = set()
1086
+ for build_file in params["build_files"]:
1087
+ for target in gyp.common.AllTargets(target_list, target_dicts, build_file):
1088
+ needed_targets.add(target)
1089
+
1090
+ build_files = set()
1091
+ include_list = set()
1092
+ android_modules = {}
1093
+ for qualified_target in target_list:
1094
+ build_file, target, toolset = gyp.common.ParseQualifiedTarget(qualified_target)
1095
+ relative_build_file = gyp.common.RelativePath(build_file, options.toplevel_dir)
1096
+ build_files.add(relative_build_file)
1097
+ included_files = data[build_file]["included_files"]
1098
+ for included_file in included_files:
1099
+ # The included_files entries are relative to the dir of the build file
1100
+ # that included them, so we have to undo that and then make them relative
1101
+ # to the root dir.
1102
+ relative_include_file = gyp.common.RelativePath(
1103
+ gyp.common.UnrelativePath(included_file, build_file),
1104
+ options.toplevel_dir,
1105
+ )
1106
+ abs_include_file = os.path.abspath(relative_include_file)
1107
+ # If the include file is from the ~/.gyp dir, we should use absolute path
1108
+ # so that relocating the src dir doesn't break the path.
1109
+ if params["home_dot_gyp"] and abs_include_file.startswith(
1110
+ params["home_dot_gyp"]
1111
+ ):
1112
+ build_files.add(abs_include_file)
1113
+ else:
1114
+ build_files.add(relative_include_file)
1115
+
1116
+ base_path, output_file = CalculateMakefilePath(
1117
+ build_file, target + "." + toolset + options.suffix + ".mk"
1118
+ )
1119
+
1120
+ spec = target_dicts[qualified_target]
1121
+ configs = spec["configurations"]
1122
+
1123
+ part_of_all = qualified_target in needed_targets
1124
+ if limit_to_target_all and not part_of_all:
1125
+ continue
1126
+
1127
+ relative_target = gyp.common.QualifiedTarget(
1128
+ relative_build_file, target, toolset
1129
+ )
1130
+ writer = AndroidMkWriter(android_top_dir)
1131
+ android_module = writer.Write(
1132
+ qualified_target,
1133
+ relative_target,
1134
+ base_path,
1135
+ output_file,
1136
+ spec,
1137
+ configs,
1138
+ part_of_all=part_of_all,
1139
+ write_alias_target=write_alias_targets,
1140
+ sdk_version=sdk_version,
1141
+ )
1142
+ if android_module in android_modules:
1143
+ print(
1144
+ "ERROR: Android module names must be unique. The following "
1145
+ "targets both generate Android module name %s.\n %s\n %s"
1146
+ % (android_module, android_modules[android_module], qualified_target)
1147
+ )
1148
+ return
1149
+ android_modules[android_module] = qualified_target
1150
+
1151
+ # Our root_makefile lives at the source root. Compute the relative path
1152
+ # from there to the output_file for including.
1153
+ mkfile_rel_path = gyp.common.RelativePath(
1154
+ output_file, os.path.dirname(makefile_path)
1155
+ )
1156
+ include_list.add(mkfile_rel_path)
1157
+
1158
+ root_makefile.write("GYP_CONFIGURATION ?= %s\n" % default_configuration)
1159
+ root_makefile.write("GYP_VAR_PREFIX ?=\n")
1160
+ root_makefile.write("GYP_HOST_VAR_PREFIX ?=\n")
1161
+ root_makefile.write("GYP_HOST_MULTILIB ?= first\n")
1162
+
1163
+ # Write out the sorted list of includes.
1164
+ root_makefile.write("\n")
1165
+ for include_file in sorted(include_list):
1166
+ root_makefile.write("include $(LOCAL_PATH)/" + include_file + "\n")
1167
+ root_makefile.write("\n")
1168
+
1169
+ if write_alias_targets:
1170
+ root_makefile.write(ALL_MODULES_FOOTER)
1171
+
1172
+ root_makefile.close()