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,704 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # Copyright (c) 2012 Google Inc. All rights reserved.
4
+ # Use of this source code is governed by a BSD-style license that can be
5
+ # found in the LICENSE file.
6
+
7
+ from __future__ import annotations
8
+
9
+ import argparse
10
+ import copy
11
+ import os.path
12
+ import re
13
+ import shlex
14
+ import sys
15
+ import traceback
16
+
17
+ import gyp.input
18
+ from gyp.common import GypError
19
+
20
+ # Default debug modes for GYP
21
+ debug = {}
22
+
23
+ # List of "official" debug modes, but you can use anything you like.
24
+ DEBUG_GENERAL = "general"
25
+ DEBUG_VARIABLES = "variables"
26
+ DEBUG_INCLUDES = "includes"
27
+
28
+ def EscapeForCString(string: bytes | str) -> str:
29
+ if isinstance(string, str):
30
+ string = string.encode(encoding='utf8')
31
+
32
+ backslash_or_double_quote = {ord('\\'), ord('"')}
33
+ result = ''
34
+ for char in string:
35
+ if char in backslash_or_double_quote or not 32 <= char < 127:
36
+ result += '\\%03o' % char
37
+ else:
38
+ result += chr(char)
39
+ return result
40
+
41
+ def DebugOutput(mode, message, *args):
42
+ if "all" in gyp.debug or mode in gyp.debug:
43
+ ctx = ("unknown", 0, "unknown")
44
+ try:
45
+ f = traceback.extract_stack(limit=2)
46
+ if f:
47
+ ctx = f[0][:3]
48
+ except Exception:
49
+ pass
50
+ if args:
51
+ message %= args
52
+ print(
53
+ "%s:%s:%d:%s %s"
54
+ % (mode.upper(), os.path.basename(ctx[0]), ctx[1], ctx[2], message)
55
+ )
56
+
57
+
58
+ def FindBuildFiles():
59
+ extension = ".gyp"
60
+ files = os.listdir(os.getcwd())
61
+ build_files = []
62
+ for file in files:
63
+ if file.endswith(extension):
64
+ build_files.append(file)
65
+ return build_files
66
+
67
+
68
+ def Load(
69
+ build_files,
70
+ format,
71
+ default_variables={},
72
+ includes=[],
73
+ depth=".",
74
+ params=None,
75
+ check=False,
76
+ circular_check=True,
77
+ ):
78
+ """
79
+ Loads one or more specified build files.
80
+ default_variables and includes will be copied before use.
81
+ Returns the generator for the specified format and the
82
+ data returned by loading the specified build files.
83
+ """
84
+ if params is None:
85
+ params = {}
86
+
87
+ if "-" in format:
88
+ format, params["flavor"] = format.split("-", 1)
89
+
90
+ default_variables = copy.copy(default_variables)
91
+
92
+ # Default variables provided by this program and its modules should be
93
+ # named WITH_CAPITAL_LETTERS to provide a distinct "best practice" namespace,
94
+ # avoiding collisions with user and automatic variables.
95
+ default_variables["GENERATOR"] = format
96
+ default_variables["GENERATOR_FLAVOR"] = params.get("flavor", "")
97
+
98
+ # Format can be a custom python file, or by default the name of a module
99
+ # within gyp.generator.
100
+ if format.endswith(".py"):
101
+ generator_name = os.path.splitext(format)[0]
102
+ path, generator_name = os.path.split(generator_name)
103
+
104
+ # Make sure the path to the custom generator is in sys.path
105
+ # Don't worry about removing it once we are done. Keeping the path
106
+ # to each generator that is used in sys.path is likely harmless and
107
+ # arguably a good idea.
108
+ path = os.path.abspath(path)
109
+ if path not in sys.path:
110
+ sys.path.insert(0, path)
111
+ else:
112
+ generator_name = "gyp.generator." + format
113
+
114
+ # These parameters are passed in order (as opposed to by key)
115
+ # because ActivePython cannot handle key parameters to __import__.
116
+ generator = __import__(generator_name, globals(), locals(), generator_name)
117
+ for (key, val) in generator.generator_default_variables.items():
118
+ default_variables.setdefault(key, val)
119
+
120
+ output_dir = params["options"].generator_output or params["options"].toplevel_dir
121
+ if default_variables["GENERATOR"] == "ninja":
122
+ product_dir_abs = os.path.join(
123
+ output_dir, "out", default_variables.get("build_type", "default")
124
+ )
125
+ else:
126
+ product_dir_abs = os.path.join(
127
+ output_dir, default_variables["CONFIGURATION_NAME"]
128
+ )
129
+
130
+ default_variables.setdefault("PRODUCT_DIR_ABS", product_dir_abs)
131
+ default_variables.setdefault(
132
+ "PRODUCT_DIR_ABS_CSTR", EscapeForCString(product_dir_abs)
133
+ )
134
+
135
+ # Give the generator the opportunity to set additional variables based on
136
+ # the params it will receive in the output phase.
137
+ if getattr(generator, "CalculateVariables", None):
138
+ generator.CalculateVariables(default_variables, params)
139
+
140
+ # Give the generator the opportunity to set generator_input_info based on
141
+ # the params it will receive in the output phase.
142
+ if getattr(generator, "CalculateGeneratorInputInfo", None):
143
+ generator.CalculateGeneratorInputInfo(params)
144
+
145
+ # Fetch the generator specific info that gets fed to input, we use getattr
146
+ # so we can default things and the generators only have to provide what
147
+ # they need.
148
+ generator_input_info = {
149
+ "non_configuration_keys": getattr(
150
+ generator, "generator_additional_non_configuration_keys", []
151
+ ),
152
+ "path_sections": getattr(generator, "generator_additional_path_sections", []),
153
+ "extra_sources_for_rules": getattr(
154
+ generator, "generator_extra_sources_for_rules", []
155
+ ),
156
+ "generator_supports_multiple_toolsets": getattr(
157
+ generator, "generator_supports_multiple_toolsets", False
158
+ ),
159
+ "generator_wants_static_library_dependencies_adjusted": getattr(
160
+ generator, "generator_wants_static_library_dependencies_adjusted", True
161
+ ),
162
+ "generator_wants_sorted_dependencies": getattr(
163
+ generator, "generator_wants_sorted_dependencies", False
164
+ ),
165
+ "generator_filelist_paths": getattr(
166
+ generator, "generator_filelist_paths", None
167
+ ),
168
+ }
169
+
170
+ # Process the input specific to this generator.
171
+ result = gyp.input.Load(
172
+ build_files,
173
+ default_variables,
174
+ includes[:],
175
+ depth,
176
+ generator_input_info,
177
+ check,
178
+ circular_check,
179
+ params["parallel"],
180
+ params["root_targets"],
181
+ )
182
+ return [generator] + result
183
+
184
+
185
+ def NameValueListToDict(name_value_list):
186
+ """
187
+ Takes an array of strings of the form 'NAME=VALUE' and creates a dictionary
188
+ of the pairs. If a string is simply NAME, then the value in the dictionary
189
+ is set to True. If VALUE can be converted to an integer, it is.
190
+ """
191
+ result = {}
192
+ for item in name_value_list:
193
+ tokens = item.split("=", 1)
194
+ if len(tokens) == 2:
195
+ # If we can make it an int, use that, otherwise, use the string.
196
+ try:
197
+ token_value = int(tokens[1])
198
+ except ValueError:
199
+ token_value = tokens[1]
200
+ # Set the variable to the supplied value.
201
+ result[tokens[0]] = token_value
202
+ else:
203
+ # No value supplied, treat it as a boolean and set it.
204
+ result[tokens[0]] = True
205
+ return result
206
+
207
+
208
+ def ShlexEnv(env_name):
209
+ if flags := os.environ.get(env_name) or []:
210
+ flags = shlex.split(flags)
211
+ return flags
212
+
213
+
214
+ def FormatOpt(opt, value):
215
+ if opt.startswith("--"):
216
+ return f"{opt}={value}"
217
+ return opt + value
218
+
219
+
220
+ def RegenerateAppendFlag(flag, values, predicate, env_name, options):
221
+ """Regenerate a list of command line flags, for an option of action='append'.
222
+
223
+ The |env_name|, if given, is checked in the environment and used to generate
224
+ an initial list of options, then the options that were specified on the
225
+ command line (given in |values|) are appended. This matches the handling of
226
+ environment variables and command line flags where command line flags override
227
+ the environment, while not requiring the environment to be set when the flags
228
+ are used again.
229
+ """
230
+ flags = []
231
+ if options.use_environment and env_name:
232
+ for flag_value in ShlexEnv(env_name):
233
+ value = FormatOpt(flag, predicate(flag_value))
234
+ if value in flags:
235
+ flags.remove(value)
236
+ flags.append(value)
237
+ if values:
238
+ for flag_value in values:
239
+ flags.append(FormatOpt(flag, predicate(flag_value)))
240
+ return flags
241
+
242
+
243
+ def RegenerateFlags(options):
244
+ """Given a parsed options object, and taking the environment variables into
245
+ account, returns a list of flags that should regenerate an equivalent options
246
+ object (even in the absence of the environment variables.)
247
+
248
+ Any path options will be normalized relative to depth.
249
+
250
+ The format flag is not included, as it is assumed the calling generator will
251
+ set that as appropriate.
252
+ """
253
+
254
+ def FixPath(path):
255
+ path = gyp.common.FixIfRelativePath(path, options.depth)
256
+ if not path:
257
+ return os.path.curdir
258
+ return path
259
+
260
+ def Noop(value):
261
+ return value
262
+
263
+ # We always want to ignore the environment when regenerating, to avoid
264
+ # duplicate or changed flags in the environment at the time of regeneration.
265
+ flags = ["--ignore-environment"]
266
+ for name, metadata in options._regeneration_metadata.items():
267
+ opt = metadata["opt"]
268
+ value = getattr(options, name)
269
+ value_predicate = (metadata["type"] == "path" and FixPath) or Noop
270
+ action = metadata["action"]
271
+ env_name = metadata["env_name"]
272
+ if action == "append":
273
+ flags.extend(
274
+ RegenerateAppendFlag(opt, value, value_predicate, env_name, options)
275
+ )
276
+ elif action in ("store", None): # None is a synonym for 'store'.
277
+ if value:
278
+ flags.append(FormatOpt(opt, value_predicate(value)))
279
+ elif options.use_environment and env_name and os.environ.get(env_name):
280
+ flags.append(FormatOpt(opt, value_predicate(os.environ.get(env_name))))
281
+ elif action in ("store_true", "store_false"):
282
+ if (action == "store_true" and value) or (
283
+ action == "store_false" and not value
284
+ ):
285
+ flags.append(opt)
286
+ elif options.use_environment and env_name:
287
+ print(
288
+ "Warning: environment regeneration unimplemented "
289
+ "for %s flag %r env_name %r" % (action, opt, env_name),
290
+ file=sys.stderr,
291
+ )
292
+ else:
293
+ print(
294
+ "Warning: regeneration unimplemented for action %r "
295
+ "flag %r" % (action, opt),
296
+ file=sys.stderr,
297
+ )
298
+
299
+ return flags
300
+
301
+
302
+ class RegeneratableOptionParser(argparse.ArgumentParser):
303
+ def __init__(self, usage):
304
+ self.__regeneratable_options = {}
305
+ argparse.ArgumentParser.__init__(self, usage=usage)
306
+
307
+ def add_argument(self, *args, **kw):
308
+ """Add an option to the parser.
309
+
310
+ This accepts the same arguments as ArgumentParser.add_argument, plus the
311
+ following:
312
+ regenerate: can be set to False to prevent this option from being included
313
+ in regeneration.
314
+ env_name: name of environment variable that additional values for this
315
+ option come from.
316
+ type: adds type='path', to tell the regenerator that the values of
317
+ this option need to be made relative to options.depth
318
+ """
319
+ env_name = kw.pop("env_name", None)
320
+ if "dest" in kw and kw.pop("regenerate", True):
321
+ dest = kw["dest"]
322
+
323
+ # The path type is needed for regenerating, for optparse we can just treat
324
+ # it as a string.
325
+ type = kw.get("type")
326
+ if type == "path":
327
+ kw["type"] = str
328
+
329
+ self.__regeneratable_options[dest] = {
330
+ "action": kw.get("action"),
331
+ "type": type,
332
+ "env_name": env_name,
333
+ "opt": args[0],
334
+ }
335
+
336
+ argparse.ArgumentParser.add_argument(self, *args, **kw)
337
+
338
+ def parse_args(self, *args):
339
+ values, args = argparse.ArgumentParser.parse_known_args(self, *args)
340
+ values._regeneration_metadata = self.__regeneratable_options
341
+ return values, args
342
+
343
+
344
+ def gyp_main(args):
345
+ my_name = os.path.basename(sys.argv[0])
346
+ usage = "usage: %(prog)s [options ...] [build_file ...]"
347
+
348
+ parser = RegeneratableOptionParser(usage=usage.replace("%s", "%(prog)s"))
349
+ parser.add_argument(
350
+ "--build",
351
+ dest="configs",
352
+ action="append",
353
+ help="configuration for build after project generation",
354
+ )
355
+ parser.add_argument(
356
+ "--check", dest="check", action="store_true", help="check format of gyp files"
357
+ )
358
+ parser.add_argument(
359
+ "--config-dir",
360
+ dest="config_dir",
361
+ action="store",
362
+ env_name="GYP_CONFIG_DIR",
363
+ default=None,
364
+ help="The location for configuration files like include.gypi.",
365
+ )
366
+ parser.add_argument(
367
+ "-d",
368
+ "--debug",
369
+ dest="debug",
370
+ metavar="DEBUGMODE",
371
+ action="append",
372
+ default=[],
373
+ help="turn on a debugging "
374
+ 'mode for debugging GYP. Supported modes are "variables", '
375
+ '"includes" and "general" or "all" for all of them.',
376
+ )
377
+ parser.add_argument(
378
+ "-D",
379
+ dest="defines",
380
+ action="append",
381
+ metavar="VAR=VAL",
382
+ env_name="GYP_DEFINES",
383
+ help="sets variable VAR to value VAL",
384
+ )
385
+ parser.add_argument(
386
+ "--depth",
387
+ dest="depth",
388
+ metavar="PATH",
389
+ type="path",
390
+ help="set DEPTH gyp variable to a relative path to PATH",
391
+ )
392
+ parser.add_argument(
393
+ "-f",
394
+ "--format",
395
+ dest="formats",
396
+ action="append",
397
+ env_name="GYP_GENERATORS",
398
+ regenerate=False,
399
+ help="output formats to generate",
400
+ )
401
+ parser.add_argument(
402
+ "-G",
403
+ dest="generator_flags",
404
+ action="append",
405
+ default=[],
406
+ metavar="FLAG=VAL",
407
+ env_name="GYP_GENERATOR_FLAGS",
408
+ help="sets generator flag FLAG to VAL",
409
+ )
410
+ parser.add_argument(
411
+ "--generator-output",
412
+ dest="generator_output",
413
+ action="store",
414
+ default=None,
415
+ metavar="DIR",
416
+ type="path",
417
+ env_name="GYP_GENERATOR_OUTPUT",
418
+ help="puts generated build files under DIR",
419
+ )
420
+ parser.add_argument(
421
+ "--ignore-environment",
422
+ dest="use_environment",
423
+ action="store_false",
424
+ default=True,
425
+ regenerate=False,
426
+ help="do not read options from environment variables",
427
+ )
428
+ parser.add_argument(
429
+ "-I",
430
+ "--include",
431
+ dest="includes",
432
+ action="append",
433
+ metavar="INCLUDE",
434
+ type="path",
435
+ help="files to include in all loaded .gyp files",
436
+ )
437
+ # --no-circular-check disables the check for circular relationships between
438
+ # .gyp files. These relationships should not exist, but they've only been
439
+ # observed to be harmful with the Xcode generator. Chromium's .gyp files
440
+ # currently have some circular relationships on non-Mac platforms, so this
441
+ # option allows the strict behavior to be used on Macs and the lenient
442
+ # behavior to be used elsewhere.
443
+ # TODO(mark): Remove this option when http://crbug.com/35878 is fixed.
444
+ parser.add_argument(
445
+ "--no-circular-check",
446
+ dest="circular_check",
447
+ action="store_false",
448
+ default=True,
449
+ regenerate=False,
450
+ help="don't check for circular relationships between files",
451
+ )
452
+ parser.add_argument(
453
+ "--no-parallel",
454
+ action="store_true",
455
+ default=False,
456
+ help="Disable multiprocessing",
457
+ )
458
+ parser.add_argument(
459
+ "-S",
460
+ "--suffix",
461
+ dest="suffix",
462
+ default="",
463
+ help="suffix to add to generated files",
464
+ )
465
+ parser.add_argument(
466
+ "--toplevel-dir",
467
+ dest="toplevel_dir",
468
+ action="store",
469
+ default=None,
470
+ metavar="DIR",
471
+ type="path",
472
+ help="directory to use as the root of the source tree",
473
+ )
474
+ parser.add_argument(
475
+ "-R",
476
+ "--root-target",
477
+ dest="root_targets",
478
+ action="append",
479
+ metavar="TARGET",
480
+ help="include only TARGET and its deep dependencies",
481
+ )
482
+ parser.add_argument(
483
+ "-V",
484
+ "--version",
485
+ dest="version",
486
+ action="store_true",
487
+ help="Show the version and exit.",
488
+ )
489
+
490
+ options, build_files_arg = parser.parse_args(args)
491
+ if options.version:
492
+ import pkg_resources
493
+ print(f"v{pkg_resources.get_distribution('gyp-next').version}")
494
+ return 0
495
+ build_files = build_files_arg
496
+
497
+ # Set up the configuration directory (defaults to ~/.gyp)
498
+ if not options.config_dir:
499
+ home = None
500
+ home_dot_gyp = None
501
+ if options.use_environment:
502
+ home_dot_gyp = os.environ.get("GYP_CONFIG_DIR", None)
503
+ if home_dot_gyp:
504
+ home_dot_gyp = os.path.expanduser(home_dot_gyp)
505
+
506
+ if not home_dot_gyp:
507
+ home_vars = ["HOME"]
508
+ if sys.platform in ("cygwin", "win32"):
509
+ home_vars.append("USERPROFILE")
510
+ for home_var in home_vars:
511
+ home = os.getenv(home_var)
512
+ if home:
513
+ home_dot_gyp = os.path.join(home, ".gyp")
514
+ if not os.path.exists(home_dot_gyp):
515
+ home_dot_gyp = None
516
+ else:
517
+ break
518
+ else:
519
+ home_dot_gyp = os.path.expanduser(options.config_dir)
520
+
521
+ if home_dot_gyp and not os.path.exists(home_dot_gyp):
522
+ home_dot_gyp = None
523
+
524
+ if not options.formats:
525
+ # If no format was given on the command line, then check the env variable.
526
+ generate_formats = []
527
+ if options.use_environment:
528
+ generate_formats = os.environ.get("GYP_GENERATORS") or []
529
+ if generate_formats:
530
+ generate_formats = re.split(r"[\s,]", generate_formats)
531
+ if generate_formats:
532
+ options.formats = generate_formats
533
+ # Nothing in the variable, default based on platform.
534
+ elif sys.platform == "darwin":
535
+ options.formats = ["xcode"]
536
+ elif sys.platform in ("win32", "cygwin"):
537
+ options.formats = ["msvs"]
538
+ else:
539
+ options.formats = ["make"]
540
+
541
+ if not options.generator_output and options.use_environment:
542
+ g_o = os.environ.get("GYP_GENERATOR_OUTPUT")
543
+ if g_o:
544
+ options.generator_output = g_o
545
+
546
+ options.parallel = not options.no_parallel
547
+
548
+ for mode in options.debug:
549
+ gyp.debug[mode] = 1
550
+
551
+ # Do an extra check to avoid work when we're not debugging.
552
+ if DEBUG_GENERAL in gyp.debug:
553
+ DebugOutput(DEBUG_GENERAL, "running with these options:")
554
+ for option, value in sorted(options.__dict__.items()):
555
+ if option[0] == "_":
556
+ continue
557
+ if isinstance(value, str):
558
+ DebugOutput(DEBUG_GENERAL, " %s: '%s'", option, value)
559
+ else:
560
+ DebugOutput(DEBUG_GENERAL, " %s: %s", option, value)
561
+
562
+ if not build_files:
563
+ build_files = FindBuildFiles()
564
+ if not build_files:
565
+ raise GypError((usage + "\n\n%s: error: no build_file") % (my_name, my_name))
566
+
567
+ # TODO(mark): Chromium-specific hack!
568
+ # For Chromium, the gyp "depth" variable should always be a relative path
569
+ # to Chromium's top-level "src" directory. If no depth variable was set
570
+ # on the command line, try to find a "src" directory by looking at the
571
+ # absolute path to each build file's directory. The first "src" component
572
+ # found will be treated as though it were the path used for --depth.
573
+ if not options.depth:
574
+ for build_file in build_files:
575
+ build_file_dir = os.path.abspath(os.path.dirname(build_file))
576
+ build_file_dir_components = build_file_dir.split(os.path.sep)
577
+ components_len = len(build_file_dir_components)
578
+ for index in range(components_len - 1, -1, -1):
579
+ if build_file_dir_components[index] == "src":
580
+ options.depth = os.path.sep.join(build_file_dir_components)
581
+ break
582
+ del build_file_dir_components[index]
583
+
584
+ # If the inner loop found something, break without advancing to another
585
+ # build file.
586
+ if options.depth:
587
+ break
588
+
589
+ if not options.depth:
590
+ raise GypError(
591
+ "Could not automatically locate src directory. This is"
592
+ "a temporary Chromium feature that will be removed. Use"
593
+ "--depth as a workaround."
594
+ )
595
+
596
+ # If toplevel-dir is not set, we assume that depth is the root of our source
597
+ # tree.
598
+ if not options.toplevel_dir:
599
+ options.toplevel_dir = options.depth
600
+
601
+ # -D on the command line sets variable defaults - D isn't just for define,
602
+ # it's for default. Perhaps there should be a way to force (-F?) a
603
+ # variable's value so that it can't be overridden by anything else.
604
+ cmdline_default_variables = {}
605
+ defines = []
606
+ if options.use_environment:
607
+ defines += ShlexEnv("GYP_DEFINES")
608
+ if options.defines:
609
+ defines += options.defines
610
+ cmdline_default_variables = NameValueListToDict(defines)
611
+ if DEBUG_GENERAL in gyp.debug:
612
+ DebugOutput(
613
+ DEBUG_GENERAL, "cmdline_default_variables: %s", cmdline_default_variables
614
+ )
615
+
616
+ # Set up includes.
617
+ includes = []
618
+
619
+ # If ~/.gyp/include.gypi exists, it'll be forcibly included into every
620
+ # .gyp file that's loaded, before anything else is included.
621
+ if home_dot_gyp:
622
+ default_include = os.path.join(home_dot_gyp, "include.gypi")
623
+ if os.path.exists(default_include):
624
+ print("Using overrides found in " + default_include)
625
+ includes.append(default_include)
626
+
627
+ # Command-line --include files come after the default include.
628
+ if options.includes:
629
+ includes.extend(options.includes)
630
+
631
+ # Generator flags should be prefixed with the target generator since they
632
+ # are global across all generator runs.
633
+ gen_flags = []
634
+ if options.use_environment:
635
+ gen_flags += ShlexEnv("GYP_GENERATOR_FLAGS")
636
+ if options.generator_flags:
637
+ gen_flags += options.generator_flags
638
+ generator_flags = NameValueListToDict(gen_flags)
639
+ if DEBUG_GENERAL in gyp.debug:
640
+ DebugOutput(DEBUG_GENERAL, "generator_flags: %s", generator_flags)
641
+
642
+ # Generate all requested formats (use a set in case we got one format request
643
+ # twice)
644
+ for format in set(options.formats):
645
+ params = {
646
+ "options": options,
647
+ "build_files": build_files,
648
+ "generator_flags": generator_flags,
649
+ "cwd": os.getcwd(),
650
+ "build_files_arg": build_files_arg,
651
+ "gyp_binary": sys.argv[0],
652
+ "home_dot_gyp": home_dot_gyp,
653
+ "parallel": options.parallel,
654
+ "root_targets": options.root_targets,
655
+ "target_arch": cmdline_default_variables.get("target_arch", ""),
656
+ }
657
+
658
+ # Start with the default variables from the command line.
659
+ [generator, flat_list, targets, data] = Load(
660
+ build_files,
661
+ format,
662
+ cmdline_default_variables,
663
+ includes,
664
+ options.depth,
665
+ params,
666
+ options.check,
667
+ options.circular_check,
668
+ )
669
+
670
+ # TODO(mark): Pass |data| for now because the generator needs a list of
671
+ # build files that came in. In the future, maybe it should just accept
672
+ # a list, and not the whole data dict.
673
+ # NOTE: flat_list is the flattened dependency graph specifying the order
674
+ # that targets may be built. Build systems that operate serially or that
675
+ # need to have dependencies defined before dependents reference them should
676
+ # generate targets in the order specified in flat_list.
677
+ generator.GenerateOutput(flat_list, targets, data, params)
678
+
679
+ if options.configs:
680
+ valid_configs = targets[flat_list[0]]["configurations"]
681
+ for conf in options.configs:
682
+ if conf not in valid_configs:
683
+ raise GypError("Invalid config specified via --build: %s" % conf)
684
+ generator.PerformBuild(data, options.configs, params)
685
+
686
+ # Done
687
+ return 0
688
+
689
+
690
+ def main(args):
691
+ try:
692
+ return gyp_main(args)
693
+ except GypError as e:
694
+ sys.stderr.write("gyp: %s\n" % e)
695
+ return 1
696
+
697
+
698
+ # NOTE: console_scripts calls this function with no arguments
699
+ def script_main():
700
+ return main(sys.argv[1:])
701
+
702
+
703
+ if __name__ == "__main__":
704
+ sys.exit(script_main())