wsba-hockey 1.0.3__py3-none-any.whl → 1.0.5__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 (131) hide show
  1. wsba_hockey/__init__.py +1 -1
  2. wsba_hockey/data_pipelines.py +183 -0
  3. wsba_hockey/evidence/weakside-breakout/node_modules/duckdb/vendor.py +146 -0
  4. wsba_hockey/evidence/weakside-breakout/node_modules/flatted/python/flatted.py +149 -0
  5. wsba_hockey/evidence/weakside-breakout/node_modules/flatted/python/test.py +63 -0
  6. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  7. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +367 -0
  8. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  9. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1270 -0
  10. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
  11. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  12. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +153 -0
  13. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +271 -0
  14. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
  15. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +690 -0
  16. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/common.py +661 -0
  17. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +78 -0
  18. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +165 -0
  19. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +109 -0
  20. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  21. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  22. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +808 -0
  23. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1173 -0
  24. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1321 -0
  25. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +120 -0
  26. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +103 -0
  27. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +464 -0
  28. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
  29. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +58 -0
  30. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2714 -0
  31. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3981 -0
  32. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  33. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2936 -0
  34. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +55 -0
  35. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1394 -0
  36. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +25 -0
  37. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/input.py +3130 -0
  38. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +98 -0
  39. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +771 -0
  40. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1271 -0
  41. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  42. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  43. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +374 -0
  44. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1939 -0
  45. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +302 -0
  46. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3197 -0
  47. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
  48. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/test_gyp.py +261 -0
  49. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/graphviz.py +102 -0
  50. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_gyp.py +156 -0
  51. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_sln.py +181 -0
  52. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_vcproj.py +339 -0
  53. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/test/fixtures/test-charmap.py +31 -0
  54. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/update-gyp.py +64 -0
  55. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  56. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +367 -0
  57. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  58. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1270 -0
  59. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
  60. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  61. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +153 -0
  62. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +271 -0
  63. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
  64. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +666 -0
  65. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/common.py +654 -0
  66. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +78 -0
  67. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +165 -0
  68. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +109 -0
  69. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  70. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  71. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +808 -0
  72. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1173 -0
  73. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1321 -0
  74. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +120 -0
  75. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +103 -0
  76. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +464 -0
  77. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
  78. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +58 -0
  79. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2518 -0
  80. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3978 -0
  81. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  82. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2936 -0
  83. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +55 -0
  84. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1394 -0
  85. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +25 -0
  86. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/input.py +3137 -0
  87. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +98 -0
  88. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +771 -0
  89. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1271 -0
  90. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  91. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  92. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +374 -0
  93. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1939 -0
  94. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +302 -0
  95. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3197 -0
  96. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
  97. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/setup.py +42 -0
  98. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/test_gyp.py +260 -0
  99. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/graphviz.py +102 -0
  100. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_gyp.py +156 -0
  101. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_sln.py +181 -0
  102. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_vcproj.py +339 -0
  103. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/test/fixtures/test-charmap.py +31 -0
  104. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/update-gyp.py +46 -0
  105. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/game_stats/app.py +400 -0
  106. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/game_stats/name_fix.py +47 -0
  107. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/app.py +108 -0
  108. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/plot.py +93 -0
  109. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/rink_plot.py +245 -0
  110. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/app.py +145 -0
  111. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/plot.py +77 -0
  112. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/rink_plot.py +245 -0
  113. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/app.py +389 -0
  114. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/plot.py +70 -0
  115. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/rink_plot.py +245 -0
  116. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/app.py +110 -0
  117. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/plot.py +58 -0
  118. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/rink_plot.py +245 -0
  119. wsba_hockey/tools/agg.py +243 -54
  120. wsba_hockey/tools/plotting.py +25 -25
  121. wsba_hockey/tools/scraping.py +154 -263
  122. wsba_hockey/tools/xg_model.py +369 -315
  123. wsba_hockey/workspace.py +22 -117
  124. wsba_hockey/wsba_main.py +499 -167
  125. {wsba_hockey-1.0.3.dist-info → wsba_hockey-1.0.5.dist-info}/METADATA +1 -1
  126. wsba_hockey-1.0.5.dist-info/RECORD +135 -0
  127. {wsba_hockey-1.0.3.dist-info → wsba_hockey-1.0.5.dist-info}/WHEEL +1 -1
  128. wsba_hockey/stats/calculate_viz/shot_impact.py +0 -2
  129. wsba_hockey-1.0.3.dist-info/RECORD +0 -19
  130. {wsba_hockey-1.0.3.dist-info → wsba_hockey-1.0.5.dist-info}/licenses/LICENSE +0 -0
  131. {wsba_hockey-1.0.3.dist-info → wsba_hockey-1.0.5.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,1394 @@
1
+ # Copyright (c) 2012 Google Inc. All rights reserved.
2
+ # Use of this source code is governed by a BSD-style license that can be
3
+ # found in the LICENSE file.
4
+
5
+
6
+ import filecmp
7
+ import gyp.common
8
+ import gyp.xcodeproj_file
9
+ import gyp.xcode_ninja
10
+ import errno
11
+ import os
12
+ import sys
13
+ import posixpath
14
+ import re
15
+ import shutil
16
+ import subprocess
17
+ import tempfile
18
+
19
+
20
+ # Project files generated by this module will use _intermediate_var as a
21
+ # custom Xcode setting whose value is a DerivedSources-like directory that's
22
+ # project-specific and configuration-specific. The normal choice,
23
+ # DERIVED_FILE_DIR, is target-specific, which is thought to be too restrictive
24
+ # as it is likely that multiple targets within a single project file will want
25
+ # to access the same set of generated files. The other option,
26
+ # PROJECT_DERIVED_FILE_DIR, is unsuitable because while it is project-specific,
27
+ # it is not configuration-specific. INTERMEDIATE_DIR is defined as
28
+ # $(PROJECT_DERIVED_FILE_DIR)/$(CONFIGURATION).
29
+ _intermediate_var = "INTERMEDIATE_DIR"
30
+
31
+ # SHARED_INTERMEDIATE_DIR is the same, except that it is shared among all
32
+ # targets that share the same BUILT_PRODUCTS_DIR.
33
+ _shared_intermediate_var = "SHARED_INTERMEDIATE_DIR"
34
+
35
+ _library_search_paths_var = "LIBRARY_SEARCH_PATHS"
36
+
37
+ generator_default_variables = {
38
+ "EXECUTABLE_PREFIX": "",
39
+ "EXECUTABLE_SUFFIX": "",
40
+ "STATIC_LIB_PREFIX": "lib",
41
+ "SHARED_LIB_PREFIX": "lib",
42
+ "STATIC_LIB_SUFFIX": ".a",
43
+ "SHARED_LIB_SUFFIX": ".dylib",
44
+ # INTERMEDIATE_DIR is a place for targets to build up intermediate products.
45
+ # It is specific to each build environment. It is only guaranteed to exist
46
+ # and be constant within the context of a project, corresponding to a single
47
+ # input file. Some build environments may allow their intermediate directory
48
+ # to be shared on a wider scale, but this is not guaranteed.
49
+ "INTERMEDIATE_DIR": "$(%s)" % _intermediate_var,
50
+ "OS": "mac",
51
+ "PRODUCT_DIR": "$(BUILT_PRODUCTS_DIR)",
52
+ "LIB_DIR": "$(BUILT_PRODUCTS_DIR)",
53
+ "RULE_INPUT_ROOT": "$(INPUT_FILE_BASE)",
54
+ "RULE_INPUT_EXT": "$(INPUT_FILE_SUFFIX)",
55
+ "RULE_INPUT_NAME": "$(INPUT_FILE_NAME)",
56
+ "RULE_INPUT_PATH": "$(INPUT_FILE_PATH)",
57
+ "RULE_INPUT_DIRNAME": "$(INPUT_FILE_DIRNAME)",
58
+ "SHARED_INTERMEDIATE_DIR": "$(%s)" % _shared_intermediate_var,
59
+ "CONFIGURATION_NAME": "$(CONFIGURATION)",
60
+ }
61
+
62
+ # The Xcode-specific sections that hold paths.
63
+ generator_additional_path_sections = [
64
+ "mac_bundle_resources",
65
+ "mac_framework_headers",
66
+ "mac_framework_private_headers",
67
+ # 'mac_framework_dirs', input already handles _dirs endings.
68
+ ]
69
+
70
+ # The Xcode-specific keys that exist on targets and aren't moved down to
71
+ # configurations.
72
+ generator_additional_non_configuration_keys = [
73
+ "ios_app_extension",
74
+ "ios_watch_app",
75
+ "ios_watchkit_extension",
76
+ "mac_bundle",
77
+ "mac_bundle_resources",
78
+ "mac_framework_headers",
79
+ "mac_framework_private_headers",
80
+ "mac_xctest_bundle",
81
+ "mac_xcuitest_bundle",
82
+ "xcode_create_dependents_test_runner",
83
+ ]
84
+
85
+ # We want to let any rules apply to files that are resources also.
86
+ generator_extra_sources_for_rules = [
87
+ "mac_bundle_resources",
88
+ "mac_framework_headers",
89
+ "mac_framework_private_headers",
90
+ ]
91
+
92
+ generator_filelist_paths = None
93
+
94
+ # Xcode's standard set of library directories, which don't need to be duplicated
95
+ # in LIBRARY_SEARCH_PATHS. This list is not exhaustive, but that's okay.
96
+ xcode_standard_library_dirs = frozenset(
97
+ ["$(SDKROOT)/usr/lib", "$(SDKROOT)/usr/local/lib"]
98
+ )
99
+
100
+
101
+ def CreateXCConfigurationList(configuration_names):
102
+ xccl = gyp.xcodeproj_file.XCConfigurationList({"buildConfigurations": []})
103
+ if len(configuration_names) == 0:
104
+ configuration_names = ["Default"]
105
+ for configuration_name in configuration_names:
106
+ xcbc = gyp.xcodeproj_file.XCBuildConfiguration({"name": configuration_name})
107
+ xccl.AppendProperty("buildConfigurations", xcbc)
108
+ xccl.SetProperty("defaultConfigurationName", configuration_names[0])
109
+ return xccl
110
+
111
+
112
+ class XcodeProject:
113
+ def __init__(self, gyp_path, path, build_file_dict):
114
+ self.gyp_path = gyp_path
115
+ self.path = path
116
+ self.project = gyp.xcodeproj_file.PBXProject(path=path)
117
+ projectDirPath = gyp.common.RelativePath(
118
+ os.path.dirname(os.path.abspath(self.gyp_path)),
119
+ os.path.dirname(path) or ".",
120
+ )
121
+ self.project.SetProperty("projectDirPath", projectDirPath)
122
+ self.project_file = gyp.xcodeproj_file.XCProjectFile(
123
+ {"rootObject": self.project}
124
+ )
125
+ self.build_file_dict = build_file_dict
126
+
127
+ # TODO(mark): add destructor that cleans up self.path if created_dir is
128
+ # True and things didn't complete successfully. Or do something even
129
+ # better with "try"?
130
+ self.created_dir = False
131
+ try:
132
+ os.makedirs(self.path)
133
+ self.created_dir = True
134
+ except OSError as e:
135
+ if e.errno != errno.EEXIST:
136
+ raise
137
+
138
+ def Finalize1(self, xcode_targets, serialize_all_tests):
139
+ # Collect a list of all of the build configuration names used by the
140
+ # various targets in the file. It is very heavily advised to keep each
141
+ # target in an entire project (even across multiple project files) using
142
+ # the same set of configuration names.
143
+ configurations = []
144
+ for xct in self.project.GetProperty("targets"):
145
+ xccl = xct.GetProperty("buildConfigurationList")
146
+ xcbcs = xccl.GetProperty("buildConfigurations")
147
+ for xcbc in xcbcs:
148
+ name = xcbc.GetProperty("name")
149
+ if name not in configurations:
150
+ configurations.append(name)
151
+
152
+ # Replace the XCConfigurationList attached to the PBXProject object with
153
+ # a new one specifying all of the configuration names used by the various
154
+ # targets.
155
+ try:
156
+ xccl = CreateXCConfigurationList(configurations)
157
+ self.project.SetProperty("buildConfigurationList", xccl)
158
+ except Exception:
159
+ sys.stderr.write("Problem with gyp file %s\n" % self.gyp_path)
160
+ raise
161
+
162
+ # The need for this setting is explained above where _intermediate_var is
163
+ # defined. The comments below about wanting to avoid project-wide build
164
+ # settings apply here too, but this needs to be set on a project-wide basis
165
+ # so that files relative to the _intermediate_var setting can be displayed
166
+ # properly in the Xcode UI.
167
+ #
168
+ # Note that for configuration-relative files such as anything relative to
169
+ # _intermediate_var, for the purposes of UI tree view display, Xcode will
170
+ # only resolve the configuration name once, when the project file is
171
+ # opened. If the active build configuration is changed, the project file
172
+ # must be closed and reopened if it is desired for the tree view to update.
173
+ # This is filed as Apple radar 6588391.
174
+ xccl.SetBuildSetting(
175
+ _intermediate_var, "$(PROJECT_DERIVED_FILE_DIR)/$(CONFIGURATION)"
176
+ )
177
+ xccl.SetBuildSetting(
178
+ _shared_intermediate_var, "$(SYMROOT)/DerivedSources/$(CONFIGURATION)"
179
+ )
180
+
181
+ # Set user-specified project-wide build settings and config files. This
182
+ # is intended to be used very sparingly. Really, almost everything should
183
+ # go into target-specific build settings sections. The project-wide
184
+ # settings are only intended to be used in cases where Xcode attempts to
185
+ # resolve variable references in a project context as opposed to a target
186
+ # context, such as when resolving sourceTree references while building up
187
+ # the tree tree view for UI display.
188
+ # Any values set globally are applied to all configurations, then any
189
+ # per-configuration values are applied.
190
+ for xck, xcv in self.build_file_dict.get("xcode_settings", {}).items():
191
+ xccl.SetBuildSetting(xck, xcv)
192
+ if "xcode_config_file" in self.build_file_dict:
193
+ config_ref = self.project.AddOrGetFileInRootGroup(
194
+ self.build_file_dict["xcode_config_file"]
195
+ )
196
+ xccl.SetBaseConfiguration(config_ref)
197
+ build_file_configurations = self.build_file_dict.get("configurations", {})
198
+ if build_file_configurations:
199
+ for config_name in configurations:
200
+ build_file_configuration_named = build_file_configurations.get(
201
+ config_name, {}
202
+ )
203
+ if build_file_configuration_named:
204
+ xcc = xccl.ConfigurationNamed(config_name)
205
+ for xck, xcv in build_file_configuration_named.get(
206
+ "xcode_settings", {}
207
+ ).items():
208
+ xcc.SetBuildSetting(xck, xcv)
209
+ if "xcode_config_file" in build_file_configuration_named:
210
+ config_ref = self.project.AddOrGetFileInRootGroup(
211
+ build_file_configurations[config_name]["xcode_config_file"]
212
+ )
213
+ xcc.SetBaseConfiguration(config_ref)
214
+
215
+ # Sort the targets based on how they appeared in the input.
216
+ # TODO(mark): Like a lot of other things here, this assumes internal
217
+ # knowledge of PBXProject - in this case, of its "targets" property.
218
+
219
+ # ordinary_targets are ordinary targets that are already in the project
220
+ # file. run_test_targets are the targets that run unittests and should be
221
+ # used for the Run All Tests target. support_targets are the action/rule
222
+ # targets used by GYP file targets, just kept for the assert check.
223
+ ordinary_targets = []
224
+ run_test_targets = []
225
+ support_targets = []
226
+
227
+ # targets is full list of targets in the project.
228
+ targets = []
229
+
230
+ # does the it define it's own "all"?
231
+ has_custom_all = False
232
+
233
+ # targets_for_all is the list of ordinary_targets that should be listed
234
+ # in this project's "All" target. It includes each non_runtest_target
235
+ # that does not have suppress_wildcard set.
236
+ targets_for_all = []
237
+
238
+ for target in self.build_file_dict["targets"]:
239
+ target_name = target["target_name"]
240
+ toolset = target["toolset"]
241
+ qualified_target = gyp.common.QualifiedTarget(
242
+ self.gyp_path, target_name, toolset
243
+ )
244
+ xcode_target = xcode_targets[qualified_target]
245
+ # Make sure that the target being added to the sorted list is already in
246
+ # the unsorted list.
247
+ assert xcode_target in self.project._properties["targets"]
248
+ targets.append(xcode_target)
249
+ ordinary_targets.append(xcode_target)
250
+ if xcode_target.support_target:
251
+ support_targets.append(xcode_target.support_target)
252
+ targets.append(xcode_target.support_target)
253
+
254
+ if not int(target.get("suppress_wildcard", False)):
255
+ targets_for_all.append(xcode_target)
256
+
257
+ if target_name.lower() == "all":
258
+ has_custom_all = True
259
+
260
+ # If this target has a 'run_as' attribute, add its target to the
261
+ # targets, and add it to the test targets.
262
+ if target.get("run_as"):
263
+ # Make a target to run something. It should have one
264
+ # dependency, the parent xcode target.
265
+ xccl = CreateXCConfigurationList(configurations)
266
+ run_target = gyp.xcodeproj_file.PBXAggregateTarget(
267
+ {
268
+ "name": "Run " + target_name,
269
+ "productName": xcode_target.GetProperty("productName"),
270
+ "buildConfigurationList": xccl,
271
+ },
272
+ parent=self.project,
273
+ )
274
+ run_target.AddDependency(xcode_target)
275
+
276
+ command = target["run_as"]
277
+ script = ""
278
+ if command.get("working_directory"):
279
+ script = (
280
+ script
281
+ + 'cd "%s"\n'
282
+ % gyp.xcodeproj_file.ConvertVariablesToShellSyntax(
283
+ command.get("working_directory")
284
+ )
285
+ )
286
+
287
+ if command.get("environment"):
288
+ script = (
289
+ script
290
+ + "\n".join(
291
+ [
292
+ 'export %s="%s"'
293
+ % (
294
+ key,
295
+ gyp.xcodeproj_file.ConvertVariablesToShellSyntax(
296
+ val
297
+ ),
298
+ )
299
+ for (key, val) in command.get("environment").items()
300
+ ]
301
+ )
302
+ + "\n"
303
+ )
304
+
305
+ # Some test end up using sockets, files on disk, etc. and can get
306
+ # confused if more then one test runs at a time. The generator
307
+ # flag 'xcode_serialize_all_test_runs' controls the forcing of all
308
+ # tests serially. It defaults to True. To get serial runs this
309
+ # little bit of python does the same as the linux flock utility to
310
+ # make sure only one runs at a time.
311
+ command_prefix = ""
312
+ if serialize_all_tests:
313
+ command_prefix = """python -c "import fcntl, subprocess, sys
314
+ file = open('$TMPDIR/GYP_serialize_test_runs', 'a')
315
+ fcntl.flock(file.fileno(), fcntl.LOCK_EX)
316
+ sys.exit(subprocess.call(sys.argv[1:]))" """
317
+
318
+ # If we were unable to exec for some reason, we want to exit
319
+ # with an error, and fixup variable references to be shell
320
+ # syntax instead of xcode syntax.
321
+ script = (
322
+ script
323
+ + "exec "
324
+ + command_prefix
325
+ + "%s\nexit 1\n"
326
+ % gyp.xcodeproj_file.ConvertVariablesToShellSyntax(
327
+ gyp.common.EncodePOSIXShellList(command.get("action"))
328
+ )
329
+ )
330
+
331
+ ssbp = gyp.xcodeproj_file.PBXShellScriptBuildPhase(
332
+ {"shellScript": script, "showEnvVarsInLog": 0}
333
+ )
334
+ run_target.AppendProperty("buildPhases", ssbp)
335
+
336
+ # Add the run target to the project file.
337
+ targets.append(run_target)
338
+ run_test_targets.append(run_target)
339
+ xcode_target.test_runner = run_target
340
+
341
+ # Make sure that the list of targets being replaced is the same length as
342
+ # the one replacing it, but allow for the added test runner targets.
343
+ assert len(self.project._properties["targets"]) == len(ordinary_targets) + len(
344
+ support_targets
345
+ )
346
+
347
+ self.project._properties["targets"] = targets
348
+
349
+ # Get rid of unnecessary levels of depth in groups like the Source group.
350
+ self.project.RootGroupsTakeOverOnlyChildren(True)
351
+
352
+ # Sort the groups nicely. Do this after sorting the targets, because the
353
+ # Products group is sorted based on the order of the targets.
354
+ self.project.SortGroups()
355
+
356
+ # Create an "All" target if there's more than one target in this project
357
+ # file and the project didn't define its own "All" target. Put a generated
358
+ # "All" target first so that people opening up the project for the first
359
+ # time will build everything by default.
360
+ if len(targets_for_all) > 1 and not has_custom_all:
361
+ xccl = CreateXCConfigurationList(configurations)
362
+ all_target = gyp.xcodeproj_file.PBXAggregateTarget(
363
+ {"buildConfigurationList": xccl, "name": "All"}, parent=self.project
364
+ )
365
+
366
+ for target in targets_for_all:
367
+ all_target.AddDependency(target)
368
+
369
+ # TODO(mark): This is evil because it relies on internal knowledge of
370
+ # PBXProject._properties. It's important to get the "All" target first,
371
+ # though.
372
+ self.project._properties["targets"].insert(0, all_target)
373
+
374
+ # The same, but for run_test_targets.
375
+ if len(run_test_targets) > 1:
376
+ xccl = CreateXCConfigurationList(configurations)
377
+ run_all_tests_target = gyp.xcodeproj_file.PBXAggregateTarget(
378
+ {"buildConfigurationList": xccl, "name": "Run All Tests"},
379
+ parent=self.project,
380
+ )
381
+ for run_test_target in run_test_targets:
382
+ run_all_tests_target.AddDependency(run_test_target)
383
+
384
+ # Insert after the "All" target, which must exist if there is more than
385
+ # one run_test_target.
386
+ self.project._properties["targets"].insert(1, run_all_tests_target)
387
+
388
+ def Finalize2(self, xcode_targets, xcode_target_to_target_dict):
389
+ # Finalize2 needs to happen in a separate step because the process of
390
+ # updating references to other projects depends on the ordering of targets
391
+ # within remote project files. Finalize1 is responsible for sorting duty,
392
+ # and once all project files are sorted, Finalize2 can come in and update
393
+ # these references.
394
+
395
+ # To support making a "test runner" target that will run all the tests
396
+ # that are direct dependents of any given target, we look for
397
+ # xcode_create_dependents_test_runner being set on an Aggregate target,
398
+ # and generate a second target that will run the tests runners found under
399
+ # the marked target.
400
+ for bf_tgt in self.build_file_dict["targets"]:
401
+ if int(bf_tgt.get("xcode_create_dependents_test_runner", 0)):
402
+ tgt_name = bf_tgt["target_name"]
403
+ toolset = bf_tgt["toolset"]
404
+ qualified_target = gyp.common.QualifiedTarget(
405
+ self.gyp_path, tgt_name, toolset
406
+ )
407
+ xcode_target = xcode_targets[qualified_target]
408
+ if isinstance(xcode_target, gyp.xcodeproj_file.PBXAggregateTarget):
409
+ # Collect all the run test targets.
410
+ all_run_tests = []
411
+ pbxtds = xcode_target.GetProperty("dependencies")
412
+ for pbxtd in pbxtds:
413
+ pbxcip = pbxtd.GetProperty("targetProxy")
414
+ dependency_xct = pbxcip.GetProperty("remoteGlobalIDString")
415
+ if hasattr(dependency_xct, "test_runner"):
416
+ all_run_tests.append(dependency_xct.test_runner)
417
+
418
+ # Directly depend on all the runners as they depend on the target
419
+ # that builds them.
420
+ if len(all_run_tests) > 0:
421
+ run_all_target = gyp.xcodeproj_file.PBXAggregateTarget(
422
+ {
423
+ "name": "Run %s Tests" % tgt_name,
424
+ "productName": tgt_name,
425
+ },
426
+ parent=self.project,
427
+ )
428
+ for run_test_target in all_run_tests:
429
+ run_all_target.AddDependency(run_test_target)
430
+
431
+ # Insert the test runner after the related target.
432
+ idx = self.project._properties["targets"].index(xcode_target)
433
+ self.project._properties["targets"].insert(
434
+ idx + 1, run_all_target
435
+ )
436
+
437
+ # Update all references to other projects, to make sure that the lists of
438
+ # remote products are complete. Otherwise, Xcode will fill them in when
439
+ # it opens the project file, which will result in unnecessary diffs.
440
+ # TODO(mark): This is evil because it relies on internal knowledge of
441
+ # PBXProject._other_pbxprojects.
442
+ for other_pbxproject in self.project._other_pbxprojects.keys():
443
+ self.project.AddOrGetProjectReference(other_pbxproject)
444
+
445
+ self.project.SortRemoteProductReferences()
446
+
447
+ # Give everything an ID.
448
+ self.project_file.ComputeIDs()
449
+
450
+ # Make sure that no two objects in the project file have the same ID. If
451
+ # multiple objects wind up with the same ID, upon loading the file, Xcode
452
+ # will only recognize one object (the last one in the file?) and the
453
+ # results are unpredictable.
454
+ self.project_file.EnsureNoIDCollisions()
455
+
456
+ def Write(self):
457
+ # Write the project file to a temporary location first. Xcode watches for
458
+ # changes to the project file and presents a UI sheet offering to reload
459
+ # the project when it does change. However, in some cases, especially when
460
+ # multiple projects are open or when Xcode is busy, things don't work so
461
+ # seamlessly. Sometimes, Xcode is able to detect that a project file has
462
+ # changed but can't unload it because something else is referencing it.
463
+ # To mitigate this problem, and to avoid even having Xcode present the UI
464
+ # sheet when an open project is rewritten for inconsequential changes, the
465
+ # project file is written to a temporary file in the xcodeproj directory
466
+ # first. The new temporary file is then compared to the existing project
467
+ # file, if any. If they differ, the new file replaces the old; otherwise,
468
+ # the new project file is simply deleted. Xcode properly detects a file
469
+ # being renamed over an open project file as a change and so it remains
470
+ # able to present the "project file changed" sheet under this system.
471
+ # Writing to a temporary file first also avoids the possible problem of
472
+ # Xcode rereading an incomplete project file.
473
+ (output_fd, new_pbxproj_path) = tempfile.mkstemp(
474
+ suffix=".tmp", prefix="project.pbxproj.gyp.", dir=self.path
475
+ )
476
+
477
+ try:
478
+ output_file = os.fdopen(output_fd, "w")
479
+
480
+ self.project_file.Print(output_file)
481
+ output_file.close()
482
+
483
+ pbxproj_path = os.path.join(self.path, "project.pbxproj")
484
+
485
+ same = False
486
+ try:
487
+ same = filecmp.cmp(pbxproj_path, new_pbxproj_path, False)
488
+ except OSError as e:
489
+ if e.errno != errno.ENOENT:
490
+ raise
491
+
492
+ if same:
493
+ # The new file is identical to the old one, just get rid of the new
494
+ # one.
495
+ os.unlink(new_pbxproj_path)
496
+ else:
497
+ # The new file is different from the old one, or there is no old one.
498
+ # Rename the new file to the permanent name.
499
+ #
500
+ # tempfile.mkstemp uses an overly restrictive mode, resulting in a
501
+ # file that can only be read by the owner, regardless of the umask.
502
+ # There's no reason to not respect the umask here, which means that
503
+ # an extra hoop is required to fetch it and reset the new file's mode.
504
+ #
505
+ # No way to get the umask without setting a new one? Set a safe one
506
+ # and then set it back to the old value.
507
+ umask = os.umask(0o77)
508
+ os.umask(umask)
509
+
510
+ os.chmod(new_pbxproj_path, 0o666 & ~umask)
511
+ os.rename(new_pbxproj_path, pbxproj_path)
512
+
513
+ except Exception:
514
+ # Don't leave turds behind. In fact, if this code was responsible for
515
+ # creating the xcodeproj directory, get rid of that too.
516
+ os.unlink(new_pbxproj_path)
517
+ if self.created_dir:
518
+ shutil.rmtree(self.path, True)
519
+ raise
520
+
521
+
522
+ def AddSourceToTarget(source, type, pbxp, xct):
523
+ # TODO(mark): Perhaps source_extensions and library_extensions can be made a
524
+ # little bit fancier.
525
+ source_extensions = ["c", "cc", "cpp", "cxx", "m", "mm", "s", "swift"]
526
+
527
+ # .o is conceptually more of a "source" than a "library," but Xcode thinks
528
+ # of "sources" as things to compile and "libraries" (or "frameworks") as
529
+ # things to link with. Adding an object file to an Xcode target's frameworks
530
+ # phase works properly.
531
+ library_extensions = ["a", "dylib", "framework", "o"]
532
+
533
+ basename = posixpath.basename(source)
534
+ (root, ext) = posixpath.splitext(basename)
535
+ if ext:
536
+ ext = ext[1:].lower()
537
+
538
+ if ext in source_extensions and type != "none":
539
+ xct.SourcesPhase().AddFile(source)
540
+ elif ext in library_extensions and type != "none":
541
+ xct.FrameworksPhase().AddFile(source)
542
+ else:
543
+ # Files that aren't added to a sources or frameworks build phase can still
544
+ # go into the project file, just not as part of a build phase.
545
+ pbxp.AddOrGetFileInRootGroup(source)
546
+
547
+
548
+ def AddResourceToTarget(resource, pbxp, xct):
549
+ # TODO(mark): Combine with AddSourceToTarget above? Or just inline this call
550
+ # where it's used.
551
+ xct.ResourcesPhase().AddFile(resource)
552
+
553
+
554
+ def AddHeaderToTarget(header, pbxp, xct, is_public):
555
+ # TODO(mark): Combine with AddSourceToTarget above? Or just inline this call
556
+ # where it's used.
557
+ settings = "{ATTRIBUTES = (%s, ); }" % ("Private", "Public")[is_public]
558
+ xct.HeadersPhase().AddFile(header, settings)
559
+
560
+
561
+ _xcode_variable_re = re.compile(r"(\$\((.*?)\))")
562
+
563
+
564
+ def ExpandXcodeVariables(string, expansions):
565
+ """Expands Xcode-style $(VARIABLES) in string per the expansions dict.
566
+
567
+ In some rare cases, it is appropriate to expand Xcode variables when a
568
+ project file is generated. For any substring $(VAR) in string, if VAR is a
569
+ key in the expansions dict, $(VAR) will be replaced with expansions[VAR].
570
+ Any $(VAR) substring in string for which VAR is not a key in the expansions
571
+ dict will remain in the returned string.
572
+ """
573
+
574
+ matches = _xcode_variable_re.findall(string)
575
+ if matches is None:
576
+ return string
577
+
578
+ matches.reverse()
579
+ for match in matches:
580
+ (to_replace, variable) = match
581
+ if variable not in expansions:
582
+ continue
583
+
584
+ replacement = expansions[variable]
585
+ string = re.sub(re.escape(to_replace), replacement, string)
586
+
587
+ return string
588
+
589
+
590
+ _xcode_define_re = re.compile(r"([\\\"\' ])")
591
+
592
+
593
+ def EscapeXcodeDefine(s):
594
+ """We must escape the defines that we give to XCode so that it knows not to
595
+ split on spaces and to respect backslash and quote literals. However, we
596
+ must not quote the define, or Xcode will incorrectly interpret variables
597
+ especially $(inherited)."""
598
+ return re.sub(_xcode_define_re, r"\\\1", s)
599
+
600
+
601
+ def PerformBuild(data, configurations, params):
602
+ options = params["options"]
603
+
604
+ for build_file, build_file_dict in data.items():
605
+ (build_file_root, build_file_ext) = os.path.splitext(build_file)
606
+ if build_file_ext != ".gyp":
607
+ continue
608
+ xcodeproj_path = build_file_root + options.suffix + ".xcodeproj"
609
+ if options.generator_output:
610
+ xcodeproj_path = os.path.join(options.generator_output, xcodeproj_path)
611
+
612
+ for config in configurations:
613
+ arguments = ["xcodebuild", "-project", xcodeproj_path]
614
+ arguments += ["-configuration", config]
615
+ print(f"Building [{config}]: {arguments}")
616
+ subprocess.check_call(arguments)
617
+
618
+
619
+ def CalculateGeneratorInputInfo(params):
620
+ toplevel = params["options"].toplevel_dir
621
+ if params.get("flavor") == "ninja":
622
+ generator_dir = os.path.relpath(params["options"].generator_output or ".")
623
+ output_dir = params.get("generator_flags", {}).get("output_dir", "out")
624
+ output_dir = os.path.normpath(os.path.join(generator_dir, output_dir))
625
+ qualified_out_dir = os.path.normpath(
626
+ os.path.join(toplevel, output_dir, "gypfiles-xcode-ninja")
627
+ )
628
+ else:
629
+ output_dir = os.path.normpath(os.path.join(toplevel, "xcodebuild"))
630
+ qualified_out_dir = os.path.normpath(
631
+ os.path.join(toplevel, output_dir, "gypfiles")
632
+ )
633
+
634
+ global generator_filelist_paths
635
+ generator_filelist_paths = {
636
+ "toplevel": toplevel,
637
+ "qualified_out_dir": qualified_out_dir,
638
+ }
639
+
640
+
641
+ def GenerateOutput(target_list, target_dicts, data, params):
642
+ # Optionally configure each spec to use ninja as the external builder.
643
+ ninja_wrapper = params.get("flavor") == "ninja"
644
+ if ninja_wrapper:
645
+ (target_list, target_dicts, data) = gyp.xcode_ninja.CreateWrapper(
646
+ target_list, target_dicts, data, params
647
+ )
648
+
649
+ options = params["options"]
650
+ generator_flags = params.get("generator_flags", {})
651
+ parallel_builds = generator_flags.get("xcode_parallel_builds", True)
652
+ serialize_all_tests = generator_flags.get("xcode_serialize_all_test_runs", True)
653
+ upgrade_check_project_version = generator_flags.get(
654
+ "xcode_upgrade_check_project_version", None
655
+ )
656
+
657
+ # Format upgrade_check_project_version with leading zeros as needed.
658
+ if upgrade_check_project_version:
659
+ upgrade_check_project_version = str(upgrade_check_project_version)
660
+ while len(upgrade_check_project_version) < 4:
661
+ upgrade_check_project_version = "0" + upgrade_check_project_version
662
+
663
+ skip_excluded_files = not generator_flags.get("xcode_list_excluded_files", True)
664
+ xcode_projects = {}
665
+ for build_file, build_file_dict in data.items():
666
+ (build_file_root, build_file_ext) = os.path.splitext(build_file)
667
+ if build_file_ext != ".gyp":
668
+ continue
669
+ xcodeproj_path = build_file_root + options.suffix + ".xcodeproj"
670
+ if options.generator_output:
671
+ xcodeproj_path = os.path.join(options.generator_output, xcodeproj_path)
672
+ xcp = XcodeProject(build_file, xcodeproj_path, build_file_dict)
673
+ xcode_projects[build_file] = xcp
674
+ pbxp = xcp.project
675
+
676
+ # Set project-level attributes from multiple options
677
+ project_attributes = {}
678
+ if parallel_builds:
679
+ project_attributes["BuildIndependentTargetsInParallel"] = "YES"
680
+ if upgrade_check_project_version:
681
+ project_attributes["LastUpgradeCheck"] = upgrade_check_project_version
682
+ project_attributes[
683
+ "LastTestingUpgradeCheck"
684
+ ] = upgrade_check_project_version
685
+ project_attributes["LastSwiftUpdateCheck"] = upgrade_check_project_version
686
+ pbxp.SetProperty("attributes", project_attributes)
687
+
688
+ # Add gyp/gypi files to project
689
+ if not generator_flags.get("standalone"):
690
+ main_group = pbxp.GetProperty("mainGroup")
691
+ build_group = gyp.xcodeproj_file.PBXGroup({"name": "Build"})
692
+ main_group.AppendChild(build_group)
693
+ for included_file in build_file_dict["included_files"]:
694
+ build_group.AddOrGetFileByPath(included_file, False)
695
+
696
+ xcode_targets = {}
697
+ xcode_target_to_target_dict = {}
698
+ for qualified_target in target_list:
699
+ [build_file, target_name, toolset] = gyp.common.ParseQualifiedTarget(
700
+ qualified_target
701
+ )
702
+
703
+ spec = target_dicts[qualified_target]
704
+ if spec["toolset"] != "target":
705
+ raise Exception(
706
+ "Multiple toolsets not supported in xcode build (target %s)"
707
+ % qualified_target
708
+ )
709
+ configuration_names = [spec["default_configuration"]]
710
+ for configuration_name in sorted(spec["configurations"].keys()):
711
+ if configuration_name not in configuration_names:
712
+ configuration_names.append(configuration_name)
713
+ xcp = xcode_projects[build_file]
714
+ pbxp = xcp.project
715
+
716
+ # Set up the configurations for the target according to the list of names
717
+ # supplied.
718
+ xccl = CreateXCConfigurationList(configuration_names)
719
+
720
+ # Create an XCTarget subclass object for the target. The type with
721
+ # "+bundle" appended will be used if the target has "mac_bundle" set.
722
+ # loadable_modules not in a mac_bundle are mapped to
723
+ # com.googlecode.gyp.xcode.bundle, a pseudo-type that xcode.py interprets
724
+ # to create a single-file mh_bundle.
725
+ _types = {
726
+ "executable": "com.apple.product-type.tool",
727
+ "loadable_module": "com.googlecode.gyp.xcode.bundle",
728
+ "shared_library": "com.apple.product-type.library.dynamic",
729
+ "static_library": "com.apple.product-type.library.static",
730
+ "mac_kernel_extension": "com.apple.product-type.kernel-extension",
731
+ "executable+bundle": "com.apple.product-type.application",
732
+ "loadable_module+bundle": "com.apple.product-type.bundle",
733
+ "loadable_module+xctest": "com.apple.product-type.bundle.unit-test",
734
+ "loadable_module+xcuitest": "com.apple.product-type.bundle.ui-testing",
735
+ "shared_library+bundle": "com.apple.product-type.framework",
736
+ "executable+extension+bundle": "com.apple.product-type.app-extension",
737
+ "executable+watch+extension+bundle":
738
+ "com.apple.product-type.watchkit-extension",
739
+ "executable+watch+bundle": "com.apple.product-type.application.watchapp",
740
+ "mac_kernel_extension+bundle": "com.apple.product-type.kernel-extension",
741
+ }
742
+
743
+ target_properties = {
744
+ "buildConfigurationList": xccl,
745
+ "name": target_name,
746
+ }
747
+
748
+ type = spec["type"]
749
+ is_xctest = int(spec.get("mac_xctest_bundle", 0))
750
+ is_xcuitest = int(spec.get("mac_xcuitest_bundle", 0))
751
+ is_bundle = int(spec.get("mac_bundle", 0)) or is_xctest
752
+ is_app_extension = int(spec.get("ios_app_extension", 0))
753
+ is_watchkit_extension = int(spec.get("ios_watchkit_extension", 0))
754
+ is_watch_app = int(spec.get("ios_watch_app", 0))
755
+ if type != "none":
756
+ type_bundle_key = type
757
+ if is_xcuitest:
758
+ type_bundle_key += "+xcuitest"
759
+ assert type == "loadable_module", (
760
+ "mac_xcuitest_bundle targets must have type loadable_module "
761
+ "(target %s)" % target_name
762
+ )
763
+ elif is_xctest:
764
+ type_bundle_key += "+xctest"
765
+ assert type == "loadable_module", (
766
+ "mac_xctest_bundle targets must have type loadable_module "
767
+ "(target %s)" % target_name
768
+ )
769
+ elif is_app_extension:
770
+ assert is_bundle, (
771
+ "ios_app_extension flag requires mac_bundle "
772
+ "(target %s)" % target_name
773
+ )
774
+ type_bundle_key += "+extension+bundle"
775
+ elif is_watchkit_extension:
776
+ assert is_bundle, (
777
+ "ios_watchkit_extension flag requires mac_bundle "
778
+ "(target %s)" % target_name
779
+ )
780
+ type_bundle_key += "+watch+extension+bundle"
781
+ elif is_watch_app:
782
+ assert is_bundle, (
783
+ "ios_watch_app flag requires mac_bundle "
784
+ "(target %s)" % target_name
785
+ )
786
+ type_bundle_key += "+watch+bundle"
787
+ elif is_bundle:
788
+ type_bundle_key += "+bundle"
789
+
790
+ xctarget_type = gyp.xcodeproj_file.PBXNativeTarget
791
+ try:
792
+ target_properties["productType"] = _types[type_bundle_key]
793
+ except KeyError as e:
794
+ gyp.common.ExceptionAppend(
795
+ e,
796
+ "-- unknown product type while " "writing target %s" % target_name,
797
+ )
798
+ raise
799
+ else:
800
+ xctarget_type = gyp.xcodeproj_file.PBXAggregateTarget
801
+ assert not is_bundle, (
802
+ 'mac_bundle targets cannot have type none (target "%s")' % target_name
803
+ )
804
+ assert not is_xcuitest, (
805
+ 'mac_xcuitest_bundle targets cannot have type none (target "%s")'
806
+ % target_name
807
+ )
808
+ assert not is_xctest, (
809
+ 'mac_xctest_bundle targets cannot have type none (target "%s")'
810
+ % target_name
811
+ )
812
+
813
+ target_product_name = spec.get("product_name")
814
+ if target_product_name is not None:
815
+ target_properties["productName"] = target_product_name
816
+
817
+ xct = xctarget_type(
818
+ target_properties,
819
+ parent=pbxp,
820
+ force_outdir=spec.get("product_dir"),
821
+ force_prefix=spec.get("product_prefix"),
822
+ force_extension=spec.get("product_extension"),
823
+ )
824
+ pbxp.AppendProperty("targets", xct)
825
+ xcode_targets[qualified_target] = xct
826
+ xcode_target_to_target_dict[xct] = spec
827
+
828
+ spec_actions = spec.get("actions", [])
829
+ spec_rules = spec.get("rules", [])
830
+
831
+ # Xcode has some "issues" with checking dependencies for the "Compile
832
+ # sources" step with any source files/headers generated by actions/rules.
833
+ # To work around this, if a target is building anything directly (not
834
+ # type "none"), then a second target is used to run the GYP actions/rules
835
+ # and is made a dependency of this target. This way the work is done
836
+ # before the dependency checks for what should be recompiled.
837
+ support_xct = None
838
+ # The Xcode "issues" don't affect xcode-ninja builds, since the dependency
839
+ # logic all happens in ninja. Don't bother creating the extra targets in
840
+ # that case.
841
+ if type != "none" and (spec_actions or spec_rules) and not ninja_wrapper:
842
+ support_xccl = CreateXCConfigurationList(configuration_names)
843
+ support_target_suffix = generator_flags.get(
844
+ "support_target_suffix", " Support"
845
+ )
846
+ support_target_properties = {
847
+ "buildConfigurationList": support_xccl,
848
+ "name": target_name + support_target_suffix,
849
+ }
850
+ if target_product_name:
851
+ support_target_properties["productName"] = (
852
+ target_product_name + " Support"
853
+ )
854
+ support_xct = gyp.xcodeproj_file.PBXAggregateTarget(
855
+ support_target_properties, parent=pbxp
856
+ )
857
+ pbxp.AppendProperty("targets", support_xct)
858
+ xct.AddDependency(support_xct)
859
+ # Hang the support target off the main target so it can be tested/found
860
+ # by the generator during Finalize.
861
+ xct.support_target = support_xct
862
+
863
+ prebuild_index = 0
864
+
865
+ # Add custom shell script phases for "actions" sections.
866
+ for action in spec_actions:
867
+ # There's no need to write anything into the script to ensure that the
868
+ # output directories already exist, because Xcode will look at the
869
+ # declared outputs and automatically ensure that they exist for us.
870
+
871
+ # Do we have a message to print when this action runs?
872
+ message = action.get("message")
873
+ if message:
874
+ message = "echo note: " + gyp.common.EncodePOSIXShellArgument(message)
875
+ else:
876
+ message = ""
877
+
878
+ # Turn the list into a string that can be passed to a shell.
879
+ action_string = gyp.common.EncodePOSIXShellList(action["action"])
880
+
881
+ # Convert Xcode-type variable references to sh-compatible environment
882
+ # variable references.
883
+ message_sh = gyp.xcodeproj_file.ConvertVariablesToShellSyntax(message)
884
+ action_string_sh = gyp.xcodeproj_file.ConvertVariablesToShellSyntax(
885
+ action_string
886
+ )
887
+
888
+ script = ""
889
+ # Include the optional message
890
+ if message_sh:
891
+ script += message_sh + "\n"
892
+ # Be sure the script runs in exec, and that if exec fails, the script
893
+ # exits signalling an error.
894
+ script += "exec " + action_string_sh + "\nexit 1\n"
895
+ ssbp = gyp.xcodeproj_file.PBXShellScriptBuildPhase(
896
+ {
897
+ "inputPaths": action["inputs"],
898
+ "name": 'Action "' + action["action_name"] + '"',
899
+ "outputPaths": action["outputs"],
900
+ "shellScript": script,
901
+ "showEnvVarsInLog": 0,
902
+ }
903
+ )
904
+
905
+ if support_xct:
906
+ support_xct.AppendProperty("buildPhases", ssbp)
907
+ else:
908
+ # TODO(mark): this assumes too much knowledge of the internals of
909
+ # xcodeproj_file; some of these smarts should move into xcodeproj_file
910
+ # itself.
911
+ xct._properties["buildPhases"].insert(prebuild_index, ssbp)
912
+ prebuild_index = prebuild_index + 1
913
+
914
+ # TODO(mark): Should verify that at most one of these is specified.
915
+ if int(action.get("process_outputs_as_sources", False)):
916
+ for output in action["outputs"]:
917
+ AddSourceToTarget(output, type, pbxp, xct)
918
+
919
+ if int(action.get("process_outputs_as_mac_bundle_resources", False)):
920
+ for output in action["outputs"]:
921
+ AddResourceToTarget(output, pbxp, xct)
922
+
923
+ # tgt_mac_bundle_resources holds the list of bundle resources so
924
+ # the rule processing can check against it.
925
+ if is_bundle:
926
+ tgt_mac_bundle_resources = spec.get("mac_bundle_resources", [])
927
+ else:
928
+ tgt_mac_bundle_resources = []
929
+
930
+ # Add custom shell script phases driving "make" for "rules" sections.
931
+ #
932
+ # Xcode's built-in rule support is almost powerful enough to use directly,
933
+ # but there are a few significant deficiencies that render them unusable.
934
+ # There are workarounds for some of its inadequacies, but in aggregate,
935
+ # the workarounds added complexity to the generator, and some workarounds
936
+ # actually require input files to be crafted more carefully than I'd like.
937
+ # Consequently, until Xcode rules are made more capable, "rules" input
938
+ # sections will be handled in Xcode output by shell script build phases
939
+ # performed prior to the compilation phase.
940
+ #
941
+ # The following problems with Xcode rules were found. The numbers are
942
+ # Apple radar IDs. I hope that these shortcomings are addressed, I really
943
+ # liked having the rules handled directly in Xcode during the period that
944
+ # I was prototyping this.
945
+ #
946
+ # 6588600 Xcode compiles custom script rule outputs too soon, compilation
947
+ # fails. This occurs when rule outputs from distinct inputs are
948
+ # interdependent. The only workaround is to put rules and their
949
+ # inputs in a separate target from the one that compiles the rule
950
+ # outputs. This requires input file cooperation and it means that
951
+ # process_outputs_as_sources is unusable.
952
+ # 6584932 Need to declare that custom rule outputs should be excluded from
953
+ # compilation. A possible workaround is to lie to Xcode about a
954
+ # rule's output, giving it a dummy file it doesn't know how to
955
+ # compile. The rule action script would need to touch the dummy.
956
+ # 6584839 I need a way to declare additional inputs to a custom rule.
957
+ # A possible workaround is a shell script phase prior to
958
+ # compilation that touches a rule's primary input files if any
959
+ # would-be additional inputs are newer than the output. Modifying
960
+ # the source tree - even just modification times - feels dirty.
961
+ # 6564240 Xcode "custom script" build rules always dump all environment
962
+ # variables. This is a low-prioroty problem and is not a
963
+ # show-stopper.
964
+ rules_by_ext = {}
965
+ for rule in spec_rules:
966
+ rules_by_ext[rule["extension"]] = rule
967
+
968
+ # First, some definitions:
969
+ #
970
+ # A "rule source" is a file that was listed in a target's "sources"
971
+ # list and will have a rule applied to it on the basis of matching the
972
+ # rule's "extensions" attribute. Rule sources are direct inputs to
973
+ # rules.
974
+ #
975
+ # Rule definitions may specify additional inputs in their "inputs"
976
+ # attribute. These additional inputs are used for dependency tracking
977
+ # purposes.
978
+ #
979
+ # A "concrete output" is a rule output with input-dependent variables
980
+ # resolved. For example, given a rule with:
981
+ # 'extension': 'ext', 'outputs': ['$(INPUT_FILE_BASE).cc'],
982
+ # if the target's "sources" list contained "one.ext" and "two.ext",
983
+ # the "concrete output" for rule input "two.ext" would be "two.cc". If
984
+ # a rule specifies multiple outputs, each input file that the rule is
985
+ # applied to will have the same number of concrete outputs.
986
+ #
987
+ # If any concrete outputs are outdated or missing relative to their
988
+ # corresponding rule_source or to any specified additional input, the
989
+ # rule action must be performed to generate the concrete outputs.
990
+
991
+ # concrete_outputs_by_rule_source will have an item at the same index
992
+ # as the rule['rule_sources'] that it corresponds to. Each item is a
993
+ # list of all of the concrete outputs for the rule_source.
994
+ concrete_outputs_by_rule_source = []
995
+
996
+ # concrete_outputs_all is a flat list of all concrete outputs that this
997
+ # rule is able to produce, given the known set of input files
998
+ # (rule_sources) that apply to it.
999
+ concrete_outputs_all = []
1000
+
1001
+ # messages & actions are keyed by the same indices as rule['rule_sources']
1002
+ # and concrete_outputs_by_rule_source. They contain the message and
1003
+ # action to perform after resolving input-dependent variables. The
1004
+ # message is optional, in which case None is stored for each rule source.
1005
+ messages = []
1006
+ actions = []
1007
+
1008
+ for rule_source in rule.get("rule_sources", []):
1009
+ rule_source_dirname, rule_source_basename = posixpath.split(rule_source)
1010
+ (rule_source_root, rule_source_ext) = posixpath.splitext(
1011
+ rule_source_basename
1012
+ )
1013
+
1014
+ # These are the same variable names that Xcode uses for its own native
1015
+ # rule support. Because Xcode's rule engine is not being used, they
1016
+ # need to be expanded as they are written to the makefile.
1017
+ rule_input_dict = {
1018
+ "INPUT_FILE_BASE": rule_source_root,
1019
+ "INPUT_FILE_SUFFIX": rule_source_ext,
1020
+ "INPUT_FILE_NAME": rule_source_basename,
1021
+ "INPUT_FILE_PATH": rule_source,
1022
+ "INPUT_FILE_DIRNAME": rule_source_dirname,
1023
+ }
1024
+
1025
+ concrete_outputs_for_this_rule_source = []
1026
+ for output in rule.get("outputs", []):
1027
+ # Fortunately, Xcode and make both use $(VAR) format for their
1028
+ # variables, so the expansion is the only transformation necessary.
1029
+ # Any remaining $(VAR)-type variables in the string can be given
1030
+ # directly to make, which will pick up the correct settings from
1031
+ # what Xcode puts into the environment.
1032
+ concrete_output = ExpandXcodeVariables(output, rule_input_dict)
1033
+ concrete_outputs_for_this_rule_source.append(concrete_output)
1034
+
1035
+ # Add all concrete outputs to the project.
1036
+ pbxp.AddOrGetFileInRootGroup(concrete_output)
1037
+
1038
+ concrete_outputs_by_rule_source.append(
1039
+ concrete_outputs_for_this_rule_source
1040
+ )
1041
+ concrete_outputs_all.extend(concrete_outputs_for_this_rule_source)
1042
+
1043
+ # TODO(mark): Should verify that at most one of these is specified.
1044
+ if int(rule.get("process_outputs_as_sources", False)):
1045
+ for output in concrete_outputs_for_this_rule_source:
1046
+ AddSourceToTarget(output, type, pbxp, xct)
1047
+
1048
+ # If the file came from the mac_bundle_resources list or if the rule
1049
+ # is marked to process outputs as bundle resource, do so.
1050
+ was_mac_bundle_resource = rule_source in tgt_mac_bundle_resources
1051
+ if was_mac_bundle_resource or int(
1052
+ rule.get("process_outputs_as_mac_bundle_resources", False)
1053
+ ):
1054
+ for output in concrete_outputs_for_this_rule_source:
1055
+ AddResourceToTarget(output, pbxp, xct)
1056
+
1057
+ # Do we have a message to print when this rule runs?
1058
+ message = rule.get("message")
1059
+ if message:
1060
+ message = gyp.common.EncodePOSIXShellArgument(message)
1061
+ message = ExpandXcodeVariables(message, rule_input_dict)
1062
+ messages.append(message)
1063
+
1064
+ # Turn the list into a string that can be passed to a shell.
1065
+ action_string = gyp.common.EncodePOSIXShellList(rule["action"])
1066
+
1067
+ action = ExpandXcodeVariables(action_string, rule_input_dict)
1068
+ actions.append(action)
1069
+
1070
+ if len(concrete_outputs_all) > 0:
1071
+ # TODO(mark): There's a possibility for collision here. Consider
1072
+ # target "t" rule "A_r" and target "t_A" rule "r".
1073
+ makefile_name = "%s.make" % re.sub(
1074
+ "[^a-zA-Z0-9_]", "_", "{}_{}".format(target_name, rule["rule_name"])
1075
+ )
1076
+ makefile_path = os.path.join(
1077
+ xcode_projects[build_file].path, makefile_name
1078
+ )
1079
+ # TODO(mark): try/close? Write to a temporary file and swap it only
1080
+ # if it's got changes?
1081
+ makefile = open(makefile_path, "w")
1082
+
1083
+ # make will build the first target in the makefile by default. By
1084
+ # convention, it's called "all". List all (or at least one)
1085
+ # concrete output for each rule source as a prerequisite of the "all"
1086
+ # target.
1087
+ makefile.write("all: \\\n")
1088
+ for concrete_output_index, concrete_output_by_rule_source in enumerate(
1089
+ concrete_outputs_by_rule_source
1090
+ ):
1091
+ # Only list the first (index [0]) concrete output of each input
1092
+ # in the "all" target. Otherwise, a parallel make (-j > 1) would
1093
+ # attempt to process each input multiple times simultaneously.
1094
+ # Otherwise, "all" could just contain the entire list of
1095
+ # concrete_outputs_all.
1096
+ concrete_output = concrete_output_by_rule_source[0]
1097
+ if (
1098
+ concrete_output_index
1099
+ == len(concrete_outputs_by_rule_source) - 1
1100
+ ):
1101
+ eol = ""
1102
+ else:
1103
+ eol = " \\"
1104
+ makefile.write(f" {concrete_output}{eol}\n")
1105
+
1106
+ for (rule_source, concrete_outputs, message, action) in zip(
1107
+ rule["rule_sources"],
1108
+ concrete_outputs_by_rule_source,
1109
+ messages,
1110
+ actions,
1111
+ ):
1112
+ makefile.write("\n")
1113
+
1114
+ # Add a rule that declares it can build each concrete output of a
1115
+ # rule source. Collect the names of the directories that are
1116
+ # required.
1117
+ concrete_output_dirs = []
1118
+ for concrete_output_index, concrete_output in enumerate(
1119
+ concrete_outputs
1120
+ ):
1121
+ if concrete_output_index == 0:
1122
+ bol = ""
1123
+ else:
1124
+ bol = " "
1125
+ makefile.write(f"{bol}{concrete_output} \\\n")
1126
+
1127
+ concrete_output_dir = posixpath.dirname(concrete_output)
1128
+ if (
1129
+ concrete_output_dir
1130
+ and concrete_output_dir not in concrete_output_dirs
1131
+ ):
1132
+ concrete_output_dirs.append(concrete_output_dir)
1133
+
1134
+ makefile.write(" : \\\n")
1135
+
1136
+ # The prerequisites for this rule are the rule source itself and
1137
+ # the set of additional rule inputs, if any.
1138
+ prerequisites = [rule_source]
1139
+ prerequisites.extend(rule.get("inputs", []))
1140
+ for prerequisite_index, prerequisite in enumerate(prerequisites):
1141
+ if prerequisite_index == len(prerequisites) - 1:
1142
+ eol = ""
1143
+ else:
1144
+ eol = " \\"
1145
+ makefile.write(f" {prerequisite}{eol}\n")
1146
+
1147
+ # Make sure that output directories exist before executing the rule
1148
+ # action.
1149
+ if len(concrete_output_dirs) > 0:
1150
+ makefile.write(
1151
+ '\t@mkdir -p "%s"\n' % '" "'.join(concrete_output_dirs)
1152
+ )
1153
+
1154
+ # The rule message and action have already had
1155
+ # the necessary variable substitutions performed.
1156
+ if message:
1157
+ # Mark it with note: so Xcode picks it up in build output.
1158
+ makefile.write("\t@echo note: %s\n" % message)
1159
+ makefile.write("\t%s\n" % action)
1160
+
1161
+ makefile.close()
1162
+
1163
+ # It might be nice to ensure that needed output directories exist
1164
+ # here rather than in each target in the Makefile, but that wouldn't
1165
+ # work if there ever was a concrete output that had an input-dependent
1166
+ # variable anywhere other than in the leaf position.
1167
+
1168
+ # Don't declare any inputPaths or outputPaths. If they're present,
1169
+ # Xcode will provide a slight optimization by only running the script
1170
+ # phase if any output is missing or outdated relative to any input.
1171
+ # Unfortunately, it will also assume that all outputs are touched by
1172
+ # the script, and if the outputs serve as files in a compilation
1173
+ # phase, they will be unconditionally rebuilt. Since make might not
1174
+ # rebuild everything that could be declared here as an output, this
1175
+ # extra compilation activity is unnecessary. With inputPaths and
1176
+ # outputPaths not supplied, make will always be called, but it knows
1177
+ # enough to not do anything when everything is up-to-date.
1178
+
1179
+ # To help speed things up, pass -j COUNT to make so it does some work
1180
+ # in parallel. Don't use ncpus because Xcode will build ncpus targets
1181
+ # in parallel and if each target happens to have a rules step, there
1182
+ # would be ncpus^2 things going. With a machine that has 2 quad-core
1183
+ # Xeons, a build can quickly run out of processes based on
1184
+ # scheduling/other tasks, and randomly failing builds are no good.
1185
+ script = (
1186
+ """JOB_COUNT="$(/usr/sbin/sysctl -n hw.ncpu)"
1187
+ if [ "${JOB_COUNT}" -gt 4 ]; then
1188
+ JOB_COUNT=4
1189
+ fi
1190
+ exec xcrun make -f "${PROJECT_FILE_PATH}/%s" -j "${JOB_COUNT}"
1191
+ exit 1
1192
+ """
1193
+ % makefile_name
1194
+ )
1195
+ ssbp = gyp.xcodeproj_file.PBXShellScriptBuildPhase(
1196
+ {
1197
+ "name": 'Rule "' + rule["rule_name"] + '"',
1198
+ "shellScript": script,
1199
+ "showEnvVarsInLog": 0,
1200
+ }
1201
+ )
1202
+
1203
+ if support_xct:
1204
+ support_xct.AppendProperty("buildPhases", ssbp)
1205
+ else:
1206
+ # TODO(mark): this assumes too much knowledge of the internals of
1207
+ # xcodeproj_file; some of these smarts should move
1208
+ # into xcodeproj_file itself.
1209
+ xct._properties["buildPhases"].insert(prebuild_index, ssbp)
1210
+ prebuild_index = prebuild_index + 1
1211
+
1212
+ # Extra rule inputs also go into the project file. Concrete outputs were
1213
+ # already added when they were computed.
1214
+ groups = ["inputs", "inputs_excluded"]
1215
+ if skip_excluded_files:
1216
+ groups = [x for x in groups if not x.endswith("_excluded")]
1217
+ for group in groups:
1218
+ for item in rule.get(group, []):
1219
+ pbxp.AddOrGetFileInRootGroup(item)
1220
+
1221
+ # Add "sources".
1222
+ for source in spec.get("sources", []):
1223
+ (source_root, source_extension) = posixpath.splitext(source)
1224
+ if source_extension[1:] not in rules_by_ext:
1225
+ # AddSourceToTarget will add the file to a root group if it's not
1226
+ # already there.
1227
+ AddSourceToTarget(source, type, pbxp, xct)
1228
+ else:
1229
+ pbxp.AddOrGetFileInRootGroup(source)
1230
+
1231
+ # Add "mac_bundle_resources" and "mac_framework_private_headers" if
1232
+ # it's a bundle of any type.
1233
+ if is_bundle:
1234
+ for resource in tgt_mac_bundle_resources:
1235
+ (resource_root, resource_extension) = posixpath.splitext(resource)
1236
+ if resource_extension[1:] not in rules_by_ext:
1237
+ AddResourceToTarget(resource, pbxp, xct)
1238
+ else:
1239
+ pbxp.AddOrGetFileInRootGroup(resource)
1240
+
1241
+ for header in spec.get("mac_framework_private_headers", []):
1242
+ AddHeaderToTarget(header, pbxp, xct, False)
1243
+
1244
+ # Add "mac_framework_headers". These can be valid for both frameworks
1245
+ # and static libraries.
1246
+ if is_bundle or type == "static_library":
1247
+ for header in spec.get("mac_framework_headers", []):
1248
+ AddHeaderToTarget(header, pbxp, xct, True)
1249
+
1250
+ # Add "copies".
1251
+ pbxcp_dict = {}
1252
+ for copy_group in spec.get("copies", []):
1253
+ dest = copy_group["destination"]
1254
+ if dest[0] not in ("/", "$"):
1255
+ # Relative paths are relative to $(SRCROOT).
1256
+ dest = "$(SRCROOT)/" + dest
1257
+
1258
+ code_sign = int(copy_group.get("xcode_code_sign", 0))
1259
+ settings = (None, "{ATTRIBUTES = (CodeSignOnCopy, ); }")[code_sign]
1260
+
1261
+ # Coalesce multiple "copies" sections in the same target with the same
1262
+ # "destination" property into the same PBXCopyFilesBuildPhase, otherwise
1263
+ # they'll wind up with ID collisions.
1264
+ pbxcp = pbxcp_dict.get(dest, None)
1265
+ if pbxcp is None:
1266
+ pbxcp = gyp.xcodeproj_file.PBXCopyFilesBuildPhase(
1267
+ {"name": "Copy to " + copy_group["destination"]}, parent=xct
1268
+ )
1269
+ pbxcp.SetDestination(dest)
1270
+
1271
+ # TODO(mark): The usual comment about this knowing too much about
1272
+ # gyp.xcodeproj_file internals applies.
1273
+ xct._properties["buildPhases"].insert(prebuild_index, pbxcp)
1274
+
1275
+ pbxcp_dict[dest] = pbxcp
1276
+
1277
+ for file in copy_group["files"]:
1278
+ pbxcp.AddFile(file, settings)
1279
+
1280
+ # Excluded files can also go into the project file.
1281
+ if not skip_excluded_files:
1282
+ for key in [
1283
+ "sources",
1284
+ "mac_bundle_resources",
1285
+ "mac_framework_headers",
1286
+ "mac_framework_private_headers",
1287
+ ]:
1288
+ excluded_key = key + "_excluded"
1289
+ for item in spec.get(excluded_key, []):
1290
+ pbxp.AddOrGetFileInRootGroup(item)
1291
+
1292
+ # So can "inputs" and "outputs" sections of "actions" groups.
1293
+ groups = ["inputs", "inputs_excluded", "outputs", "outputs_excluded"]
1294
+ if skip_excluded_files:
1295
+ groups = [x for x in groups if not x.endswith("_excluded")]
1296
+ for action in spec.get("actions", []):
1297
+ for group in groups:
1298
+ for item in action.get(group, []):
1299
+ # Exclude anything in BUILT_PRODUCTS_DIR. They're products, not
1300
+ # sources.
1301
+ if not item.startswith("$(BUILT_PRODUCTS_DIR)/"):
1302
+ pbxp.AddOrGetFileInRootGroup(item)
1303
+
1304
+ for postbuild in spec.get("postbuilds", []):
1305
+ action_string_sh = gyp.common.EncodePOSIXShellList(postbuild["action"])
1306
+ script = "exec " + action_string_sh + "\nexit 1\n"
1307
+
1308
+ # Make the postbuild step depend on the output of ld or ar from this
1309
+ # target. Apparently putting the script step after the link step isn't
1310
+ # sufficient to ensure proper ordering in all cases. With an input
1311
+ # declared but no outputs, the script step should run every time, as
1312
+ # desired.
1313
+ ssbp = gyp.xcodeproj_file.PBXShellScriptBuildPhase(
1314
+ {
1315
+ "inputPaths": ["$(BUILT_PRODUCTS_DIR)/$(EXECUTABLE_PATH)"],
1316
+ "name": 'Postbuild "' + postbuild["postbuild_name"] + '"',
1317
+ "shellScript": script,
1318
+ "showEnvVarsInLog": 0,
1319
+ }
1320
+ )
1321
+ xct.AppendProperty("buildPhases", ssbp)
1322
+
1323
+ # Add dependencies before libraries, because adding a dependency may imply
1324
+ # adding a library. It's preferable to keep dependencies listed first
1325
+ # during a link phase so that they can override symbols that would
1326
+ # otherwise be provided by libraries, which will usually include system
1327
+ # libraries. On some systems, ld is finicky and even requires the
1328
+ # libraries to be ordered in such a way that unresolved symbols in
1329
+ # earlier-listed libraries may only be resolved by later-listed libraries.
1330
+ # The Mac linker doesn't work that way, but other platforms do, and so
1331
+ # their linker invocations need to be constructed in this way. There's
1332
+ # no compelling reason for Xcode's linker invocations to differ.
1333
+
1334
+ if "dependencies" in spec:
1335
+ for dependency in spec["dependencies"]:
1336
+ xct.AddDependency(xcode_targets[dependency])
1337
+ # The support project also gets the dependencies (in case they are
1338
+ # needed for the actions/rules to work).
1339
+ if support_xct:
1340
+ support_xct.AddDependency(xcode_targets[dependency])
1341
+
1342
+ if "libraries" in spec:
1343
+ for library in spec["libraries"]:
1344
+ xct.FrameworksPhase().AddFile(library)
1345
+ # Add the library's directory to LIBRARY_SEARCH_PATHS if necessary.
1346
+ # I wish Xcode handled this automatically.
1347
+ library_dir = posixpath.dirname(library)
1348
+ if library_dir not in xcode_standard_library_dirs and (
1349
+ not xct.HasBuildSetting(_library_search_paths_var)
1350
+ or library_dir not in xct.GetBuildSetting(_library_search_paths_var)
1351
+ ):
1352
+ xct.AppendBuildSetting(_library_search_paths_var, library_dir)
1353
+
1354
+ for configuration_name in configuration_names:
1355
+ configuration = spec["configurations"][configuration_name]
1356
+ xcbc = xct.ConfigurationNamed(configuration_name)
1357
+ for include_dir in configuration.get("mac_framework_dirs", []):
1358
+ xcbc.AppendBuildSetting("FRAMEWORK_SEARCH_PATHS", include_dir)
1359
+ for include_dir in configuration.get("include_dirs", []):
1360
+ xcbc.AppendBuildSetting("HEADER_SEARCH_PATHS", include_dir)
1361
+ for library_dir in configuration.get("library_dirs", []):
1362
+ if library_dir not in xcode_standard_library_dirs and (
1363
+ not xcbc.HasBuildSetting(_library_search_paths_var)
1364
+ or library_dir
1365
+ not in xcbc.GetBuildSetting(_library_search_paths_var)
1366
+ ):
1367
+ xcbc.AppendBuildSetting(_library_search_paths_var, library_dir)
1368
+
1369
+ if "defines" in configuration:
1370
+ for define in configuration["defines"]:
1371
+ set_define = EscapeXcodeDefine(define)
1372
+ xcbc.AppendBuildSetting("GCC_PREPROCESSOR_DEFINITIONS", set_define)
1373
+ if "xcode_settings" in configuration:
1374
+ for xck, xcv in configuration["xcode_settings"].items():
1375
+ xcbc.SetBuildSetting(xck, xcv)
1376
+ if "xcode_config_file" in configuration:
1377
+ config_ref = pbxp.AddOrGetFileInRootGroup(
1378
+ configuration["xcode_config_file"]
1379
+ )
1380
+ xcbc.SetBaseConfiguration(config_ref)
1381
+
1382
+ build_files = []
1383
+ for build_file, build_file_dict in data.items():
1384
+ if build_file.endswith(".gyp"):
1385
+ build_files.append(build_file)
1386
+
1387
+ for build_file in build_files:
1388
+ xcode_projects[build_file].Finalize1(xcode_targets, serialize_all_tests)
1389
+
1390
+ for build_file in build_files:
1391
+ xcode_projects[build_file].Finalize2(xcode_targets, xcode_target_to_target_dict)
1392
+
1393
+ for build_file in build_files:
1394
+ xcode_projects[build_file].Write()