wsba-hockey 1.0.2__py3-none-any.whl → 1.0.4__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 (130) hide show
  1. wsba_hockey/data_pipelines.py +183 -0
  2. wsba_hockey/evidence/weakside-breakout/node_modules/duckdb/vendor.py +146 -0
  3. wsba_hockey/evidence/weakside-breakout/node_modules/flatted/python/flatted.py +149 -0
  4. wsba_hockey/evidence/weakside-breakout/node_modules/flatted/python/test.py +63 -0
  5. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  6. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +367 -0
  7. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  8. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1270 -0
  9. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
  10. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  11. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +153 -0
  12. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +271 -0
  13. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
  14. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +690 -0
  15. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/common.py +661 -0
  16. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +78 -0
  17. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +165 -0
  18. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +109 -0
  19. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  20. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  21. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +808 -0
  22. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1173 -0
  23. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1321 -0
  24. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +120 -0
  25. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +103 -0
  26. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +464 -0
  27. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
  28. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +58 -0
  29. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2714 -0
  30. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3981 -0
  31. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  32. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2936 -0
  33. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +55 -0
  34. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1394 -0
  35. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +25 -0
  36. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/input.py +3130 -0
  37. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +98 -0
  38. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +771 -0
  39. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1271 -0
  40. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  41. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  42. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +374 -0
  43. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1939 -0
  44. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +302 -0
  45. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3197 -0
  46. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
  47. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/test_gyp.py +261 -0
  48. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/graphviz.py +102 -0
  49. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_gyp.py +156 -0
  50. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_sln.py +181 -0
  51. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_vcproj.py +339 -0
  52. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/test/fixtures/test-charmap.py +31 -0
  53. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/update-gyp.py +64 -0
  54. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  55. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +367 -0
  56. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  57. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1270 -0
  58. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
  59. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  60. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +153 -0
  61. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +271 -0
  62. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
  63. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +666 -0
  64. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/common.py +654 -0
  65. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +78 -0
  66. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +165 -0
  67. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +109 -0
  68. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  69. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  70. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +808 -0
  71. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1173 -0
  72. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1321 -0
  73. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +120 -0
  74. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +103 -0
  75. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +464 -0
  76. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
  77. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +58 -0
  78. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2518 -0
  79. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3978 -0
  80. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  81. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2936 -0
  82. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +55 -0
  83. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1394 -0
  84. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +25 -0
  85. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/input.py +3137 -0
  86. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +98 -0
  87. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +771 -0
  88. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1271 -0
  89. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  90. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  91. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +374 -0
  92. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1939 -0
  93. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +302 -0
  94. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3197 -0
  95. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
  96. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/setup.py +42 -0
  97. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/test_gyp.py +260 -0
  98. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/graphviz.py +102 -0
  99. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_gyp.py +156 -0
  100. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_sln.py +181 -0
  101. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_vcproj.py +339 -0
  102. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/test/fixtures/test-charmap.py +31 -0
  103. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/update-gyp.py +46 -0
  104. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/game_stats/app.py +401 -0
  105. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/game_stats/name_fix.py +47 -0
  106. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/app.py +108 -0
  107. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/plot.py +93 -0
  108. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/rink_plot.py +245 -0
  109. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/app.py +145 -0
  110. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/plot.py +77 -0
  111. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/rink_plot.py +245 -0
  112. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/app.py +389 -0
  113. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/plot.py +70 -0
  114. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/rink_plot.py +245 -0
  115. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/app.py +110 -0
  116. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/plot.py +58 -0
  117. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/rink_plot.py +245 -0
  118. wsba_hockey/tools/agg.py +242 -53
  119. wsba_hockey/tools/plotting.py +15 -20
  120. wsba_hockey/tools/scraping.py +149 -258
  121. wsba_hockey/tools/xg_model.py +370 -298
  122. wsba_hockey/workspace.py +22 -101
  123. wsba_hockey/wsba_main.py +494 -147
  124. {wsba_hockey-1.0.2.dist-info → wsba_hockey-1.0.4.dist-info}/METADATA +2 -2
  125. wsba_hockey-1.0.4.dist-info/RECORD +135 -0
  126. {wsba_hockey-1.0.2.dist-info → wsba_hockey-1.0.4.dist-info}/WHEEL +1 -1
  127. wsba_hockey/stats/calculate_viz/shot_impact.py +0 -2
  128. wsba_hockey-1.0.2.dist-info/RECORD +0 -19
  129. {wsba_hockey-1.0.2.dist-info → wsba_hockey-1.0.4.dist-info}/licenses/LICENSE +0 -0
  130. {wsba_hockey-1.0.2.dist-info → wsba_hockey-1.0.4.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,2518 @@
1
+ # Copyright (c) 2013 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 is all roughly based on the Makefile system used by the Linux
8
+ # kernel, but is a non-recursive make -- we put the entire dependency
9
+ # graph in front of make and let it figure it out.
10
+ #
11
+ # The code below generates a separate .mk file for each target, but
12
+ # all are sourced by the top-level Makefile. This means that all
13
+ # variables in .mk-files clobber one another. Be careful to use :=
14
+ # where appropriate for immediate evaluation, and similarly to watch
15
+ # that you're not relying on a variable value to last between different
16
+ # .mk files.
17
+ #
18
+ # TODOs:
19
+ #
20
+ # Global settings and utility functions are currently stuffed in the
21
+ # toplevel Makefile. It may make sense to generate some .mk files on
22
+ # the side to keep the files readable.
23
+
24
+
25
+ import os
26
+ import re
27
+ import subprocess
28
+ import gyp
29
+ import gyp.common
30
+ import gyp.xcode_emulation
31
+ from gyp.common import GetEnvironFallback
32
+
33
+ import hashlib
34
+
35
+ generator_default_variables = {
36
+ "EXECUTABLE_PREFIX": "",
37
+ "EXECUTABLE_SUFFIX": "",
38
+ "STATIC_LIB_PREFIX": "lib",
39
+ "SHARED_LIB_PREFIX": "lib",
40
+ "STATIC_LIB_SUFFIX": ".a",
41
+ "INTERMEDIATE_DIR": "$(obj).$(TOOLSET)/$(TARGET)/geni",
42
+ "SHARED_INTERMEDIATE_DIR": "$(obj)/gen",
43
+ "PRODUCT_DIR": "$(builddir)",
44
+ "RULE_INPUT_ROOT": "%(INPUT_ROOT)s", # This gets expanded by Python.
45
+ "RULE_INPUT_DIRNAME": "%(INPUT_DIRNAME)s", # This gets expanded by Python.
46
+ "RULE_INPUT_PATH": "$(abspath $<)",
47
+ "RULE_INPUT_EXT": "$(suffix $<)",
48
+ "RULE_INPUT_NAME": "$(notdir $<)",
49
+ "CONFIGURATION_NAME": "$(BUILDTYPE)",
50
+ }
51
+
52
+ # Make supports multiple toolsets
53
+ generator_supports_multiple_toolsets = True
54
+
55
+ # Request sorted dependencies in the order from dependents to dependencies.
56
+ generator_wants_sorted_dependencies = False
57
+
58
+ # Placates pylint.
59
+ generator_additional_non_configuration_keys = []
60
+ generator_additional_path_sections = []
61
+ generator_extra_sources_for_rules = []
62
+ generator_filelist_paths = None
63
+
64
+
65
+ def CalculateVariables(default_variables, params):
66
+ """Calculate additional variables for use in the build (called by gyp)."""
67
+ flavor = gyp.common.GetFlavor(params)
68
+ if flavor == "mac":
69
+ default_variables.setdefault("OS", "mac")
70
+ default_variables.setdefault("SHARED_LIB_SUFFIX", ".dylib")
71
+ default_variables.setdefault(
72
+ "SHARED_LIB_DIR", generator_default_variables["PRODUCT_DIR"]
73
+ )
74
+ default_variables.setdefault(
75
+ "LIB_DIR", generator_default_variables["PRODUCT_DIR"]
76
+ )
77
+
78
+ # Copy additional generator configuration data from Xcode, which is shared
79
+ # by the Mac Make generator.
80
+ import gyp.generator.xcode as xcode_generator
81
+
82
+ global generator_additional_non_configuration_keys
83
+ generator_additional_non_configuration_keys = getattr(
84
+ xcode_generator, "generator_additional_non_configuration_keys", []
85
+ )
86
+ global generator_additional_path_sections
87
+ generator_additional_path_sections = getattr(
88
+ xcode_generator, "generator_additional_path_sections", []
89
+ )
90
+ global generator_extra_sources_for_rules
91
+ generator_extra_sources_for_rules = getattr(
92
+ xcode_generator, "generator_extra_sources_for_rules", []
93
+ )
94
+ COMPILABLE_EXTENSIONS.update({".m": "objc", ".mm": "objcxx"})
95
+ else:
96
+ operating_system = flavor
97
+ if flavor == "android":
98
+ operating_system = "linux" # Keep this legacy behavior for now.
99
+ default_variables.setdefault("OS", operating_system)
100
+ if flavor == "aix":
101
+ default_variables.setdefault("SHARED_LIB_SUFFIX", ".a")
102
+ else:
103
+ default_variables.setdefault("SHARED_LIB_SUFFIX", ".so")
104
+ default_variables.setdefault("SHARED_LIB_DIR", "$(builddir)/lib.$(TOOLSET)")
105
+ default_variables.setdefault("LIB_DIR", "$(obj).$(TOOLSET)")
106
+
107
+
108
+ def CalculateGeneratorInputInfo(params):
109
+ """Calculate the generator specific info that gets fed to input (called by
110
+ gyp)."""
111
+ generator_flags = params.get("generator_flags", {})
112
+ android_ndk_version = generator_flags.get("android_ndk_version", None)
113
+ # Android NDK requires a strict link order.
114
+ if android_ndk_version:
115
+ global generator_wants_sorted_dependencies
116
+ generator_wants_sorted_dependencies = True
117
+
118
+ output_dir = params["options"].generator_output or params["options"].toplevel_dir
119
+ builddir_name = generator_flags.get("output_dir", "out")
120
+ qualified_out_dir = os.path.normpath(
121
+ os.path.join(output_dir, builddir_name, "gypfiles")
122
+ )
123
+
124
+ global generator_filelist_paths
125
+ generator_filelist_paths = {
126
+ "toplevel": params["options"].toplevel_dir,
127
+ "qualified_out_dir": qualified_out_dir,
128
+ }
129
+
130
+
131
+ # The .d checking code below uses these functions:
132
+ # wildcard, sort, foreach, shell, wordlist
133
+ # wildcard can handle spaces, the rest can't.
134
+ # Since I could find no way to make foreach work with spaces in filenames
135
+ # correctly, the .d files have spaces replaced with another character. The .d
136
+ # file for
137
+ # Chromium\ Framework.framework/foo
138
+ # is for example
139
+ # out/Release/.deps/out/Release/Chromium?Framework.framework/foo
140
+ # This is the replacement character.
141
+ SPACE_REPLACEMENT = "?"
142
+
143
+
144
+ LINK_COMMANDS_LINUX = """\
145
+ quiet_cmd_alink = AR($(TOOLSET)) $@
146
+ cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^)
147
+
148
+ quiet_cmd_alink_thin = AR($(TOOLSET)) $@
149
+ cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^)
150
+
151
+ # Due to circular dependencies between libraries :(, we wrap the
152
+ # special "figure out circular dependencies" flags around the entire
153
+ # input list during linking.
154
+ quiet_cmd_link = LINK($(TOOLSET)) $@
155
+ cmd_link = $(LINK.$(TOOLSET)) -o $@ $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,--start-group $(LD_INPUTS) $(LIBS) -Wl,--end-group
156
+
157
+ # We support two kinds of shared objects (.so):
158
+ # 1) shared_library, which is just bundling together many dependent libraries
159
+ # into a link line.
160
+ # 2) loadable_module, which is generating a module intended for dlopen().
161
+ #
162
+ # They differ only slightly:
163
+ # In the former case, we want to package all dependent code into the .so.
164
+ # In the latter case, we want to package just the API exposed by the
165
+ # outermost module.
166
+ # This means shared_library uses --whole-archive, while loadable_module doesn't.
167
+ # (Note that --whole-archive is incompatible with the --start-group used in
168
+ # normal linking.)
169
+
170
+ # Other shared-object link notes:
171
+ # - Set SONAME to the library filename so our binaries don't reference
172
+ # the local, absolute paths used on the link command-line.
173
+ quiet_cmd_solink = SOLINK($(TOOLSET)) $@
174
+ cmd_solink = $(LINK.$(TOOLSET)) -o $@ -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -Wl,--whole-archive $(LD_INPUTS) -Wl,--no-whole-archive $(LIBS)
175
+
176
+ quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
177
+ cmd_solink_module = $(LINK.$(TOOLSET)) -o $@ -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -Wl,--start-group $(filter-out FORCE_DO_CMD, $^) -Wl,--end-group $(LIBS)
178
+ """ # noqa: E501
179
+
180
+ LINK_COMMANDS_MAC = """\
181
+ quiet_cmd_alink = LIBTOOL-STATIC $@
182
+ cmd_alink = rm -f $@ && ./gyp-mac-tool filter-libtool libtool $(GYP_LIBTOOLFLAGS) -static -o $@ $(filter %.o,$^)
183
+
184
+ quiet_cmd_link = LINK($(TOOLSET)) $@
185
+ cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o "$@" $(LD_INPUTS) $(LIBS)
186
+
187
+ quiet_cmd_solink = SOLINK($(TOOLSET)) $@
188
+ cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o "$@" $(LD_INPUTS) $(LIBS)
189
+
190
+ quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
191
+ cmd_solink_module = $(LINK.$(TOOLSET)) -bundle $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
192
+ """ # noqa: E501
193
+
194
+ LINK_COMMANDS_ANDROID = """\
195
+ quiet_cmd_alink = AR($(TOOLSET)) $@
196
+ cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^)
197
+
198
+ quiet_cmd_alink_thin = AR($(TOOLSET)) $@
199
+ cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^)
200
+
201
+ # Due to circular dependencies between libraries :(, we wrap the
202
+ # special "figure out circular dependencies" flags around the entire
203
+ # input list during linking.
204
+ quiet_cmd_link = LINK($(TOOLSET)) $@
205
+ quiet_cmd_link_host = LINK($(TOOLSET)) $@
206
+ cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS)
207
+ cmd_link_host = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS)
208
+
209
+ # Other shared-object link notes:
210
+ # - Set SONAME to the library filename so our binaries don't reference
211
+ # the local, absolute paths used on the link command-line.
212
+ quiet_cmd_solink = SOLINK($(TOOLSET)) $@
213
+ cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--whole-archive $(LD_INPUTS) -Wl,--no-whole-archive $(LIBS)
214
+
215
+ quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
216
+ cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--start-group $(filter-out FORCE_DO_CMD, $^) -Wl,--end-group $(LIBS)
217
+ quiet_cmd_solink_module_host = SOLINK_MODULE($(TOOLSET)) $@
218
+ cmd_solink_module_host = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
219
+ """ # noqa: E501
220
+
221
+
222
+ LINK_COMMANDS_AIX = """\
223
+ quiet_cmd_alink = AR($(TOOLSET)) $@
224
+ cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) -X32_64 crs $@ $(filter %.o,$^)
225
+
226
+ quiet_cmd_alink_thin = AR($(TOOLSET)) $@
227
+ cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) -X32_64 crs $@ $(filter %.o,$^)
228
+
229
+ quiet_cmd_link = LINK($(TOOLSET)) $@
230
+ cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS)
231
+
232
+ quiet_cmd_solink = SOLINK($(TOOLSET)) $@
233
+ cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS)
234
+
235
+ quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
236
+ cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
237
+ """ # noqa: E501
238
+
239
+
240
+ LINK_COMMANDS_OS390 = """\
241
+ quiet_cmd_alink = AR($(TOOLSET)) $@
242
+ cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^)
243
+
244
+ quiet_cmd_alink_thin = AR($(TOOLSET)) $@
245
+ cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^)
246
+
247
+ quiet_cmd_link = LINK($(TOOLSET)) $@
248
+ cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS)
249
+
250
+ quiet_cmd_solink = SOLINK($(TOOLSET)) $@
251
+ cmd_solink = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS) -Wl,DLL
252
+
253
+ quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
254
+ cmd_solink_module = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS) -Wl,DLL
255
+ """ # noqa: E501
256
+
257
+
258
+ # Header of toplevel Makefile.
259
+ # This should go into the build tree, but it's easier to keep it here for now.
260
+ SHARED_HEADER = (
261
+ """\
262
+ # We borrow heavily from the kernel build setup, though we are simpler since
263
+ # we don't have Kconfig tweaking settings on us.
264
+
265
+ # The implicit make rules have it looking for RCS files, among other things.
266
+ # We instead explicitly write all the rules we care about.
267
+ # It's even quicker (saves ~200ms) to pass -r on the command line.
268
+ MAKEFLAGS=-r
269
+
270
+ # The source directory tree.
271
+ srcdir := %(srcdir)s
272
+ abs_srcdir := $(abspath $(srcdir))
273
+
274
+ # The name of the builddir.
275
+ builddir_name ?= %(builddir)s
276
+
277
+ # The V=1 flag on command line makes us verbosely print command lines.
278
+ ifdef V
279
+ quiet=
280
+ else
281
+ quiet=quiet_
282
+ endif
283
+
284
+ # Specify BUILDTYPE=Release on the command line for a release build.
285
+ BUILDTYPE ?= %(default_configuration)s
286
+
287
+ # Directory all our build output goes into.
288
+ # Note that this must be two directories beneath src/ for unit tests to pass,
289
+ # as they reach into the src/ directory for data with relative paths.
290
+ builddir ?= $(builddir_name)/$(BUILDTYPE)
291
+ abs_builddir := $(abspath $(builddir))
292
+ depsdir := $(builddir)/.deps
293
+
294
+ # Object output directory.
295
+ obj := $(builddir)/obj
296
+ abs_obj := $(abspath $(obj))
297
+
298
+ # We build up a list of every single one of the targets so we can slurp in the
299
+ # generated dependency rule Makefiles in one pass.
300
+ all_deps :=
301
+
302
+ %(make_global_settings)s
303
+
304
+ CC.target ?= %(CC.target)s
305
+ CFLAGS.target ?= $(CPPFLAGS) $(CFLAGS)
306
+ CXX.target ?= %(CXX.target)s
307
+ CXXFLAGS.target ?= $(CPPFLAGS) $(CXXFLAGS)
308
+ LINK.target ?= %(LINK.target)s
309
+ LDFLAGS.target ?= $(LDFLAGS)
310
+ AR.target ?= $(AR)
311
+
312
+ # C++ apps need to be linked with g++.
313
+ LINK ?= $(CXX.target)
314
+
315
+ # TODO(evan): move all cross-compilation logic to gyp-time so we don't need
316
+ # to replicate this environment fallback in make as well.
317
+ CC.host ?= %(CC.host)s
318
+ CFLAGS.host ?= $(CPPFLAGS_host) $(CFLAGS_host)
319
+ CXX.host ?= %(CXX.host)s
320
+ CXXFLAGS.host ?= $(CPPFLAGS_host) $(CXXFLAGS_host)
321
+ LINK.host ?= %(LINK.host)s
322
+ LDFLAGS.host ?= $(LDFLAGS_host)
323
+ AR.host ?= %(AR.host)s
324
+
325
+ # Define a dir function that can handle spaces.
326
+ # http://www.gnu.org/software/make/manual/make.html#Syntax-of-Functions
327
+ # "leading spaces cannot appear in the text of the first argument as written.
328
+ # These characters can be put into the argument value by variable substitution."
329
+ empty :=
330
+ space := $(empty) $(empty)
331
+
332
+ # http://stackoverflow.com/questions/1189781/using-make-dir-or-notdir-on-a-path-with-spaces
333
+ replace_spaces = $(subst $(space),"""
334
+ + SPACE_REPLACEMENT
335
+ + """,$1)
336
+ unreplace_spaces = $(subst """
337
+ + SPACE_REPLACEMENT
338
+ + """,$(space),$1)
339
+ dirx = $(call unreplace_spaces,$(dir $(call replace_spaces,$1)))
340
+
341
+ # Flags to make gcc output dependency info. Note that you need to be
342
+ # careful here to use the flags that ccache and distcc can understand.
343
+ # We write to a dep file on the side first and then rename at the end
344
+ # so we can't end up with a broken dep file.
345
+ depfile = $(depsdir)/$(call replace_spaces,$@).d
346
+ DEPFLAGS = %(makedep_args)s -MF $(depfile).raw
347
+
348
+ # We have to fixup the deps output in a few ways.
349
+ # (1) the file output should mention the proper .o file.
350
+ # ccache or distcc lose the path to the target, so we convert a rule of
351
+ # the form:
352
+ # foobar.o: DEP1 DEP2
353
+ # into
354
+ # path/to/foobar.o: DEP1 DEP2
355
+ # (2) we want missing files not to cause us to fail to build.
356
+ # We want to rewrite
357
+ # foobar.o: DEP1 DEP2 \\
358
+ # DEP3
359
+ # to
360
+ # DEP1:
361
+ # DEP2:
362
+ # DEP3:
363
+ # so if the files are missing, they're just considered phony rules.
364
+ # We have to do some pretty insane escaping to get those backslashes
365
+ # and dollar signs past make, the shell, and sed at the same time.
366
+ # Doesn't work with spaces, but that's fine: .d files have spaces in
367
+ # their names replaced with other characters."""
368
+ r"""
369
+ define fixup_dep
370
+ # The depfile may not exist if the input file didn't have any #includes.
371
+ touch $(depfile).raw
372
+ # Fixup path as in (1).
373
+ sed -e "s|^$(notdir $@)|$@|" $(depfile).raw >> $(depfile)
374
+ # Add extra rules as in (2).
375
+ # We remove slashes and replace spaces with new lines;
376
+ # remove blank lines;
377
+ # delete the first line and append a colon to the remaining lines.
378
+ sed -e 's|\\||' -e 'y| |\n|' $(depfile).raw |\
379
+ grep -v '^$$' |\
380
+ sed -e 1d -e 's|$$|:|' \
381
+ >> $(depfile)
382
+ rm $(depfile).raw
383
+ endef
384
+ """
385
+ """
386
+ # Command definitions:
387
+ # - cmd_foo is the actual command to run;
388
+ # - quiet_cmd_foo is the brief-output summary of the command.
389
+
390
+ quiet_cmd_cc = CC($(TOOLSET)) $@
391
+ cmd_cc = $(CC.$(TOOLSET)) -o $@ $< $(GYP_CFLAGS) $(DEPFLAGS) $(CFLAGS.$(TOOLSET)) -c
392
+
393
+ quiet_cmd_cxx = CXX($(TOOLSET)) $@
394
+ cmd_cxx = $(CXX.$(TOOLSET)) -o $@ $< $(GYP_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c
395
+ %(extra_commands)s
396
+ quiet_cmd_touch = TOUCH $@
397
+ cmd_touch = touch $@
398
+
399
+ quiet_cmd_copy = COPY $@
400
+ # send stderr to /dev/null to ignore messages when linking directories.
401
+ cmd_copy = ln -f "$<" "$@" 2>/dev/null || (rm -rf "$@" && cp %(copy_archive_args)s "$<" "$@")
402
+
403
+ %(link_commands)s
404
+ """ # noqa: E501
405
+ r"""
406
+ # Define an escape_quotes function to escape single quotes.
407
+ # This allows us to handle quotes properly as long as we always use
408
+ # use single quotes and escape_quotes.
409
+ escape_quotes = $(subst ','\'',$(1))
410
+ # This comment is here just to include a ' to unconfuse syntax highlighting.
411
+ # Define an escape_vars function to escape '$' variable syntax.
412
+ # This allows us to read/write command lines with shell variables (e.g.
413
+ # $LD_LIBRARY_PATH), without triggering make substitution.
414
+ escape_vars = $(subst $$,$$$$,$(1))
415
+ # Helper that expands to a shell command to echo a string exactly as it is in
416
+ # make. This uses printf instead of echo because printf's behaviour with respect
417
+ # to escape sequences is more portable than echo's across different shells
418
+ # (e.g., dash, bash).
419
+ exact_echo = printf '%%s\n' '$(call escape_quotes,$(1))'
420
+ """
421
+ """
422
+ # Helper to compare the command we're about to run against the command
423
+ # we logged the last time we ran the command. Produces an empty
424
+ # string (false) when the commands match.
425
+ # Tricky point: Make has no string-equality test function.
426
+ # The kernel uses the following, but it seems like it would have false
427
+ # positives, where one string reordered its arguments.
428
+ # arg_check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \\
429
+ # $(filter-out $(cmd_$@), $(cmd_$(1))))
430
+ # We instead substitute each for the empty string into the other, and
431
+ # say they're equal if both substitutions produce the empty string.
432
+ # .d files contain """
433
+ + SPACE_REPLACEMENT
434
+ + """ instead of spaces, take that into account.
435
+ command_changed = $(or $(subst $(cmd_$(1)),,$(cmd_$(call replace_spaces,$@))),\\
436
+ $(subst $(cmd_$(call replace_spaces,$@)),,$(cmd_$(1))))
437
+
438
+ # Helper that is non-empty when a prerequisite changes.
439
+ # Normally make does this implicitly, but we force rules to always run
440
+ # so we can check their command lines.
441
+ # $? -- new prerequisites
442
+ # $| -- order-only dependencies
443
+ prereq_changed = $(filter-out FORCE_DO_CMD,$(filter-out $|,$?))
444
+
445
+ # Helper that executes all postbuilds until one fails.
446
+ define do_postbuilds
447
+ @E=0;\\
448
+ for p in $(POSTBUILDS); do\\
449
+ eval $$p;\\
450
+ E=$$?;\\
451
+ if [ $$E -ne 0 ]; then\\
452
+ break;\\
453
+ fi;\\
454
+ done;\\
455
+ if [ $$E -ne 0 ]; then\\
456
+ rm -rf "$@";\\
457
+ exit $$E;\\
458
+ fi
459
+ endef
460
+
461
+ # do_cmd: run a command via the above cmd_foo names, if necessary.
462
+ # Should always run for a given target to handle command-line changes.
463
+ # Second argument, if non-zero, makes it do asm/C/C++ dependency munging.
464
+ # Third argument, if non-zero, makes it do POSTBUILDS processing.
465
+ # Note: We intentionally do NOT call dirx for depfile, since it contains """
466
+ + SPACE_REPLACEMENT
467
+ + """ for
468
+ # spaces already and dirx strips the """
469
+ + SPACE_REPLACEMENT
470
+ + """ characters.
471
+ define do_cmd
472
+ $(if $(or $(command_changed),$(prereq_changed)),
473
+ @$(call exact_echo, $($(quiet)cmd_$(1)))
474
+ @mkdir -p "$(call dirx,$@)" "$(dir $(depfile))"
475
+ $(if $(findstring flock,$(word %(flock_index)d,$(cmd_$1))),
476
+ @$(cmd_$(1))
477
+ @echo " $(quiet_cmd_$(1)): Finished",
478
+ @$(cmd_$(1))
479
+ )
480
+ @$(call exact_echo,$(call escape_vars,cmd_$(call replace_spaces,$@) := $(cmd_$(1)))) > $(depfile)
481
+ @$(if $(2),$(fixup_dep))
482
+ $(if $(and $(3), $(POSTBUILDS)),
483
+ $(call do_postbuilds)
484
+ )
485
+ )
486
+ endef
487
+
488
+ # Declare the "%(default_target)s" target first so it is the default,
489
+ # even though we don't have the deps yet.
490
+ .PHONY: %(default_target)s
491
+ %(default_target)s:
492
+
493
+ # make looks for ways to re-generate included makefiles, but in our case, we
494
+ # don't have a direct way. Explicitly telling make that it has nothing to do
495
+ # for them makes it go faster.
496
+ %%.d: ;
497
+
498
+ # Use FORCE_DO_CMD to force a target to run. Should be coupled with
499
+ # do_cmd.
500
+ .PHONY: FORCE_DO_CMD
501
+ FORCE_DO_CMD:
502
+
503
+ """ # noqa: E501
504
+ )
505
+
506
+ SHARED_HEADER_MAC_COMMANDS = """
507
+ quiet_cmd_objc = CXX($(TOOLSET)) $@
508
+ cmd_objc = $(CC.$(TOOLSET)) $(GYP_OBJCFLAGS) $(DEPFLAGS) -c -o $@ $<
509
+
510
+ quiet_cmd_objcxx = CXX($(TOOLSET)) $@
511
+ cmd_objcxx = $(CXX.$(TOOLSET)) $(GYP_OBJCXXFLAGS) $(DEPFLAGS) -c -o $@ $<
512
+
513
+ # Commands for precompiled header files.
514
+ quiet_cmd_pch_c = CXX($(TOOLSET)) $@
515
+ cmd_pch_c = $(CC.$(TOOLSET)) $(GYP_PCH_CFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $<
516
+ quiet_cmd_pch_cc = CXX($(TOOLSET)) $@
517
+ cmd_pch_cc = $(CC.$(TOOLSET)) $(GYP_PCH_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $<
518
+ quiet_cmd_pch_m = CXX($(TOOLSET)) $@
519
+ cmd_pch_m = $(CC.$(TOOLSET)) $(GYP_PCH_OBJCFLAGS) $(DEPFLAGS) -c -o $@ $<
520
+ quiet_cmd_pch_mm = CXX($(TOOLSET)) $@
521
+ cmd_pch_mm = $(CC.$(TOOLSET)) $(GYP_PCH_OBJCXXFLAGS) $(DEPFLAGS) -c -o $@ $<
522
+
523
+ # gyp-mac-tool is written next to the root Makefile by gyp.
524
+ # Use $(4) for the command, since $(2) and $(3) are used as flag by do_cmd
525
+ # already.
526
+ quiet_cmd_mac_tool = MACTOOL $(4) $<
527
+ cmd_mac_tool = ./gyp-mac-tool $(4) $< "$@"
528
+
529
+ quiet_cmd_mac_package_framework = PACKAGE FRAMEWORK $@
530
+ cmd_mac_package_framework = ./gyp-mac-tool package-framework "$@" $(4)
531
+
532
+ quiet_cmd_infoplist = INFOPLIST $@
533
+ cmd_infoplist = $(CC.$(TOOLSET)) -E -P -Wno-trigraphs -x c $(INFOPLIST_DEFINES) "$<" -o "$@"
534
+ """ # noqa: E501
535
+
536
+
537
+ def WriteRootHeaderSuffixRules(writer):
538
+ extensions = sorted(COMPILABLE_EXTENSIONS.keys(), key=str.lower)
539
+
540
+ writer.write("# Suffix rules, putting all outputs into $(obj).\n")
541
+ for ext in extensions:
542
+ writer.write("$(obj).$(TOOLSET)/%%.o: $(srcdir)/%%%s FORCE_DO_CMD\n" % ext)
543
+ writer.write("\t@$(call do_cmd,%s,1)\n" % COMPILABLE_EXTENSIONS[ext])
544
+
545
+ writer.write("\n# Try building from generated source, too.\n")
546
+ for ext in extensions:
547
+ writer.write(
548
+ "$(obj).$(TOOLSET)/%%.o: $(obj).$(TOOLSET)/%%%s FORCE_DO_CMD\n" % ext
549
+ )
550
+ writer.write("\t@$(call do_cmd,%s,1)\n" % COMPILABLE_EXTENSIONS[ext])
551
+ writer.write("\n")
552
+ for ext in extensions:
553
+ writer.write("$(obj).$(TOOLSET)/%%.o: $(obj)/%%%s FORCE_DO_CMD\n" % ext)
554
+ writer.write("\t@$(call do_cmd,%s,1)\n" % COMPILABLE_EXTENSIONS[ext])
555
+ writer.write("\n")
556
+
557
+
558
+ SHARED_HEADER_SUFFIX_RULES_COMMENT1 = """\
559
+ # Suffix rules, putting all outputs into $(obj).
560
+ """
561
+
562
+
563
+ SHARED_HEADER_SUFFIX_RULES_COMMENT2 = """\
564
+ # Try building from generated source, too.
565
+ """
566
+
567
+
568
+ SHARED_FOOTER = """\
569
+ # "all" is a concatenation of the "all" targets from all the included
570
+ # sub-makefiles. This is just here to clarify.
571
+ all:
572
+
573
+ # Add in dependency-tracking rules. $(all_deps) is the list of every single
574
+ # target in our tree. Only consider the ones with .d (dependency) info:
575
+ d_files := $(wildcard $(foreach f,$(all_deps),$(depsdir)/$(f).d))
576
+ ifneq ($(d_files),)
577
+ include $(d_files)
578
+ endif
579
+ """
580
+
581
+ header = """\
582
+ # This file is generated by gyp; do not edit.
583
+
584
+ """
585
+
586
+ # Maps every compilable file extension to the do_cmd that compiles it.
587
+ COMPILABLE_EXTENSIONS = {
588
+ ".c": "cc",
589
+ ".cc": "cxx",
590
+ ".cpp": "cxx",
591
+ ".cxx": "cxx",
592
+ ".s": "cc",
593
+ ".S": "cc",
594
+ }
595
+
596
+
597
+ def Compilable(filename):
598
+ """Return true if the file is compilable (should be in OBJS)."""
599
+ for res in (filename.endswith(e) for e in COMPILABLE_EXTENSIONS):
600
+ if res:
601
+ return True
602
+ return False
603
+
604
+
605
+ def Linkable(filename):
606
+ """Return true if the file is linkable (should be on the link line)."""
607
+ return filename.endswith(".o")
608
+
609
+
610
+ def Target(filename):
611
+ """Translate a compilable filename to its .o target."""
612
+ return os.path.splitext(filename)[0] + ".o"
613
+
614
+
615
+ def EscapeShellArgument(s):
616
+ """Quotes an argument so that it will be interpreted literally by a POSIX
617
+ shell. Taken from
618
+ http://stackoverflow.com/questions/35817/whats-the-best-way-to-escape-ossystem-calls-in-python
619
+ """
620
+ return "'" + s.replace("'", "'\\''") + "'"
621
+
622
+
623
+ def EscapeMakeVariableExpansion(s):
624
+ """Make has its own variable expansion syntax using $. We must escape it for
625
+ string to be interpreted literally."""
626
+ return s.replace("$", "$$")
627
+
628
+
629
+ def EscapeCppDefine(s):
630
+ """Escapes a CPP define so that it will reach the compiler unaltered."""
631
+ s = EscapeShellArgument(s)
632
+ s = EscapeMakeVariableExpansion(s)
633
+ # '#' characters must be escaped even embedded in a string, else Make will
634
+ # treat it as the start of a comment.
635
+ return s.replace("#", r"\#")
636
+
637
+
638
+ def QuoteIfNecessary(string):
639
+ """TODO: Should this ideally be replaced with one or more of the above
640
+ functions?"""
641
+ if '"' in string:
642
+ string = '"' + string.replace('"', '\\"') + '"'
643
+ return string
644
+
645
+
646
+ def StringToMakefileVariable(string):
647
+ """Convert a string to a value that is acceptable as a make variable name."""
648
+ return re.sub("[^a-zA-Z0-9_]", "_", string)
649
+
650
+
651
+ srcdir_prefix = ""
652
+
653
+
654
+ def Sourceify(path):
655
+ """Convert a path to its source directory form."""
656
+ if "$(" in path:
657
+ return path
658
+ if os.path.isabs(path):
659
+ return path
660
+ return srcdir_prefix + path
661
+
662
+
663
+ def QuoteSpaces(s, quote=r"\ "):
664
+ return s.replace(" ", quote)
665
+
666
+
667
+ def SourceifyAndQuoteSpaces(path):
668
+ """Convert a path to its source directory form and quote spaces."""
669
+ return QuoteSpaces(Sourceify(path))
670
+
671
+
672
+ # Map from qualified target to path to output.
673
+ target_outputs = {}
674
+ # Map from qualified target to any linkable output. A subset
675
+ # of target_outputs. E.g. when mybinary depends on liba, we want to
676
+ # include liba in the linker line; when otherbinary depends on
677
+ # mybinary, we just want to build mybinary first.
678
+ target_link_deps = {}
679
+
680
+
681
+ class MakefileWriter:
682
+ """MakefileWriter packages up the writing of one target-specific foobar.mk.
683
+
684
+ Its only real entry point is Write(), and is mostly used for namespacing.
685
+ """
686
+
687
+ def __init__(self, generator_flags, flavor):
688
+ self.generator_flags = generator_flags
689
+ self.flavor = flavor
690
+
691
+ self.suffix_rules_srcdir = {}
692
+ self.suffix_rules_objdir1 = {}
693
+ self.suffix_rules_objdir2 = {}
694
+
695
+ # Generate suffix rules for all compilable extensions.
696
+ for ext in COMPILABLE_EXTENSIONS.keys():
697
+ # Suffix rules for source folder.
698
+ self.suffix_rules_srcdir.update(
699
+ {
700
+ ext: (
701
+ """\
702
+ $(obj).$(TOOLSET)/$(TARGET)/%%.o: $(srcdir)/%%%s FORCE_DO_CMD
703
+ \t@$(call do_cmd,%s,1)
704
+ """
705
+ % (ext, COMPILABLE_EXTENSIONS[ext])
706
+ )
707
+ }
708
+ )
709
+
710
+ # Suffix rules for generated source files.
711
+ self.suffix_rules_objdir1.update(
712
+ {
713
+ ext: (
714
+ """\
715
+ $(obj).$(TOOLSET)/$(TARGET)/%%.o: $(obj).$(TOOLSET)/%%%s FORCE_DO_CMD
716
+ \t@$(call do_cmd,%s,1)
717
+ """
718
+ % (ext, COMPILABLE_EXTENSIONS[ext])
719
+ )
720
+ }
721
+ )
722
+ self.suffix_rules_objdir2.update(
723
+ {
724
+ ext: (
725
+ """\
726
+ $(obj).$(TOOLSET)/$(TARGET)/%%.o: $(obj)/%%%s FORCE_DO_CMD
727
+ \t@$(call do_cmd,%s,1)
728
+ """
729
+ % (ext, COMPILABLE_EXTENSIONS[ext])
730
+ )
731
+ }
732
+ )
733
+
734
+ def Write(
735
+ self, qualified_target, base_path, output_filename, spec, configs, part_of_all
736
+ ):
737
+ """The main entry point: writes a .mk file for a single target.
738
+
739
+ Arguments:
740
+ qualified_target: target we're generating
741
+ base_path: path relative to source root we're building in, used to resolve
742
+ target-relative paths
743
+ output_filename: output .mk file name to write
744
+ spec, configs: gyp info
745
+ part_of_all: flag indicating this target is part of 'all'
746
+ """
747
+ gyp.common.EnsureDirExists(output_filename)
748
+
749
+ self.fp = open(output_filename, "w")
750
+
751
+ self.fp.write(header)
752
+
753
+ self.qualified_target = qualified_target
754
+ self.path = base_path
755
+ self.target = spec["target_name"]
756
+ self.type = spec["type"]
757
+ self.toolset = spec["toolset"]
758
+
759
+ self.is_mac_bundle = gyp.xcode_emulation.IsMacBundle(self.flavor, spec)
760
+ if self.flavor == "mac":
761
+ self.xcode_settings = gyp.xcode_emulation.XcodeSettings(spec)
762
+ else:
763
+ self.xcode_settings = None
764
+
765
+ deps, link_deps = self.ComputeDeps(spec)
766
+
767
+ # Some of the generation below can add extra output, sources, or
768
+ # link dependencies. All of the out params of the functions that
769
+ # follow use names like extra_foo.
770
+ extra_outputs = []
771
+ extra_sources = []
772
+ extra_link_deps = []
773
+ extra_mac_bundle_resources = []
774
+ mac_bundle_deps = []
775
+
776
+ if self.is_mac_bundle:
777
+ self.output = self.ComputeMacBundleOutput(spec)
778
+ self.output_binary = self.ComputeMacBundleBinaryOutput(spec)
779
+ else:
780
+ self.output = self.output_binary = self.ComputeOutput(spec)
781
+
782
+ self.is_standalone_static_library = bool(
783
+ spec.get("standalone_static_library", 0)
784
+ )
785
+ self._INSTALLABLE_TARGETS = ("executable", "loadable_module", "shared_library")
786
+ if self.is_standalone_static_library or self.type in self._INSTALLABLE_TARGETS:
787
+ self.alias = os.path.basename(self.output)
788
+ install_path = self._InstallableTargetInstallPath()
789
+ else:
790
+ self.alias = self.output
791
+ install_path = self.output
792
+
793
+ self.WriteLn("TOOLSET := " + self.toolset)
794
+ self.WriteLn("TARGET := " + self.target)
795
+
796
+ # Actions must come first, since they can generate more OBJs for use below.
797
+ if "actions" in spec:
798
+ self.WriteActions(
799
+ spec["actions"],
800
+ extra_sources,
801
+ extra_outputs,
802
+ extra_mac_bundle_resources,
803
+ part_of_all,
804
+ )
805
+
806
+ # Rules must be early like actions.
807
+ if "rules" in spec:
808
+ self.WriteRules(
809
+ spec["rules"],
810
+ extra_sources,
811
+ extra_outputs,
812
+ extra_mac_bundle_resources,
813
+ part_of_all,
814
+ )
815
+
816
+ if "copies" in spec:
817
+ self.WriteCopies(spec["copies"], extra_outputs, part_of_all)
818
+
819
+ # Bundle resources.
820
+ if self.is_mac_bundle:
821
+ all_mac_bundle_resources = (
822
+ spec.get("mac_bundle_resources", []) + extra_mac_bundle_resources
823
+ )
824
+ self.WriteMacBundleResources(all_mac_bundle_resources, mac_bundle_deps)
825
+ self.WriteMacInfoPlist(mac_bundle_deps)
826
+
827
+ # Sources.
828
+ all_sources = spec.get("sources", []) + extra_sources
829
+ if all_sources:
830
+ self.WriteSources(
831
+ configs,
832
+ deps,
833
+ all_sources,
834
+ extra_outputs,
835
+ extra_link_deps,
836
+ part_of_all,
837
+ gyp.xcode_emulation.MacPrefixHeader(
838
+ self.xcode_settings,
839
+ lambda p: Sourceify(self.Absolutify(p)),
840
+ self.Pchify,
841
+ ),
842
+ )
843
+ sources = [x for x in all_sources if Compilable(x)]
844
+ if sources:
845
+ self.WriteLn(SHARED_HEADER_SUFFIX_RULES_COMMENT1)
846
+ extensions = {os.path.splitext(s)[1] for s in sources}
847
+ for ext in extensions:
848
+ if ext in self.suffix_rules_srcdir:
849
+ self.WriteLn(self.suffix_rules_srcdir[ext])
850
+ self.WriteLn(SHARED_HEADER_SUFFIX_RULES_COMMENT2)
851
+ for ext in extensions:
852
+ if ext in self.suffix_rules_objdir1:
853
+ self.WriteLn(self.suffix_rules_objdir1[ext])
854
+ for ext in extensions:
855
+ if ext in self.suffix_rules_objdir2:
856
+ self.WriteLn(self.suffix_rules_objdir2[ext])
857
+ self.WriteLn("# End of this set of suffix rules")
858
+
859
+ # Add dependency from bundle to bundle binary.
860
+ if self.is_mac_bundle:
861
+ mac_bundle_deps.append(self.output_binary)
862
+
863
+ self.WriteTarget(
864
+ spec,
865
+ configs,
866
+ deps,
867
+ extra_link_deps + link_deps,
868
+ mac_bundle_deps,
869
+ extra_outputs,
870
+ part_of_all,
871
+ )
872
+
873
+ # Update global list of target outputs, used in dependency tracking.
874
+ target_outputs[qualified_target] = install_path
875
+
876
+ # Update global list of link dependencies.
877
+ if self.type in ("static_library", "shared_library"):
878
+ target_link_deps[qualified_target] = self.output_binary
879
+
880
+ # Currently any versions have the same effect, but in future the behavior
881
+ # could be different.
882
+ if self.generator_flags.get("android_ndk_version", None):
883
+ self.WriteAndroidNdkModuleRule(self.target, all_sources, link_deps)
884
+
885
+ self.fp.close()
886
+
887
+ def WriteSubMake(self, output_filename, makefile_path, targets, build_dir):
888
+ """Write a "sub-project" Makefile.
889
+
890
+ This is a small, wrapper Makefile that calls the top-level Makefile to build
891
+ the targets from a single gyp file (i.e. a sub-project).
892
+
893
+ Arguments:
894
+ output_filename: sub-project Makefile name to write
895
+ makefile_path: path to the top-level Makefile
896
+ targets: list of "all" targets for this sub-project
897
+ build_dir: build output directory, relative to the sub-project
898
+ """
899
+ gyp.common.EnsureDirExists(output_filename)
900
+ self.fp = open(output_filename, "w")
901
+ self.fp.write(header)
902
+ # For consistency with other builders, put sub-project build output in the
903
+ # sub-project dir (see test/subdirectory/gyptest-subdir-all.py).
904
+ self.WriteLn(
905
+ "export builddir_name ?= %s"
906
+ % os.path.join(os.path.dirname(output_filename), build_dir)
907
+ )
908
+ self.WriteLn(".PHONY: all")
909
+ self.WriteLn("all:")
910
+ if makefile_path:
911
+ makefile_path = " -C " + makefile_path
912
+ self.WriteLn("\t$(MAKE){} {}".format(makefile_path, " ".join(targets)))
913
+ self.fp.close()
914
+
915
+ def WriteActions(
916
+ self,
917
+ actions,
918
+ extra_sources,
919
+ extra_outputs,
920
+ extra_mac_bundle_resources,
921
+ part_of_all,
922
+ ):
923
+ """Write Makefile code for any 'actions' from the gyp input.
924
+
925
+ extra_sources: a list that will be filled in with newly generated source
926
+ files, if any
927
+ extra_outputs: a list that will be filled in with any outputs of these
928
+ actions (used to make other pieces dependent on these
929
+ actions)
930
+ part_of_all: flag indicating this target is part of 'all'
931
+ """
932
+ env = self.GetSortedXcodeEnv()
933
+ for action in actions:
934
+ name = StringToMakefileVariable(
935
+ "{}_{}".format(self.qualified_target, action["action_name"])
936
+ )
937
+ self.WriteLn('### Rules for action "%s":' % action["action_name"])
938
+ inputs = action["inputs"]
939
+ outputs = action["outputs"]
940
+
941
+ # Build up a list of outputs.
942
+ # Collect the output dirs we'll need.
943
+ dirs = set()
944
+ for out in outputs:
945
+ dir = os.path.split(out)[0]
946
+ if dir:
947
+ dirs.add(dir)
948
+ if int(action.get("process_outputs_as_sources", False)):
949
+ extra_sources += outputs
950
+ if int(action.get("process_outputs_as_mac_bundle_resources", False)):
951
+ extra_mac_bundle_resources += outputs
952
+
953
+ # Write the actual command.
954
+ action_commands = action["action"]
955
+ if self.flavor == "mac":
956
+ action_commands = [
957
+ gyp.xcode_emulation.ExpandEnvVars(command, env)
958
+ for command in action_commands
959
+ ]
960
+ command = gyp.common.EncodePOSIXShellList(action_commands)
961
+ if "message" in action:
962
+ self.WriteLn(
963
+ "quiet_cmd_{} = ACTION {} $@".format(name, action["message"])
964
+ )
965
+ else:
966
+ self.WriteLn(f"quiet_cmd_{name} = ACTION {name} $@")
967
+ if len(dirs) > 0:
968
+ command = "mkdir -p %s" % " ".join(dirs) + "; " + command
969
+
970
+ cd_action = "cd %s; " % Sourceify(self.path or ".")
971
+
972
+ # command and cd_action get written to a toplevel variable called
973
+ # cmd_foo. Toplevel variables can't handle things that change per
974
+ # makefile like $(TARGET), so hardcode the target.
975
+ command = command.replace("$(TARGET)", self.target)
976
+ cd_action = cd_action.replace("$(TARGET)", self.target)
977
+
978
+ # Set LD_LIBRARY_PATH in case the action runs an executable from this
979
+ # build which links to shared libs from this build.
980
+ # actions run on the host, so they should in theory only use host
981
+ # libraries, but until everything is made cross-compile safe, also use
982
+ # target libraries.
983
+ # TODO(piman): when everything is cross-compile safe, remove lib.target
984
+ self.WriteLn(
985
+ "cmd_%s = LD_LIBRARY_PATH=$(builddir)/lib.host:"
986
+ "$(builddir)/lib.target:$$LD_LIBRARY_PATH; "
987
+ "export LD_LIBRARY_PATH; "
988
+ "%s%s" % (name, cd_action, command)
989
+ )
990
+ self.WriteLn()
991
+ outputs = [self.Absolutify(o) for o in outputs]
992
+ # The makefile rules are all relative to the top dir, but the gyp actions
993
+ # are defined relative to their containing dir. This replaces the obj
994
+ # variable for the action rule with an absolute version so that the output
995
+ # goes in the right place.
996
+ # Only write the 'obj' and 'builddir' rules for the "primary" output (:1);
997
+ # it's superfluous for the "extra outputs", and this avoids accidentally
998
+ # writing duplicate dummy rules for those outputs.
999
+ # Same for environment.
1000
+ self.WriteLn("%s: obj := $(abs_obj)" % QuoteSpaces(outputs[0]))
1001
+ self.WriteLn("%s: builddir := $(abs_builddir)" % QuoteSpaces(outputs[0]))
1002
+ self.WriteSortedXcodeEnv(outputs[0], self.GetSortedXcodeEnv())
1003
+
1004
+ for input in inputs:
1005
+ assert " " not in input, (
1006
+ "Spaces in action input filenames not supported (%s)" % input
1007
+ )
1008
+ for output in outputs:
1009
+ assert " " not in output, (
1010
+ "Spaces in action output filenames not supported (%s)" % output
1011
+ )
1012
+
1013
+ # See the comment in WriteCopies about expanding env vars.
1014
+ outputs = [gyp.xcode_emulation.ExpandEnvVars(o, env) for o in outputs]
1015
+ inputs = [gyp.xcode_emulation.ExpandEnvVars(i, env) for i in inputs]
1016
+
1017
+ self.WriteDoCmd(
1018
+ outputs,
1019
+ [Sourceify(self.Absolutify(i)) for i in inputs],
1020
+ part_of_all=part_of_all,
1021
+ command=name,
1022
+ )
1023
+
1024
+ # Stuff the outputs in a variable so we can refer to them later.
1025
+ outputs_variable = "action_%s_outputs" % name
1026
+ self.WriteLn("{} := {}".format(outputs_variable, " ".join(outputs)))
1027
+ extra_outputs.append("$(%s)" % outputs_variable)
1028
+ self.WriteLn()
1029
+
1030
+ self.WriteLn()
1031
+
1032
+ def WriteRules(
1033
+ self,
1034
+ rules,
1035
+ extra_sources,
1036
+ extra_outputs,
1037
+ extra_mac_bundle_resources,
1038
+ part_of_all,
1039
+ ):
1040
+ """Write Makefile code for any 'rules' from the gyp input.
1041
+
1042
+ extra_sources: a list that will be filled in with newly generated source
1043
+ files, if any
1044
+ extra_outputs: a list that will be filled in with any outputs of these
1045
+ rules (used to make other pieces dependent on these rules)
1046
+ part_of_all: flag indicating this target is part of 'all'
1047
+ """
1048
+ env = self.GetSortedXcodeEnv()
1049
+ for rule in rules:
1050
+ name = StringToMakefileVariable(
1051
+ "{}_{}".format(self.qualified_target, rule["rule_name"])
1052
+ )
1053
+ count = 0
1054
+ self.WriteLn("### Generated for rule %s:" % name)
1055
+
1056
+ all_outputs = []
1057
+
1058
+ for rule_source in rule.get("rule_sources", []):
1059
+ dirs = set()
1060
+ (rule_source_dirname, rule_source_basename) = os.path.split(rule_source)
1061
+ (rule_source_root, rule_source_ext) = os.path.splitext(
1062
+ rule_source_basename
1063
+ )
1064
+
1065
+ outputs = [
1066
+ self.ExpandInputRoot(out, rule_source_root, rule_source_dirname)
1067
+ for out in rule["outputs"]
1068
+ ]
1069
+
1070
+ for out in outputs:
1071
+ dir = os.path.dirname(out)
1072
+ if dir:
1073
+ dirs.add(dir)
1074
+ if int(rule.get("process_outputs_as_sources", False)):
1075
+ extra_sources += outputs
1076
+ if int(rule.get("process_outputs_as_mac_bundle_resources", False)):
1077
+ extra_mac_bundle_resources += outputs
1078
+ inputs = [
1079
+ Sourceify(self.Absolutify(i))
1080
+ for i in [rule_source] + rule.get("inputs", [])
1081
+ ]
1082
+ actions = ["$(call do_cmd,%s_%d)" % (name, count)]
1083
+
1084
+ if name == "resources_grit":
1085
+ # HACK: This is ugly. Grit intentionally doesn't touch the
1086
+ # timestamp of its output file when the file doesn't change,
1087
+ # which is fine in hash-based dependency systems like scons
1088
+ # and forge, but not kosher in the make world. After some
1089
+ # discussion, hacking around it here seems like the least
1090
+ # amount of pain.
1091
+ actions += ["@touch --no-create $@"]
1092
+
1093
+ # See the comment in WriteCopies about expanding env vars.
1094
+ outputs = [gyp.xcode_emulation.ExpandEnvVars(o, env) for o in outputs]
1095
+ inputs = [gyp.xcode_emulation.ExpandEnvVars(i, env) for i in inputs]
1096
+
1097
+ outputs = [self.Absolutify(o) for o in outputs]
1098
+ all_outputs += outputs
1099
+ # Only write the 'obj' and 'builddir' rules for the "primary" output
1100
+ # (:1); it's superfluous for the "extra outputs", and this avoids
1101
+ # accidentally writing duplicate dummy rules for those outputs.
1102
+ self.WriteLn("%s: obj := $(abs_obj)" % outputs[0])
1103
+ self.WriteLn("%s: builddir := $(abs_builddir)" % outputs[0])
1104
+ self.WriteMakeRule(
1105
+ outputs, inputs, actions, command="%s_%d" % (name, count)
1106
+ )
1107
+ # Spaces in rule filenames are not supported, but rule variables have
1108
+ # spaces in them (e.g. RULE_INPUT_PATH expands to '$(abspath $<)').
1109
+ # The spaces within the variables are valid, so remove the variables
1110
+ # before checking.
1111
+ variables_with_spaces = re.compile(r"\$\([^ ]* \$<\)")
1112
+ for output in outputs:
1113
+ output = re.sub(variables_with_spaces, "", output)
1114
+ assert " " not in output, (
1115
+ "Spaces in rule filenames not yet supported (%s)" % output
1116
+ )
1117
+ self.WriteLn("all_deps += %s" % " ".join(outputs))
1118
+
1119
+ action = [
1120
+ self.ExpandInputRoot(ac, rule_source_root, rule_source_dirname)
1121
+ for ac in rule["action"]
1122
+ ]
1123
+ mkdirs = ""
1124
+ if len(dirs) > 0:
1125
+ mkdirs = "mkdir -p %s; " % " ".join(dirs)
1126
+ cd_action = "cd %s; " % Sourceify(self.path or ".")
1127
+
1128
+ # action, cd_action, and mkdirs get written to a toplevel variable
1129
+ # called cmd_foo. Toplevel variables can't handle things that change
1130
+ # per makefile like $(TARGET), so hardcode the target.
1131
+ if self.flavor == "mac":
1132
+ action = [
1133
+ gyp.xcode_emulation.ExpandEnvVars(command, env)
1134
+ for command in action
1135
+ ]
1136
+ action = gyp.common.EncodePOSIXShellList(action)
1137
+ action = action.replace("$(TARGET)", self.target)
1138
+ cd_action = cd_action.replace("$(TARGET)", self.target)
1139
+ mkdirs = mkdirs.replace("$(TARGET)", self.target)
1140
+
1141
+ # Set LD_LIBRARY_PATH in case the rule runs an executable from this
1142
+ # build which links to shared libs from this build.
1143
+ # rules run on the host, so they should in theory only use host
1144
+ # libraries, but until everything is made cross-compile safe, also use
1145
+ # target libraries.
1146
+ # TODO(piman): when everything is cross-compile safe, remove lib.target
1147
+ self.WriteLn(
1148
+ "cmd_%(name)s_%(count)d = LD_LIBRARY_PATH="
1149
+ "$(builddir)/lib.host:$(builddir)/lib.target:$$LD_LIBRARY_PATH; "
1150
+ "export LD_LIBRARY_PATH; "
1151
+ "%(cd_action)s%(mkdirs)s%(action)s"
1152
+ % {
1153
+ "action": action,
1154
+ "cd_action": cd_action,
1155
+ "count": count,
1156
+ "mkdirs": mkdirs,
1157
+ "name": name,
1158
+ }
1159
+ )
1160
+ self.WriteLn(
1161
+ "quiet_cmd_%(name)s_%(count)d = RULE %(name)s_%(count)d $@"
1162
+ % {"count": count, "name": name}
1163
+ )
1164
+ self.WriteLn()
1165
+ count += 1
1166
+
1167
+ outputs_variable = "rule_%s_outputs" % name
1168
+ self.WriteList(all_outputs, outputs_variable)
1169
+ extra_outputs.append("$(%s)" % outputs_variable)
1170
+
1171
+ self.WriteLn("### Finished generating for rule: %s" % name)
1172
+ self.WriteLn()
1173
+ self.WriteLn("### Finished generating for all rules")
1174
+ self.WriteLn("")
1175
+
1176
+ def WriteCopies(self, copies, extra_outputs, part_of_all):
1177
+ """Write Makefile code for any 'copies' from the gyp input.
1178
+
1179
+ extra_outputs: a list that will be filled in with any outputs of this action
1180
+ (used to make other pieces dependent on this action)
1181
+ part_of_all: flag indicating this target is part of 'all'
1182
+ """
1183
+ self.WriteLn("### Generated for copy rule.")
1184
+
1185
+ variable = StringToMakefileVariable(self.qualified_target + "_copies")
1186
+ outputs = []
1187
+ for copy in copies:
1188
+ for path in copy["files"]:
1189
+ # Absolutify() may call normpath, and will strip trailing slashes.
1190
+ path = Sourceify(self.Absolutify(path))
1191
+ filename = os.path.split(path)[1]
1192
+ output = Sourceify(
1193
+ self.Absolutify(os.path.join(copy["destination"], filename))
1194
+ )
1195
+
1196
+ # If the output path has variables in it, which happens in practice for
1197
+ # 'copies', writing the environment as target-local doesn't work,
1198
+ # because the variables are already needed for the target name.
1199
+ # Copying the environment variables into global make variables doesn't
1200
+ # work either, because then the .d files will potentially contain spaces
1201
+ # after variable expansion, and .d file handling cannot handle spaces.
1202
+ # As a workaround, manually expand variables at gyp time. Since 'copies'
1203
+ # can't run scripts, there's no need to write the env then.
1204
+ # WriteDoCmd() will escape spaces for .d files.
1205
+ env = self.GetSortedXcodeEnv()
1206
+ output = gyp.xcode_emulation.ExpandEnvVars(output, env)
1207
+ path = gyp.xcode_emulation.ExpandEnvVars(path, env)
1208
+ self.WriteDoCmd([output], [path], "copy", part_of_all)
1209
+ outputs.append(output)
1210
+ self.WriteLn(
1211
+ "{} = {}".format(variable, " ".join(QuoteSpaces(o) for o in outputs))
1212
+ )
1213
+ extra_outputs.append("$(%s)" % variable)
1214
+ self.WriteLn()
1215
+
1216
+ def WriteMacBundleResources(self, resources, bundle_deps):
1217
+ """Writes Makefile code for 'mac_bundle_resources'."""
1218
+ self.WriteLn("### Generated for mac_bundle_resources")
1219
+
1220
+ for output, res in gyp.xcode_emulation.GetMacBundleResources(
1221
+ generator_default_variables["PRODUCT_DIR"],
1222
+ self.xcode_settings,
1223
+ [Sourceify(self.Absolutify(r)) for r in resources],
1224
+ ):
1225
+ _, ext = os.path.splitext(output)
1226
+ if ext != ".xcassets":
1227
+ # Make does not supports '.xcassets' emulation.
1228
+ self.WriteDoCmd(
1229
+ [output], [res], "mac_tool,,,copy-bundle-resource", part_of_all=True
1230
+ )
1231
+ bundle_deps.append(output)
1232
+
1233
+ def WriteMacInfoPlist(self, bundle_deps):
1234
+ """Write Makefile code for bundle Info.plist files."""
1235
+ info_plist, out, defines, extra_env = gyp.xcode_emulation.GetMacInfoPlist(
1236
+ generator_default_variables["PRODUCT_DIR"],
1237
+ self.xcode_settings,
1238
+ lambda p: Sourceify(self.Absolutify(p)),
1239
+ )
1240
+ if not info_plist:
1241
+ return
1242
+ if defines:
1243
+ # Create an intermediate file to store preprocessed results.
1244
+ intermediate_plist = "$(obj).$(TOOLSET)/$(TARGET)/" + os.path.basename(
1245
+ info_plist
1246
+ )
1247
+ self.WriteList(
1248
+ defines,
1249
+ intermediate_plist + ": INFOPLIST_DEFINES",
1250
+ "-D",
1251
+ quoter=EscapeCppDefine,
1252
+ )
1253
+ self.WriteMakeRule(
1254
+ [intermediate_plist],
1255
+ [info_plist],
1256
+ [
1257
+ "$(call do_cmd,infoplist)",
1258
+ # "Convert" the plist so that any weird whitespace changes from the
1259
+ # preprocessor do not affect the XML parser in mac_tool.
1260
+ "@plutil -convert xml1 $@ $@",
1261
+ ],
1262
+ )
1263
+ info_plist = intermediate_plist
1264
+ # plists can contain envvars and substitute them into the file.
1265
+ self.WriteSortedXcodeEnv(
1266
+ out, self.GetSortedXcodeEnv(additional_settings=extra_env)
1267
+ )
1268
+ self.WriteDoCmd(
1269
+ [out], [info_plist], "mac_tool,,,copy-info-plist", part_of_all=True
1270
+ )
1271
+ bundle_deps.append(out)
1272
+
1273
+ def WriteSources(
1274
+ self,
1275
+ configs,
1276
+ deps,
1277
+ sources,
1278
+ extra_outputs,
1279
+ extra_link_deps,
1280
+ part_of_all,
1281
+ precompiled_header,
1282
+ ):
1283
+ """Write Makefile code for any 'sources' from the gyp input.
1284
+ These are source files necessary to build the current target.
1285
+
1286
+ configs, deps, sources: input from gyp.
1287
+ extra_outputs: a list of extra outputs this action should be dependent on;
1288
+ used to serialize action/rules before compilation
1289
+ extra_link_deps: a list that will be filled in with any outputs of
1290
+ compilation (to be used in link lines)
1291
+ part_of_all: flag indicating this target is part of 'all'
1292
+ """
1293
+
1294
+ # Write configuration-specific variables for CFLAGS, etc.
1295
+ for configname in sorted(configs.keys()):
1296
+ config = configs[configname]
1297
+ self.WriteList(
1298
+ config.get("defines"),
1299
+ "DEFS_%s" % configname,
1300
+ prefix="-D",
1301
+ quoter=EscapeCppDefine,
1302
+ )
1303
+
1304
+ if self.flavor == "mac":
1305
+ cflags = self.xcode_settings.GetCflags(
1306
+ configname, arch=config.get("xcode_configuration_platform")
1307
+ )
1308
+ cflags_c = self.xcode_settings.GetCflagsC(configname)
1309
+ cflags_cc = self.xcode_settings.GetCflagsCC(configname)
1310
+ cflags_objc = self.xcode_settings.GetCflagsObjC(configname)
1311
+ cflags_objcc = self.xcode_settings.GetCflagsObjCC(configname)
1312
+ else:
1313
+ cflags = config.get("cflags")
1314
+ cflags_c = config.get("cflags_c")
1315
+ cflags_cc = config.get("cflags_cc")
1316
+
1317
+ self.WriteLn("# Flags passed to all source files.")
1318
+ self.WriteList(cflags, "CFLAGS_%s" % configname)
1319
+ self.WriteLn("# Flags passed to only C files.")
1320
+ self.WriteList(cflags_c, "CFLAGS_C_%s" % configname)
1321
+ self.WriteLn("# Flags passed to only C++ files.")
1322
+ self.WriteList(cflags_cc, "CFLAGS_CC_%s" % configname)
1323
+ if self.flavor == "mac":
1324
+ self.WriteLn("# Flags passed to only ObjC files.")
1325
+ self.WriteList(cflags_objc, "CFLAGS_OBJC_%s" % configname)
1326
+ self.WriteLn("# Flags passed to only ObjC++ files.")
1327
+ self.WriteList(cflags_objcc, "CFLAGS_OBJCC_%s" % configname)
1328
+ includes = config.get("include_dirs")
1329
+ if includes:
1330
+ includes = [Sourceify(self.Absolutify(i)) for i in includes]
1331
+ self.WriteList(includes, "INCS_%s" % configname, prefix="-I")
1332
+
1333
+ compilable = list(filter(Compilable, sources))
1334
+ objs = [self.Objectify(self.Absolutify(Target(c))) for c in compilable]
1335
+ self.WriteList(objs, "OBJS")
1336
+
1337
+ for obj in objs:
1338
+ assert " " not in obj, "Spaces in object filenames not supported (%s)" % obj
1339
+ self.WriteLn(
1340
+ "# Add to the list of files we specially track " "dependencies for."
1341
+ )
1342
+ self.WriteLn("all_deps += $(OBJS)")
1343
+ self.WriteLn()
1344
+
1345
+ # Make sure our dependencies are built first.
1346
+ if deps:
1347
+ self.WriteMakeRule(
1348
+ ["$(OBJS)"],
1349
+ deps,
1350
+ comment="Make sure our dependencies are built " "before any of us.",
1351
+ order_only=True,
1352
+ )
1353
+
1354
+ # Make sure the actions and rules run first.
1355
+ # If they generate any extra headers etc., the per-.o file dep tracking
1356
+ # will catch the proper rebuilds, so order only is still ok here.
1357
+ if extra_outputs:
1358
+ self.WriteMakeRule(
1359
+ ["$(OBJS)"],
1360
+ extra_outputs,
1361
+ comment="Make sure our actions/rules run " "before any of us.",
1362
+ order_only=True,
1363
+ )
1364
+
1365
+ pchdeps = precompiled_header.GetObjDependencies(compilable, objs)
1366
+ if pchdeps:
1367
+ self.WriteLn("# Dependencies from obj files to their precompiled headers")
1368
+ for source, obj, gch in pchdeps:
1369
+ self.WriteLn(f"{obj}: {gch}")
1370
+ self.WriteLn("# End precompiled header dependencies")
1371
+
1372
+ if objs:
1373
+ extra_link_deps.append("$(OBJS)")
1374
+ self.WriteLn(
1375
+ """\
1376
+ # CFLAGS et al overrides must be target-local.
1377
+ # See "Target-specific Variable Values" in the GNU Make manual."""
1378
+ )
1379
+ self.WriteLn("$(OBJS): TOOLSET := $(TOOLSET)")
1380
+ self.WriteLn(
1381
+ "$(OBJS): GYP_CFLAGS := "
1382
+ "$(DEFS_$(BUILDTYPE)) "
1383
+ "$(INCS_$(BUILDTYPE)) "
1384
+ "%s " % precompiled_header.GetInclude("c") + "$(CFLAGS_$(BUILDTYPE)) "
1385
+ "$(CFLAGS_C_$(BUILDTYPE))"
1386
+ )
1387
+ self.WriteLn(
1388
+ "$(OBJS): GYP_CXXFLAGS := "
1389
+ "$(DEFS_$(BUILDTYPE)) "
1390
+ "$(INCS_$(BUILDTYPE)) "
1391
+ "%s " % precompiled_header.GetInclude("cc") + "$(CFLAGS_$(BUILDTYPE)) "
1392
+ "$(CFLAGS_CC_$(BUILDTYPE))"
1393
+ )
1394
+ if self.flavor == "mac":
1395
+ self.WriteLn(
1396
+ "$(OBJS): GYP_OBJCFLAGS := "
1397
+ "$(DEFS_$(BUILDTYPE)) "
1398
+ "$(INCS_$(BUILDTYPE)) "
1399
+ "%s " % precompiled_header.GetInclude("m")
1400
+ + "$(CFLAGS_$(BUILDTYPE)) "
1401
+ "$(CFLAGS_C_$(BUILDTYPE)) "
1402
+ "$(CFLAGS_OBJC_$(BUILDTYPE))"
1403
+ )
1404
+ self.WriteLn(
1405
+ "$(OBJS): GYP_OBJCXXFLAGS := "
1406
+ "$(DEFS_$(BUILDTYPE)) "
1407
+ "$(INCS_$(BUILDTYPE)) "
1408
+ "%s " % precompiled_header.GetInclude("mm")
1409
+ + "$(CFLAGS_$(BUILDTYPE)) "
1410
+ "$(CFLAGS_CC_$(BUILDTYPE)) "
1411
+ "$(CFLAGS_OBJCC_$(BUILDTYPE))"
1412
+ )
1413
+
1414
+ self.WritePchTargets(precompiled_header.GetPchBuildCommands())
1415
+
1416
+ # If there are any object files in our input file list, link them into our
1417
+ # output.
1418
+ extra_link_deps += [source for source in sources if Linkable(source)]
1419
+
1420
+ self.WriteLn()
1421
+
1422
+ def WritePchTargets(self, pch_commands):
1423
+ """Writes make rules to compile prefix headers."""
1424
+ if not pch_commands:
1425
+ return
1426
+
1427
+ for gch, lang_flag, lang, input in pch_commands:
1428
+ extra_flags = {
1429
+ "c": "$(CFLAGS_C_$(BUILDTYPE))",
1430
+ "cc": "$(CFLAGS_CC_$(BUILDTYPE))",
1431
+ "m": "$(CFLAGS_C_$(BUILDTYPE)) $(CFLAGS_OBJC_$(BUILDTYPE))",
1432
+ "mm": "$(CFLAGS_CC_$(BUILDTYPE)) $(CFLAGS_OBJCC_$(BUILDTYPE))",
1433
+ }[lang]
1434
+ var_name = {
1435
+ "c": "GYP_PCH_CFLAGS",
1436
+ "cc": "GYP_PCH_CXXFLAGS",
1437
+ "m": "GYP_PCH_OBJCFLAGS",
1438
+ "mm": "GYP_PCH_OBJCXXFLAGS",
1439
+ }[lang]
1440
+ self.WriteLn(
1441
+ f"{gch}: {var_name} := {lang_flag} " + "$(DEFS_$(BUILDTYPE)) "
1442
+ "$(INCS_$(BUILDTYPE)) "
1443
+ "$(CFLAGS_$(BUILDTYPE)) " + extra_flags
1444
+ )
1445
+
1446
+ self.WriteLn(f"{gch}: {input} FORCE_DO_CMD")
1447
+ self.WriteLn("\t@$(call do_cmd,pch_%s,1)" % lang)
1448
+ self.WriteLn("")
1449
+ assert " " not in gch, "Spaces in gch filenames not supported (%s)" % gch
1450
+ self.WriteLn("all_deps += %s" % gch)
1451
+ self.WriteLn("")
1452
+
1453
+ def ComputeOutputBasename(self, spec):
1454
+ """Return the 'output basename' of a gyp spec.
1455
+
1456
+ E.g., the loadable module 'foobar' in directory 'baz' will produce
1457
+ 'libfoobar.so'
1458
+ """
1459
+ assert not self.is_mac_bundle
1460
+
1461
+ if self.flavor == "mac" and self.type in (
1462
+ "static_library",
1463
+ "executable",
1464
+ "shared_library",
1465
+ "loadable_module",
1466
+ ):
1467
+ return self.xcode_settings.GetExecutablePath()
1468
+
1469
+ target = spec["target_name"]
1470
+ target_prefix = ""
1471
+ target_ext = ""
1472
+ if self.type == "static_library":
1473
+ if target[:3] == "lib":
1474
+ target = target[3:]
1475
+ target_prefix = "lib"
1476
+ target_ext = ".a"
1477
+ elif self.type in ("loadable_module", "shared_library"):
1478
+ if target[:3] == "lib":
1479
+ target = target[3:]
1480
+ target_prefix = "lib"
1481
+ if self.flavor == "aix":
1482
+ target_ext = ".a"
1483
+ else:
1484
+ target_ext = ".so"
1485
+ elif self.type == "none":
1486
+ target = "%s.stamp" % target
1487
+ elif self.type != "executable":
1488
+ print(
1489
+ "ERROR: What output file should be generated?",
1490
+ "type",
1491
+ self.type,
1492
+ "target",
1493
+ target,
1494
+ )
1495
+
1496
+ target_prefix = spec.get("product_prefix", target_prefix)
1497
+ target = spec.get("product_name", target)
1498
+ product_ext = spec.get("product_extension")
1499
+ if product_ext:
1500
+ target_ext = "." + product_ext
1501
+
1502
+ return target_prefix + target + target_ext
1503
+
1504
+ def _InstallImmediately(self):
1505
+ return (
1506
+ self.toolset == "target"
1507
+ and self.flavor == "mac"
1508
+ and self.type
1509
+ in ("static_library", "executable", "shared_library", "loadable_module")
1510
+ )
1511
+
1512
+ def ComputeOutput(self, spec):
1513
+ """Return the 'output' (full output path) of a gyp spec.
1514
+
1515
+ E.g., the loadable module 'foobar' in directory 'baz' will produce
1516
+ '$(obj)/baz/libfoobar.so'
1517
+ """
1518
+ assert not self.is_mac_bundle
1519
+
1520
+ path = os.path.join("$(obj)." + self.toolset, self.path)
1521
+ if self.type == "executable" or self._InstallImmediately():
1522
+ path = "$(builddir)"
1523
+ path = spec.get("product_dir", path)
1524
+ return os.path.join(path, self.ComputeOutputBasename(spec))
1525
+
1526
+ def ComputeMacBundleOutput(self, spec):
1527
+ """Return the 'output' (full output path) to a bundle output directory."""
1528
+ assert self.is_mac_bundle
1529
+ path = generator_default_variables["PRODUCT_DIR"]
1530
+ return os.path.join(path, self.xcode_settings.GetWrapperName())
1531
+
1532
+ def ComputeMacBundleBinaryOutput(self, spec):
1533
+ """Return the 'output' (full output path) to the binary in a bundle."""
1534
+ path = generator_default_variables["PRODUCT_DIR"]
1535
+ return os.path.join(path, self.xcode_settings.GetExecutablePath())
1536
+
1537
+ def ComputeDeps(self, spec):
1538
+ """Compute the dependencies of a gyp spec.
1539
+
1540
+ Returns a tuple (deps, link_deps), where each is a list of
1541
+ filenames that will need to be put in front of make for either
1542
+ building (deps) or linking (link_deps).
1543
+ """
1544
+ deps = []
1545
+ link_deps = []
1546
+ if "dependencies" in spec:
1547
+ deps.extend(
1548
+ [
1549
+ target_outputs[dep]
1550
+ for dep in spec["dependencies"]
1551
+ if target_outputs[dep]
1552
+ ]
1553
+ )
1554
+ for dep in spec["dependencies"]:
1555
+ if dep in target_link_deps:
1556
+ link_deps.append(target_link_deps[dep])
1557
+ deps.extend(link_deps)
1558
+ # TODO: It seems we need to transitively link in libraries (e.g. -lfoo)?
1559
+ # This hack makes it work:
1560
+ # link_deps.extend(spec.get('libraries', []))
1561
+ return (gyp.common.uniquer(deps), gyp.common.uniquer(link_deps))
1562
+
1563
+ def WriteDependencyOnExtraOutputs(self, target, extra_outputs):
1564
+ self.WriteMakeRule(
1565
+ [self.output_binary],
1566
+ extra_outputs,
1567
+ comment="Build our special outputs first.",
1568
+ order_only=True,
1569
+ )
1570
+
1571
+ def WriteTarget(
1572
+ self, spec, configs, deps, link_deps, bundle_deps, extra_outputs, part_of_all
1573
+ ):
1574
+ """Write Makefile code to produce the final target of the gyp spec.
1575
+
1576
+ spec, configs: input from gyp.
1577
+ deps, link_deps: dependency lists; see ComputeDeps()
1578
+ extra_outputs: any extra outputs that our target should depend on
1579
+ part_of_all: flag indicating this target is part of 'all'
1580
+ """
1581
+
1582
+ self.WriteLn("### Rules for final target.")
1583
+
1584
+ if extra_outputs:
1585
+ self.WriteDependencyOnExtraOutputs(self.output_binary, extra_outputs)
1586
+ self.WriteMakeRule(
1587
+ extra_outputs,
1588
+ deps,
1589
+ comment=("Preserve order dependency of " "special output on deps."),
1590
+ order_only=True,
1591
+ )
1592
+
1593
+ target_postbuilds = {}
1594
+ if self.type != "none":
1595
+ for configname in sorted(configs.keys()):
1596
+ config = configs[configname]
1597
+ if self.flavor == "mac":
1598
+ ldflags = self.xcode_settings.GetLdflags(
1599
+ configname,
1600
+ generator_default_variables["PRODUCT_DIR"],
1601
+ lambda p: Sourceify(self.Absolutify(p)),
1602
+ arch=config.get("xcode_configuration_platform"),
1603
+ )
1604
+
1605
+ # TARGET_POSTBUILDS_$(BUILDTYPE) is added to postbuilds later on.
1606
+ gyp_to_build = gyp.common.InvertRelativePath(self.path)
1607
+ target_postbuild = self.xcode_settings.AddImplicitPostbuilds(
1608
+ configname,
1609
+ QuoteSpaces(
1610
+ os.path.normpath(os.path.join(gyp_to_build, self.output))
1611
+ ),
1612
+ QuoteSpaces(
1613
+ os.path.normpath(
1614
+ os.path.join(gyp_to_build, self.output_binary)
1615
+ )
1616
+ ),
1617
+ )
1618
+ if target_postbuild:
1619
+ target_postbuilds[configname] = target_postbuild
1620
+ else:
1621
+ ldflags = config.get("ldflags", [])
1622
+ # Compute an rpath for this output if needed.
1623
+ if any(dep.endswith(".so") or ".so." in dep for dep in deps):
1624
+ # We want to get the literal string "$ORIGIN"
1625
+ # into the link command, so we need lots of escaping.
1626
+ ldflags.append(r"-Wl,-rpath=\$$ORIGIN/")
1627
+ ldflags.append(r"-Wl,-rpath-link=\$(builddir)/")
1628
+ library_dirs = config.get("library_dirs", [])
1629
+ ldflags += [("-L%s" % library_dir) for library_dir in library_dirs]
1630
+ self.WriteList(ldflags, "LDFLAGS_%s" % configname)
1631
+ if self.flavor == "mac":
1632
+ self.WriteList(
1633
+ self.xcode_settings.GetLibtoolflags(configname),
1634
+ "LIBTOOLFLAGS_%s" % configname,
1635
+ )
1636
+ libraries = spec.get("libraries")
1637
+ if libraries:
1638
+ # Remove duplicate entries
1639
+ libraries = gyp.common.uniquer(libraries)
1640
+ if self.flavor == "mac":
1641
+ libraries = self.xcode_settings.AdjustLibraries(libraries)
1642
+ self.WriteList(libraries, "LIBS")
1643
+ self.WriteLn(
1644
+ "%s: GYP_LDFLAGS := $(LDFLAGS_$(BUILDTYPE))"
1645
+ % QuoteSpaces(self.output_binary)
1646
+ )
1647
+ self.WriteLn("%s: LIBS := $(LIBS)" % QuoteSpaces(self.output_binary))
1648
+
1649
+ if self.flavor == "mac":
1650
+ self.WriteLn(
1651
+ "%s: GYP_LIBTOOLFLAGS := $(LIBTOOLFLAGS_$(BUILDTYPE))"
1652
+ % QuoteSpaces(self.output_binary)
1653
+ )
1654
+
1655
+ # Postbuild actions. Like actions, but implicitly depend on the target's
1656
+ # output.
1657
+ postbuilds = []
1658
+ if self.flavor == "mac":
1659
+ if target_postbuilds:
1660
+ postbuilds.append("$(TARGET_POSTBUILDS_$(BUILDTYPE))")
1661
+ postbuilds.extend(gyp.xcode_emulation.GetSpecPostbuildCommands(spec))
1662
+
1663
+ if postbuilds:
1664
+ # Envvars may be referenced by TARGET_POSTBUILDS_$(BUILDTYPE),
1665
+ # so we must output its definition first, since we declare variables
1666
+ # using ":=".
1667
+ self.WriteSortedXcodeEnv(self.output, self.GetSortedXcodePostbuildEnv())
1668
+
1669
+ for configname in target_postbuilds:
1670
+ self.WriteLn(
1671
+ "%s: TARGET_POSTBUILDS_%s := %s"
1672
+ % (
1673
+ QuoteSpaces(self.output),
1674
+ configname,
1675
+ gyp.common.EncodePOSIXShellList(target_postbuilds[configname]),
1676
+ )
1677
+ )
1678
+
1679
+ # Postbuilds expect to be run in the gyp file's directory, so insert an
1680
+ # implicit postbuild to cd to there.
1681
+ postbuilds.insert(0, gyp.common.EncodePOSIXShellList(["cd", self.path]))
1682
+ for i, postbuild in enumerate(postbuilds):
1683
+ if not postbuild.startswith("$"):
1684
+ postbuilds[i] = EscapeShellArgument(postbuild)
1685
+ self.WriteLn("%s: builddir := $(abs_builddir)" % QuoteSpaces(self.output))
1686
+ self.WriteLn(
1687
+ "%s: POSTBUILDS := %s"
1688
+ % (QuoteSpaces(self.output), " ".join(postbuilds))
1689
+ )
1690
+
1691
+ # A bundle directory depends on its dependencies such as bundle resources
1692
+ # and bundle binary. When all dependencies have been built, the bundle
1693
+ # needs to be packaged.
1694
+ if self.is_mac_bundle:
1695
+ # If the framework doesn't contain a binary, then nothing depends
1696
+ # on the actions -- make the framework depend on them directly too.
1697
+ self.WriteDependencyOnExtraOutputs(self.output, extra_outputs)
1698
+
1699
+ # Bundle dependencies. Note that the code below adds actions to this
1700
+ # target, so if you move these two lines, move the lines below as well.
1701
+ self.WriteList([QuoteSpaces(dep) for dep in bundle_deps], "BUNDLE_DEPS")
1702
+ self.WriteLn("%s: $(BUNDLE_DEPS)" % QuoteSpaces(self.output))
1703
+
1704
+ # After the framework is built, package it. Needs to happen before
1705
+ # postbuilds, since postbuilds depend on this.
1706
+ if self.type in ("shared_library", "loadable_module"):
1707
+ self.WriteLn(
1708
+ "\t@$(call do_cmd,mac_package_framework,,,%s)"
1709
+ % self.xcode_settings.GetFrameworkVersion()
1710
+ )
1711
+
1712
+ # Bundle postbuilds can depend on the whole bundle, so run them after
1713
+ # the bundle is packaged, not already after the bundle binary is done.
1714
+ if postbuilds:
1715
+ self.WriteLn("\t@$(call do_postbuilds)")
1716
+ postbuilds = [] # Don't write postbuilds for target's output.
1717
+
1718
+ # Needed by test/mac/gyptest-rebuild.py.
1719
+ self.WriteLn("\t@true # No-op, used by tests")
1720
+
1721
+ # Since this target depends on binary and resources which are in
1722
+ # nested subfolders, the framework directory will be older than
1723
+ # its dependencies usually. To prevent this rule from executing
1724
+ # on every build (expensive, especially with postbuilds), expliclity
1725
+ # update the time on the framework directory.
1726
+ self.WriteLn("\t@touch -c %s" % QuoteSpaces(self.output))
1727
+
1728
+ if postbuilds:
1729
+ assert not self.is_mac_bundle, (
1730
+ "Postbuilds for bundles should be done "
1731
+ "on the bundle, not the binary (target '%s')" % self.target
1732
+ )
1733
+ assert "product_dir" not in spec, (
1734
+ "Postbuilds do not work with " "custom product_dir"
1735
+ )
1736
+
1737
+ if self.type == "executable":
1738
+ self.WriteLn(
1739
+ "%s: LD_INPUTS := %s"
1740
+ % (
1741
+ QuoteSpaces(self.output_binary),
1742
+ " ".join(QuoteSpaces(dep) for dep in link_deps),
1743
+ )
1744
+ )
1745
+ if self.toolset == "host" and self.flavor == "android":
1746
+ self.WriteDoCmd(
1747
+ [self.output_binary],
1748
+ link_deps,
1749
+ "link_host",
1750
+ part_of_all,
1751
+ postbuilds=postbuilds,
1752
+ )
1753
+ else:
1754
+ self.WriteDoCmd(
1755
+ [self.output_binary],
1756
+ link_deps,
1757
+ "link",
1758
+ part_of_all,
1759
+ postbuilds=postbuilds,
1760
+ )
1761
+
1762
+ elif self.type == "static_library":
1763
+ for link_dep in link_deps:
1764
+ assert " " not in link_dep, (
1765
+ "Spaces in alink input filenames not supported (%s)" % link_dep
1766
+ )
1767
+ if (
1768
+ self.flavor not in ("mac", "openbsd", "netbsd", "win")
1769
+ and not self.is_standalone_static_library
1770
+ ):
1771
+ self.WriteDoCmd(
1772
+ [self.output_binary],
1773
+ link_deps,
1774
+ "alink_thin",
1775
+ part_of_all,
1776
+ postbuilds=postbuilds,
1777
+ )
1778
+ else:
1779
+ self.WriteDoCmd(
1780
+ [self.output_binary],
1781
+ link_deps,
1782
+ "alink",
1783
+ part_of_all,
1784
+ postbuilds=postbuilds,
1785
+ )
1786
+ elif self.type == "shared_library":
1787
+ self.WriteLn(
1788
+ "%s: LD_INPUTS := %s"
1789
+ % (
1790
+ QuoteSpaces(self.output_binary),
1791
+ " ".join(QuoteSpaces(dep) for dep in link_deps),
1792
+ )
1793
+ )
1794
+ self.WriteDoCmd(
1795
+ [self.output_binary],
1796
+ link_deps,
1797
+ "solink",
1798
+ part_of_all,
1799
+ postbuilds=postbuilds,
1800
+ )
1801
+ elif self.type == "loadable_module":
1802
+ for link_dep in link_deps:
1803
+ assert " " not in link_dep, (
1804
+ "Spaces in module input filenames not supported (%s)" % link_dep
1805
+ )
1806
+ if self.toolset == "host" and self.flavor == "android":
1807
+ self.WriteDoCmd(
1808
+ [self.output_binary],
1809
+ link_deps,
1810
+ "solink_module_host",
1811
+ part_of_all,
1812
+ postbuilds=postbuilds,
1813
+ )
1814
+ else:
1815
+ self.WriteDoCmd(
1816
+ [self.output_binary],
1817
+ link_deps,
1818
+ "solink_module",
1819
+ part_of_all,
1820
+ postbuilds=postbuilds,
1821
+ )
1822
+ elif self.type == "none":
1823
+ # Write a stamp line.
1824
+ self.WriteDoCmd(
1825
+ [self.output_binary], deps, "touch", part_of_all, postbuilds=postbuilds
1826
+ )
1827
+ else:
1828
+ print("WARNING: no output for", self.type, self.target)
1829
+
1830
+ # Add an alias for each target (if there are any outputs).
1831
+ # Installable target aliases are created below.
1832
+ if (self.output and self.output != self.target) and (
1833
+ self.type not in self._INSTALLABLE_TARGETS
1834
+ ):
1835
+ self.WriteMakeRule(
1836
+ [self.target], [self.output], comment="Add target alias", phony=True
1837
+ )
1838
+ if part_of_all:
1839
+ self.WriteMakeRule(
1840
+ ["all"],
1841
+ [self.target],
1842
+ comment='Add target alias to "all" target.',
1843
+ phony=True,
1844
+ )
1845
+
1846
+ # Add special-case rules for our installable targets.
1847
+ # 1) They need to install to the build dir or "product" dir.
1848
+ # 2) They get shortcuts for building (e.g. "make chrome").
1849
+ # 3) They are part of "make all".
1850
+ if self.type in self._INSTALLABLE_TARGETS or self.is_standalone_static_library:
1851
+ if self.type == "shared_library":
1852
+ file_desc = "shared library"
1853
+ elif self.type == "static_library":
1854
+ file_desc = "static library"
1855
+ else:
1856
+ file_desc = "executable"
1857
+ install_path = self._InstallableTargetInstallPath()
1858
+ installable_deps = [self.output]
1859
+ if (
1860
+ self.flavor == "mac"
1861
+ and "product_dir" not in spec
1862
+ and self.toolset == "target"
1863
+ ):
1864
+ # On mac, products are created in install_path immediately.
1865
+ assert install_path == self.output, "{} != {}".format(
1866
+ install_path,
1867
+ self.output,
1868
+ )
1869
+
1870
+ # Point the target alias to the final binary output.
1871
+ self.WriteMakeRule(
1872
+ [self.target], [install_path], comment="Add target alias", phony=True
1873
+ )
1874
+ if install_path != self.output:
1875
+ assert not self.is_mac_bundle # See comment a few lines above.
1876
+ self.WriteDoCmd(
1877
+ [install_path],
1878
+ [self.output],
1879
+ "copy",
1880
+ comment="Copy this to the %s output path." % file_desc,
1881
+ part_of_all=part_of_all,
1882
+ )
1883
+ installable_deps.append(install_path)
1884
+ if self.output != self.alias and self.alias != self.target:
1885
+ self.WriteMakeRule(
1886
+ [self.alias],
1887
+ installable_deps,
1888
+ comment="Short alias for building this %s." % file_desc,
1889
+ phony=True,
1890
+ )
1891
+ if part_of_all:
1892
+ self.WriteMakeRule(
1893
+ ["all"],
1894
+ [install_path],
1895
+ comment='Add %s to "all" target.' % file_desc,
1896
+ phony=True,
1897
+ )
1898
+
1899
+ def WriteList(self, value_list, variable=None, prefix="", quoter=QuoteIfNecessary):
1900
+ """Write a variable definition that is a list of values.
1901
+
1902
+ E.g. WriteList(['a','b'], 'foo', prefix='blah') writes out
1903
+ foo = blaha blahb
1904
+ but in a pretty-printed style.
1905
+ """
1906
+ values = ""
1907
+ if value_list:
1908
+ value_list = [quoter(prefix + value) for value in value_list]
1909
+ values = " \\\n\t" + " \\\n\t".join(value_list)
1910
+ self.fp.write(f"{variable} :={values}\n\n")
1911
+
1912
+ def WriteDoCmd(
1913
+ self, outputs, inputs, command, part_of_all, comment=None, postbuilds=False
1914
+ ):
1915
+ """Write a Makefile rule that uses do_cmd.
1916
+
1917
+ This makes the outputs dependent on the command line that was run,
1918
+ as well as support the V= make command line flag.
1919
+ """
1920
+ suffix = ""
1921
+ if postbuilds:
1922
+ assert "," not in command
1923
+ suffix = ",,1" # Tell do_cmd to honor $POSTBUILDS
1924
+ self.WriteMakeRule(
1925
+ outputs,
1926
+ inputs,
1927
+ actions=[f"$(call do_cmd,{command}{suffix})"],
1928
+ comment=comment,
1929
+ command=command,
1930
+ force=True,
1931
+ )
1932
+ # Add our outputs to the list of targets we read depfiles from.
1933
+ # all_deps is only used for deps file reading, and for deps files we replace
1934
+ # spaces with ? because escaping doesn't work with make's $(sort) and
1935
+ # other functions.
1936
+ outputs = [QuoteSpaces(o, SPACE_REPLACEMENT) for o in outputs]
1937
+ self.WriteLn("all_deps += %s" % " ".join(outputs))
1938
+
1939
+ def WriteMakeRule(
1940
+ self,
1941
+ outputs,
1942
+ inputs,
1943
+ actions=None,
1944
+ comment=None,
1945
+ order_only=False,
1946
+ force=False,
1947
+ phony=False,
1948
+ command=None,
1949
+ ):
1950
+ """Write a Makefile rule, with some extra tricks.
1951
+
1952
+ outputs: a list of outputs for the rule (note: this is not directly
1953
+ supported by make; see comments below)
1954
+ inputs: a list of inputs for the rule
1955
+ actions: a list of shell commands to run for the rule
1956
+ comment: a comment to put in the Makefile above the rule (also useful
1957
+ for making this Python script's code self-documenting)
1958
+ order_only: if true, makes the dependency order-only
1959
+ force: if true, include FORCE_DO_CMD as an order-only dep
1960
+ phony: if true, the rule does not actually generate the named output, the
1961
+ output is just a name to run the rule
1962
+ command: (optional) command name to generate unambiguous labels
1963
+ """
1964
+ outputs = [QuoteSpaces(o) for o in outputs]
1965
+ inputs = [QuoteSpaces(i) for i in inputs]
1966
+
1967
+ if comment:
1968
+ self.WriteLn("# " + comment)
1969
+ if phony:
1970
+ self.WriteLn(".PHONY: " + " ".join(outputs))
1971
+ if actions:
1972
+ self.WriteLn("%s: TOOLSET := $(TOOLSET)" % outputs[0])
1973
+ force_append = " FORCE_DO_CMD" if force else ""
1974
+
1975
+ if order_only:
1976
+ # Order only rule: Just write a simple rule.
1977
+ # TODO(evanm): just make order_only a list of deps instead of this hack.
1978
+ self.WriteLn(
1979
+ "{}: | {}{}".format(" ".join(outputs), " ".join(inputs), force_append)
1980
+ )
1981
+ elif len(outputs) == 1:
1982
+ # Regular rule, one output: Just write a simple rule.
1983
+ self.WriteLn("{}: {}{}".format(outputs[0], " ".join(inputs), force_append))
1984
+ else:
1985
+ # Regular rule, more than one output: Multiple outputs are tricky in
1986
+ # make. We will write three rules:
1987
+ # - All outputs depend on an intermediate file.
1988
+ # - Make .INTERMEDIATE depend on the intermediate.
1989
+ # - The intermediate file depends on the inputs and executes the
1990
+ # actual command.
1991
+ # - The intermediate recipe will 'touch' the intermediate file.
1992
+ # - The multi-output rule will have an do-nothing recipe.
1993
+
1994
+ # Hash the target name to avoid generating overlong filenames.
1995
+ cmddigest = hashlib.sha1(
1996
+ (command or self.target).encode("utf-8")
1997
+ ).hexdigest()
1998
+ intermediate = "%s.intermediate" % cmddigest
1999
+ self.WriteLn("{}: {}".format(" ".join(outputs), intermediate))
2000
+ self.WriteLn("\t%s" % "@:")
2001
+ self.WriteLn("{}: {}".format(".INTERMEDIATE", intermediate))
2002
+ self.WriteLn(
2003
+ "{}: {}{}".format(intermediate, " ".join(inputs), force_append)
2004
+ )
2005
+ actions.insert(0, "$(call do_cmd,touch)")
2006
+
2007
+ if actions:
2008
+ for action in actions:
2009
+ self.WriteLn("\t%s" % action)
2010
+ self.WriteLn()
2011
+
2012
+ def WriteAndroidNdkModuleRule(self, module_name, all_sources, link_deps):
2013
+ """Write a set of LOCAL_XXX definitions for Android NDK.
2014
+
2015
+ These variable definitions will be used by Android NDK but do nothing for
2016
+ non-Android applications.
2017
+
2018
+ Arguments:
2019
+ module_name: Android NDK module name, which must be unique among all
2020
+ module names.
2021
+ all_sources: A list of source files (will be filtered by Compilable).
2022
+ link_deps: A list of link dependencies, which must be sorted in
2023
+ the order from dependencies to dependents.
2024
+ """
2025
+ if self.type not in ("executable", "shared_library", "static_library"):
2026
+ return
2027
+
2028
+ self.WriteLn("# Variable definitions for Android applications")
2029
+ self.WriteLn("include $(CLEAR_VARS)")
2030
+ self.WriteLn("LOCAL_MODULE := " + module_name)
2031
+ self.WriteLn(
2032
+ "LOCAL_CFLAGS := $(CFLAGS_$(BUILDTYPE)) "
2033
+ "$(DEFS_$(BUILDTYPE)) "
2034
+ # LOCAL_CFLAGS is applied to both of C and C++. There is
2035
+ # no way to specify $(CFLAGS_C_$(BUILDTYPE)) only for C
2036
+ # sources.
2037
+ "$(CFLAGS_C_$(BUILDTYPE)) "
2038
+ # $(INCS_$(BUILDTYPE)) includes the prefix '-I' while
2039
+ # LOCAL_C_INCLUDES does not expect it. So put it in
2040
+ # LOCAL_CFLAGS.
2041
+ "$(INCS_$(BUILDTYPE))"
2042
+ )
2043
+ # LOCAL_CXXFLAGS is obsolete and LOCAL_CPPFLAGS is preferred.
2044
+ self.WriteLn("LOCAL_CPPFLAGS := $(CFLAGS_CC_$(BUILDTYPE))")
2045
+ self.WriteLn("LOCAL_C_INCLUDES :=")
2046
+ self.WriteLn("LOCAL_LDLIBS := $(LDFLAGS_$(BUILDTYPE)) $(LIBS)")
2047
+
2048
+ # Detect the C++ extension.
2049
+ cpp_ext = {".cc": 0, ".cpp": 0, ".cxx": 0}
2050
+ default_cpp_ext = ".cpp"
2051
+ for filename in all_sources:
2052
+ ext = os.path.splitext(filename)[1]
2053
+ if ext in cpp_ext:
2054
+ cpp_ext[ext] += 1
2055
+ if cpp_ext[ext] > cpp_ext[default_cpp_ext]:
2056
+ default_cpp_ext = ext
2057
+ self.WriteLn("LOCAL_CPP_EXTENSION := " + default_cpp_ext)
2058
+
2059
+ self.WriteList(
2060
+ list(map(self.Absolutify, filter(Compilable, all_sources))),
2061
+ "LOCAL_SRC_FILES",
2062
+ )
2063
+
2064
+ # Filter out those which do not match prefix and suffix and produce
2065
+ # the resulting list without prefix and suffix.
2066
+ def DepsToModules(deps, prefix, suffix):
2067
+ modules = []
2068
+ for filepath in deps:
2069
+ filename = os.path.basename(filepath)
2070
+ if filename.startswith(prefix) and filename.endswith(suffix):
2071
+ modules.append(filename[len(prefix) : -len(suffix)])
2072
+ return modules
2073
+
2074
+ # Retrieve the default value of 'SHARED_LIB_SUFFIX'
2075
+ params = {"flavor": "linux"}
2076
+ default_variables = {}
2077
+ CalculateVariables(default_variables, params)
2078
+
2079
+ self.WriteList(
2080
+ DepsToModules(
2081
+ link_deps,
2082
+ generator_default_variables["SHARED_LIB_PREFIX"],
2083
+ default_variables["SHARED_LIB_SUFFIX"],
2084
+ ),
2085
+ "LOCAL_SHARED_LIBRARIES",
2086
+ )
2087
+ self.WriteList(
2088
+ DepsToModules(
2089
+ link_deps,
2090
+ generator_default_variables["STATIC_LIB_PREFIX"],
2091
+ generator_default_variables["STATIC_LIB_SUFFIX"],
2092
+ ),
2093
+ "LOCAL_STATIC_LIBRARIES",
2094
+ )
2095
+
2096
+ if self.type == "executable":
2097
+ self.WriteLn("include $(BUILD_EXECUTABLE)")
2098
+ elif self.type == "shared_library":
2099
+ self.WriteLn("include $(BUILD_SHARED_LIBRARY)")
2100
+ elif self.type == "static_library":
2101
+ self.WriteLn("include $(BUILD_STATIC_LIBRARY)")
2102
+ self.WriteLn()
2103
+
2104
+ def WriteLn(self, text=""):
2105
+ self.fp.write(text + "\n")
2106
+
2107
+ def GetSortedXcodeEnv(self, additional_settings=None):
2108
+ return gyp.xcode_emulation.GetSortedXcodeEnv(
2109
+ self.xcode_settings,
2110
+ "$(abs_builddir)",
2111
+ os.path.join("$(abs_srcdir)", self.path),
2112
+ "$(BUILDTYPE)",
2113
+ additional_settings,
2114
+ )
2115
+
2116
+ def GetSortedXcodePostbuildEnv(self):
2117
+ # CHROMIUM_STRIP_SAVE_FILE is a chromium-specific hack.
2118
+ # TODO(thakis): It would be nice to have some general mechanism instead.
2119
+ strip_save_file = self.xcode_settings.GetPerTargetSetting(
2120
+ "CHROMIUM_STRIP_SAVE_FILE", ""
2121
+ )
2122
+ # Even if strip_save_file is empty, explicitly write it. Else a postbuild
2123
+ # might pick up an export from an earlier target.
2124
+ return self.GetSortedXcodeEnv(
2125
+ additional_settings={"CHROMIUM_STRIP_SAVE_FILE": strip_save_file}
2126
+ )
2127
+
2128
+ def WriteSortedXcodeEnv(self, target, env):
2129
+ for k, v in env:
2130
+ # For
2131
+ # foo := a\ b
2132
+ # the escaped space does the right thing. For
2133
+ # export foo := a\ b
2134
+ # it does not -- the backslash is written to the env as literal character.
2135
+ # So don't escape spaces in |env[k]|.
2136
+ self.WriteLn(f"{QuoteSpaces(target)}: export {k} := {v}")
2137
+
2138
+ def Objectify(self, path):
2139
+ """Convert a path to its output directory form."""
2140
+ if "$(" in path:
2141
+ path = path.replace("$(obj)/", "$(obj).%s/$(TARGET)/" % self.toolset)
2142
+ if "$(obj)" not in path:
2143
+ path = f"$(obj).{self.toolset}/$(TARGET)/{path}"
2144
+ return path
2145
+
2146
+ def Pchify(self, path, lang):
2147
+ """Convert a prefix header path to its output directory form."""
2148
+ path = self.Absolutify(path)
2149
+ if "$(" in path:
2150
+ path = path.replace(
2151
+ "$(obj)/", f"$(obj).{self.toolset}/$(TARGET)/pch-{lang}"
2152
+ )
2153
+ return path
2154
+ return f"$(obj).{self.toolset}/$(TARGET)/pch-{lang}/{path}"
2155
+
2156
+ def Absolutify(self, path):
2157
+ """Convert a subdirectory-relative path into a base-relative path.
2158
+ Skips over paths that contain variables."""
2159
+ if "$(" in path:
2160
+ # Don't call normpath in this case, as it might collapse the
2161
+ # path too aggressively if it features '..'. However it's still
2162
+ # important to strip trailing slashes.
2163
+ return path.rstrip("/")
2164
+ return os.path.normpath(os.path.join(self.path, path))
2165
+
2166
+ def ExpandInputRoot(self, template, expansion, dirname):
2167
+ if "%(INPUT_ROOT)s" not in template and "%(INPUT_DIRNAME)s" not in template:
2168
+ return template
2169
+ path = template % {
2170
+ "INPUT_ROOT": expansion,
2171
+ "INPUT_DIRNAME": dirname,
2172
+ }
2173
+ return path
2174
+
2175
+ def _InstallableTargetInstallPath(self):
2176
+ """Returns the location of the final output for an installable target."""
2177
+ # Functionality removed for all platforms to match Xcode and hoist
2178
+ # shared libraries into PRODUCT_DIR for users:
2179
+ # Xcode puts shared_library results into PRODUCT_DIR, and some gyp files
2180
+ # rely on this. Emulate this behavior for mac.
2181
+ # if self.type == "shared_library" and (
2182
+ # self.flavor != "mac" or self.toolset != "target"
2183
+ # ):
2184
+ # # Install all shared libs into a common directory (per toolset) for
2185
+ # # convenient access with LD_LIBRARY_PATH.
2186
+ # return "$(builddir)/lib.%s/%s" % (self.toolset, self.alias)
2187
+ return "$(builddir)/" + self.alias
2188
+
2189
+
2190
+ def WriteAutoRegenerationRule(params, root_makefile, makefile_name, build_files):
2191
+ """Write the target to regenerate the Makefile."""
2192
+ options = params["options"]
2193
+ build_files_args = [
2194
+ gyp.common.RelativePath(filename, options.toplevel_dir)
2195
+ for filename in params["build_files_arg"]
2196
+ ]
2197
+
2198
+ gyp_binary = gyp.common.FixIfRelativePath(
2199
+ params["gyp_binary"], options.toplevel_dir
2200
+ )
2201
+ if not gyp_binary.startswith(os.sep):
2202
+ gyp_binary = os.path.join(".", gyp_binary)
2203
+
2204
+ root_makefile.write(
2205
+ "quiet_cmd_regen_makefile = ACTION Regenerating $@\n"
2206
+ "cmd_regen_makefile = cd $(srcdir); %(cmd)s\n"
2207
+ "%(makefile_name)s: %(deps)s\n"
2208
+ "\t$(call do_cmd,regen_makefile)\n\n"
2209
+ % {
2210
+ "makefile_name": makefile_name,
2211
+ "deps": " ".join(SourceifyAndQuoteSpaces(bf) for bf in build_files),
2212
+ "cmd": gyp.common.EncodePOSIXShellList(
2213
+ [gyp_binary, "-fmake"] + gyp.RegenerateFlags(options) + build_files_args
2214
+ ),
2215
+ }
2216
+ )
2217
+
2218
+
2219
+ def PerformBuild(data, configurations, params):
2220
+ options = params["options"]
2221
+ for config in configurations:
2222
+ arguments = ["make"]
2223
+ if options.toplevel_dir and options.toplevel_dir != ".":
2224
+ arguments += "-C", options.toplevel_dir
2225
+ arguments.append("BUILDTYPE=" + config)
2226
+ print(f"Building [{config}]: {arguments}")
2227
+ subprocess.check_call(arguments)
2228
+
2229
+
2230
+ def GenerateOutput(target_list, target_dicts, data, params):
2231
+ options = params["options"]
2232
+ flavor = gyp.common.GetFlavor(params)
2233
+ generator_flags = params.get("generator_flags", {})
2234
+ builddir_name = generator_flags.get("output_dir", "out")
2235
+ android_ndk_version = generator_flags.get("android_ndk_version", None)
2236
+ default_target = generator_flags.get("default_target", "all")
2237
+
2238
+ def CalculateMakefilePath(build_file, base_name):
2239
+ """Determine where to write a Makefile for a given gyp file."""
2240
+ # Paths in gyp files are relative to the .gyp file, but we want
2241
+ # paths relative to the source root for the master makefile. Grab
2242
+ # the path of the .gyp file as the base to relativize against.
2243
+ # E.g. "foo/bar" when we're constructing targets for "foo/bar/baz.gyp".
2244
+ base_path = gyp.common.RelativePath(os.path.dirname(build_file), options.depth)
2245
+ # We write the file in the base_path directory.
2246
+ output_file = os.path.join(options.depth, base_path, base_name)
2247
+ if options.generator_output:
2248
+ output_file = os.path.join(
2249
+ options.depth, options.generator_output, base_path, base_name
2250
+ )
2251
+ base_path = gyp.common.RelativePath(
2252
+ os.path.dirname(build_file), options.toplevel_dir
2253
+ )
2254
+ return base_path, output_file
2255
+
2256
+ # TODO: search for the first non-'Default' target. This can go
2257
+ # away when we add verification that all targets have the
2258
+ # necessary configurations.
2259
+ default_configuration = None
2260
+ toolsets = {target_dicts[target]["toolset"] for target in target_list}
2261
+ for target in target_list:
2262
+ spec = target_dicts[target]
2263
+ if spec["default_configuration"] != "Default":
2264
+ default_configuration = spec["default_configuration"]
2265
+ break
2266
+ if not default_configuration:
2267
+ default_configuration = "Default"
2268
+
2269
+ srcdir = "."
2270
+ makefile_name = "Makefile" + options.suffix
2271
+ makefile_path = os.path.join(options.toplevel_dir, makefile_name)
2272
+ if options.generator_output:
2273
+ global srcdir_prefix
2274
+ makefile_path = os.path.join(
2275
+ options.toplevel_dir, options.generator_output, makefile_name
2276
+ )
2277
+ srcdir = gyp.common.RelativePath(srcdir, options.generator_output)
2278
+ srcdir_prefix = "$(srcdir)/"
2279
+
2280
+ flock_command = "flock"
2281
+ copy_archive_arguments = "-af"
2282
+ makedep_arguments = "-MMD"
2283
+ header_params = {
2284
+ "default_target": default_target,
2285
+ "builddir": builddir_name,
2286
+ "default_configuration": default_configuration,
2287
+ "flock": flock_command,
2288
+ "flock_index": 1,
2289
+ "link_commands": LINK_COMMANDS_LINUX,
2290
+ "extra_commands": "",
2291
+ "srcdir": srcdir,
2292
+ "copy_archive_args": copy_archive_arguments,
2293
+ "makedep_args": makedep_arguments,
2294
+ "CC.target": GetEnvironFallback(("CC_target", "CC"), "$(CC)"),
2295
+ "AR.target": GetEnvironFallback(("AR_target", "AR"), "$(AR)"),
2296
+ "CXX.target": GetEnvironFallback(("CXX_target", "CXX"), "$(CXX)"),
2297
+ "LINK.target": GetEnvironFallback(("LINK_target", "LINK"), "$(LINK)"),
2298
+ "CC.host": GetEnvironFallback(("CC_host", "CC"), "gcc"),
2299
+ "AR.host": GetEnvironFallback(("AR_host", "AR"), "ar"),
2300
+ "CXX.host": GetEnvironFallback(("CXX_host", "CXX"), "g++"),
2301
+ "LINK.host": GetEnvironFallback(("LINK_host", "LINK"), "$(CXX.host)"),
2302
+ }
2303
+ if flavor == "mac":
2304
+ flock_command = "./gyp-mac-tool flock"
2305
+ header_params.update(
2306
+ {
2307
+ "flock": flock_command,
2308
+ "flock_index": 2,
2309
+ "link_commands": LINK_COMMANDS_MAC,
2310
+ "extra_commands": SHARED_HEADER_MAC_COMMANDS,
2311
+ }
2312
+ )
2313
+ elif flavor == "android":
2314
+ header_params.update({"link_commands": LINK_COMMANDS_ANDROID})
2315
+ elif flavor == "zos":
2316
+ copy_archive_arguments = "-fPR"
2317
+ makedep_arguments = "-qmakedep=gcc"
2318
+ header_params.update(
2319
+ {
2320
+ "copy_archive_args": copy_archive_arguments,
2321
+ "makedep_args": makedep_arguments,
2322
+ "link_commands": LINK_COMMANDS_OS390,
2323
+ "CC.target": GetEnvironFallback(("CC_target", "CC"), "njsc"),
2324
+ "CXX.target": GetEnvironFallback(("CXX_target", "CXX"), "njsc++"),
2325
+ "CC.host": GetEnvironFallback(("CC_host", "CC"), "njsc"),
2326
+ "CXX.host": GetEnvironFallback(("CXX_host", "CXX"), "njsc++"),
2327
+ }
2328
+ )
2329
+ elif flavor == "solaris":
2330
+ copy_archive_arguments = "-pPRf@"
2331
+ header_params.update(
2332
+ {
2333
+ "copy_archive_args": copy_archive_arguments,
2334
+ "flock": "./gyp-flock-tool flock",
2335
+ "flock_index": 2,
2336
+ }
2337
+ )
2338
+ elif flavor == "freebsd":
2339
+ # Note: OpenBSD has sysutils/flock. lockf seems to be FreeBSD specific.
2340
+ header_params.update({"flock": "lockf"})
2341
+ elif flavor == "openbsd":
2342
+ copy_archive_arguments = "-pPRf"
2343
+ header_params.update({"copy_archive_args": copy_archive_arguments})
2344
+ elif flavor == "aix":
2345
+ copy_archive_arguments = "-pPRf"
2346
+ header_params.update(
2347
+ {
2348
+ "copy_archive_args": copy_archive_arguments,
2349
+ "link_commands": LINK_COMMANDS_AIX,
2350
+ "flock": "./gyp-flock-tool flock",
2351
+ "flock_index": 2,
2352
+ }
2353
+ )
2354
+
2355
+ build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0])
2356
+ make_global_settings_array = data[build_file].get("make_global_settings", [])
2357
+ wrappers = {}
2358
+ for key, value in make_global_settings_array:
2359
+ if key.endswith("_wrapper"):
2360
+ wrappers[key[: -len("_wrapper")]] = "$(abspath %s)" % value
2361
+ make_global_settings = ""
2362
+ for key, value in make_global_settings_array:
2363
+ if re.match(".*_wrapper", key):
2364
+ continue
2365
+ if value[0] != "$":
2366
+ value = "$(abspath %s)" % value
2367
+ wrapper = wrappers.get(key)
2368
+ if wrapper:
2369
+ value = f"{wrapper} {value}"
2370
+ del wrappers[key]
2371
+ if key in ("CC", "CC.host", "CXX", "CXX.host"):
2372
+ make_global_settings += (
2373
+ "ifneq (,$(filter $(origin %s), undefined default))\n" % key
2374
+ )
2375
+ # Let gyp-time envvars win over global settings.
2376
+ env_key = key.replace(".", "_") # CC.host -> CC_host
2377
+ if env_key in os.environ:
2378
+ value = os.environ[env_key]
2379
+ make_global_settings += f" {key} = {value}\n"
2380
+ make_global_settings += "endif\n"
2381
+ else:
2382
+ make_global_settings += f"{key} ?= {value}\n"
2383
+ # TODO(ukai): define cmd when only wrapper is specified in
2384
+ # make_global_settings.
2385
+
2386
+ header_params["make_global_settings"] = make_global_settings
2387
+
2388
+ gyp.common.EnsureDirExists(makefile_path)
2389
+ root_makefile = open(makefile_path, "w")
2390
+ root_makefile.write(SHARED_HEADER % header_params)
2391
+ # Currently any versions have the same effect, but in future the behavior
2392
+ # could be different.
2393
+ if android_ndk_version:
2394
+ root_makefile.write(
2395
+ "# Define LOCAL_PATH for build of Android applications.\n"
2396
+ "LOCAL_PATH := $(call my-dir)\n"
2397
+ "\n"
2398
+ )
2399
+ for toolset in toolsets:
2400
+ root_makefile.write("TOOLSET := %s\n" % toolset)
2401
+ WriteRootHeaderSuffixRules(root_makefile)
2402
+
2403
+ # Put build-time support tools next to the root Makefile.
2404
+ dest_path = os.path.dirname(makefile_path)
2405
+ gyp.common.CopyTool(flavor, dest_path)
2406
+
2407
+ # Find the list of targets that derive from the gyp file(s) being built.
2408
+ needed_targets = set()
2409
+ for build_file in params["build_files"]:
2410
+ for target in gyp.common.AllTargets(target_list, target_dicts, build_file):
2411
+ needed_targets.add(target)
2412
+
2413
+ build_files = set()
2414
+ include_list = set()
2415
+ for qualified_target in target_list:
2416
+ build_file, target, toolset = gyp.common.ParseQualifiedTarget(qualified_target)
2417
+
2418
+ this_make_global_settings = data[build_file].get("make_global_settings", [])
2419
+ assert make_global_settings_array == this_make_global_settings, (
2420
+ "make_global_settings needs to be the same for all targets "
2421
+ f"{this_make_global_settings} vs. {make_global_settings}"
2422
+ )
2423
+
2424
+ build_files.add(gyp.common.RelativePath(build_file, options.toplevel_dir))
2425
+ included_files = data[build_file]["included_files"]
2426
+ for included_file in included_files:
2427
+ # The included_files entries are relative to the dir of the build file
2428
+ # that included them, so we have to undo that and then make them relative
2429
+ # to the root dir.
2430
+ relative_include_file = gyp.common.RelativePath(
2431
+ gyp.common.UnrelativePath(included_file, build_file),
2432
+ options.toplevel_dir,
2433
+ )
2434
+ abs_include_file = os.path.abspath(relative_include_file)
2435
+ # If the include file is from the ~/.gyp dir, we should use absolute path
2436
+ # so that relocating the src dir doesn't break the path.
2437
+ if params["home_dot_gyp"] and abs_include_file.startswith(
2438
+ params["home_dot_gyp"]
2439
+ ):
2440
+ build_files.add(abs_include_file)
2441
+ else:
2442
+ build_files.add(relative_include_file)
2443
+
2444
+ base_path, output_file = CalculateMakefilePath(
2445
+ build_file, target + "." + toolset + options.suffix + ".mk"
2446
+ )
2447
+
2448
+ spec = target_dicts[qualified_target]
2449
+ configs = spec["configurations"]
2450
+
2451
+ if flavor == "mac":
2452
+ gyp.xcode_emulation.MergeGlobalXcodeSettingsToSpec(data[build_file], spec)
2453
+
2454
+ writer = MakefileWriter(generator_flags, flavor)
2455
+ writer.Write(
2456
+ qualified_target,
2457
+ base_path,
2458
+ output_file,
2459
+ spec,
2460
+ configs,
2461
+ part_of_all=qualified_target in needed_targets,
2462
+ )
2463
+
2464
+ # Our root_makefile lives at the source root. Compute the relative path
2465
+ # from there to the output_file for including.
2466
+ mkfile_rel_path = gyp.common.RelativePath(
2467
+ output_file, os.path.dirname(makefile_path)
2468
+ )
2469
+ include_list.add(mkfile_rel_path)
2470
+
2471
+ # Write out per-gyp (sub-project) Makefiles.
2472
+ depth_rel_path = gyp.common.RelativePath(options.depth, os.getcwd())
2473
+ for build_file in build_files:
2474
+ # The paths in build_files were relativized above, so undo that before
2475
+ # testing against the non-relativized items in target_list and before
2476
+ # calculating the Makefile path.
2477
+ build_file = os.path.join(depth_rel_path, build_file)
2478
+ gyp_targets = [
2479
+ target_dicts[qualified_target]["target_name"]
2480
+ for qualified_target in target_list
2481
+ if qualified_target.startswith(build_file)
2482
+ and qualified_target in needed_targets
2483
+ ]
2484
+ # Only generate Makefiles for gyp files with targets.
2485
+ if not gyp_targets:
2486
+ continue
2487
+ base_path, output_file = CalculateMakefilePath(
2488
+ build_file, os.path.splitext(os.path.basename(build_file))[0] + ".Makefile"
2489
+ )
2490
+ makefile_rel_path = gyp.common.RelativePath(
2491
+ os.path.dirname(makefile_path), os.path.dirname(output_file)
2492
+ )
2493
+ writer.WriteSubMake(output_file, makefile_rel_path, gyp_targets, builddir_name)
2494
+
2495
+ # Write out the sorted list of includes.
2496
+ root_makefile.write("\n")
2497
+ for include_file in sorted(include_list):
2498
+ # We wrap each .mk include in an if statement so users can tell make to
2499
+ # not load a file by setting NO_LOAD. The below make code says, only
2500
+ # load the .mk file if the .mk filename doesn't start with a token in
2501
+ # NO_LOAD.
2502
+ root_makefile.write(
2503
+ "ifeq ($(strip $(foreach prefix,$(NO_LOAD),\\\n"
2504
+ " $(findstring $(join ^,$(prefix)),\\\n"
2505
+ " $(join ^," + include_file + ")))),)\n"
2506
+ )
2507
+ root_makefile.write(" include " + include_file + "\n")
2508
+ root_makefile.write("endif\n")
2509
+ root_makefile.write("\n")
2510
+
2511
+ if not generator_flags.get("standalone") and generator_flags.get(
2512
+ "auto_regeneration", True
2513
+ ):
2514
+ WriteAutoRegenerationRule(params, root_makefile, makefile_name, build_files)
2515
+
2516
+ root_makefile.write(SHARED_FOOTER)
2517
+
2518
+ root_makefile.close()