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.
- wsba_hockey/__init__.py +1 -1
- wsba_hockey/data_pipelines.py +183 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/duckdb/vendor.py +146 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/flatted/python/flatted.py +149 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/flatted/python/test.py +63 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/gyp_main.py +45 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +367 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1270 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +153 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +271 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +690 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/common.py +661 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +78 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +165 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +109 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +808 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1173 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1321 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +120 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +103 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +464 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +58 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2714 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3981 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2936 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +55 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1394 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +25 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/input.py +3130 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +98 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +771 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1271 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +374 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1939 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +302 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3197 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/test_gyp.py +261 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/graphviz.py +102 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_gyp.py +156 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_sln.py +181 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_vcproj.py +339 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/test/fixtures/test-charmap.py +31 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/update-gyp.py +64 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/gyp_main.py +45 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +367 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1270 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +153 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +271 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +666 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/common.py +654 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +78 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +165 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +109 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +808 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1173 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1321 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +120 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +103 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +464 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +58 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2518 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3978 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2936 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +55 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1394 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +25 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/input.py +3137 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +98 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +771 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1271 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +374 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1939 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +302 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3197 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/setup.py +42 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/test_gyp.py +260 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/graphviz.py +102 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_gyp.py +156 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_sln.py +181 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_vcproj.py +339 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/test/fixtures/test-charmap.py +31 -0
- wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/update-gyp.py +46 -0
- wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/game_stats/app.py +400 -0
- wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/game_stats/name_fix.py +47 -0
- wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/app.py +108 -0
- wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/plot.py +93 -0
- wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/rink_plot.py +245 -0
- wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/app.py +145 -0
- wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/plot.py +77 -0
- wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/rink_plot.py +245 -0
- wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/app.py +389 -0
- wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/plot.py +70 -0
- wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/rink_plot.py +245 -0
- wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/app.py +110 -0
- wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/plot.py +58 -0
- wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/rink_plot.py +245 -0
- wsba_hockey/tools/agg.py +243 -54
- wsba_hockey/tools/plotting.py +25 -25
- wsba_hockey/tools/scraping.py +154 -263
- wsba_hockey/tools/xg_model.py +369 -315
- wsba_hockey/workspace.py +22 -117
- wsba_hockey/wsba_main.py +499 -167
- {wsba_hockey-1.0.3.dist-info → wsba_hockey-1.0.5.dist-info}/METADATA +1 -1
- wsba_hockey-1.0.5.dist-info/RECORD +135 -0
- {wsba_hockey-1.0.3.dist-info → wsba_hockey-1.0.5.dist-info}/WHEEL +1 -1
- wsba_hockey/stats/calculate_viz/shot_impact.py +0 -2
- wsba_hockey-1.0.3.dist-info/RECORD +0 -19
- {wsba_hockey-1.0.3.dist-info → wsba_hockey-1.0.5.dist-info}/licenses/LICENSE +0 -0
- {wsba_hockey-1.0.3.dist-info → wsba_hockey-1.0.5.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,1939 @@
|
|
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
|
+
This module contains classes that help to emulate xcodebuild behavior on top of
|
7
|
+
other build systems, such as make and ninja.
|
8
|
+
"""
|
9
|
+
|
10
|
+
|
11
|
+
import copy
|
12
|
+
import gyp.common
|
13
|
+
import os
|
14
|
+
import os.path
|
15
|
+
import re
|
16
|
+
import shlex
|
17
|
+
import subprocess
|
18
|
+
import sys
|
19
|
+
from gyp.common import GypError
|
20
|
+
|
21
|
+
# Populated lazily by XcodeVersion, for efficiency, and to fix an issue when
|
22
|
+
# "xcodebuild" is called too quickly (it has been found to return incorrect
|
23
|
+
# version number).
|
24
|
+
XCODE_VERSION_CACHE = None
|
25
|
+
|
26
|
+
# Populated lazily by GetXcodeArchsDefault, to an |XcodeArchsDefault| instance
|
27
|
+
# corresponding to the installed version of Xcode.
|
28
|
+
XCODE_ARCHS_DEFAULT_CACHE = None
|
29
|
+
|
30
|
+
|
31
|
+
def XcodeArchsVariableMapping(archs, archs_including_64_bit=None):
|
32
|
+
"""Constructs a dictionary with expansion for $(ARCHS_STANDARD) variable,
|
33
|
+
and optionally for $(ARCHS_STANDARD_INCLUDING_64_BIT)."""
|
34
|
+
mapping = {"$(ARCHS_STANDARD)": archs}
|
35
|
+
if archs_including_64_bit:
|
36
|
+
mapping["$(ARCHS_STANDARD_INCLUDING_64_BIT)"] = archs_including_64_bit
|
37
|
+
return mapping
|
38
|
+
|
39
|
+
|
40
|
+
class XcodeArchsDefault:
|
41
|
+
"""A class to resolve ARCHS variable from xcode_settings, resolving Xcode
|
42
|
+
macros and implementing filtering by VALID_ARCHS. The expansion of macros
|
43
|
+
depends on the SDKROOT used ("macosx", "iphoneos", "iphonesimulator") and
|
44
|
+
on the version of Xcode.
|
45
|
+
"""
|
46
|
+
|
47
|
+
# Match variable like $(ARCHS_STANDARD).
|
48
|
+
variable_pattern = re.compile(r"\$\([a-zA-Z_][a-zA-Z0-9_]*\)$")
|
49
|
+
|
50
|
+
def __init__(self, default, mac, iphonesimulator, iphoneos):
|
51
|
+
self._default = (default,)
|
52
|
+
self._archs = {"mac": mac, "ios": iphoneos, "iossim": iphonesimulator}
|
53
|
+
|
54
|
+
def _VariableMapping(self, sdkroot):
|
55
|
+
"""Returns the dictionary of variable mapping depending on the SDKROOT."""
|
56
|
+
sdkroot = sdkroot.lower()
|
57
|
+
if "iphoneos" in sdkroot:
|
58
|
+
return self._archs["ios"]
|
59
|
+
elif "iphonesimulator" in sdkroot:
|
60
|
+
return self._archs["iossim"]
|
61
|
+
else:
|
62
|
+
return self._archs["mac"]
|
63
|
+
|
64
|
+
def _ExpandArchs(self, archs, sdkroot):
|
65
|
+
"""Expands variables references in ARCHS, and remove duplicates."""
|
66
|
+
variable_mapping = self._VariableMapping(sdkroot)
|
67
|
+
expanded_archs = []
|
68
|
+
for arch in archs:
|
69
|
+
if self.variable_pattern.match(arch):
|
70
|
+
variable = arch
|
71
|
+
try:
|
72
|
+
variable_expansion = variable_mapping[variable]
|
73
|
+
for arch in variable_expansion:
|
74
|
+
if arch not in expanded_archs:
|
75
|
+
expanded_archs.append(arch)
|
76
|
+
except KeyError:
|
77
|
+
print('Warning: Ignoring unsupported variable "%s".' % variable)
|
78
|
+
elif arch not in expanded_archs:
|
79
|
+
expanded_archs.append(arch)
|
80
|
+
return expanded_archs
|
81
|
+
|
82
|
+
def ActiveArchs(self, archs, valid_archs, sdkroot):
|
83
|
+
"""Expands variables references in ARCHS, and filter by VALID_ARCHS if it
|
84
|
+
is defined (if not set, Xcode accept any value in ARCHS, otherwise, only
|
85
|
+
values present in VALID_ARCHS are kept)."""
|
86
|
+
expanded_archs = self._ExpandArchs(archs or self._default, sdkroot or "")
|
87
|
+
if valid_archs:
|
88
|
+
filtered_archs = []
|
89
|
+
for arch in expanded_archs:
|
90
|
+
if arch in valid_archs:
|
91
|
+
filtered_archs.append(arch)
|
92
|
+
expanded_archs = filtered_archs
|
93
|
+
return expanded_archs
|
94
|
+
|
95
|
+
|
96
|
+
def GetXcodeArchsDefault():
|
97
|
+
"""Returns the |XcodeArchsDefault| object to use to expand ARCHS for the
|
98
|
+
installed version of Xcode. The default values used by Xcode for ARCHS
|
99
|
+
and the expansion of the variables depends on the version of Xcode used.
|
100
|
+
|
101
|
+
For all version anterior to Xcode 5.0 or posterior to Xcode 5.1 included
|
102
|
+
uses $(ARCHS_STANDARD) if ARCHS is unset, while Xcode 5.0 to 5.0.2 uses
|
103
|
+
$(ARCHS_STANDARD_INCLUDING_64_BIT). This variable was added to Xcode 5.0
|
104
|
+
and deprecated with Xcode 5.1.
|
105
|
+
|
106
|
+
For "macosx" SDKROOT, all version starting with Xcode 5.0 includes 64-bit
|
107
|
+
architecture as part of $(ARCHS_STANDARD) and default to only building it.
|
108
|
+
|
109
|
+
For "iphoneos" and "iphonesimulator" SDKROOT, 64-bit architectures are part
|
110
|
+
of $(ARCHS_STANDARD_INCLUDING_64_BIT) from Xcode 5.0. From Xcode 5.1, they
|
111
|
+
are also part of $(ARCHS_STANDARD).
|
112
|
+
|
113
|
+
All these rules are coded in the construction of the |XcodeArchsDefault|
|
114
|
+
object to use depending on the version of Xcode detected. The object is
|
115
|
+
for performance reason."""
|
116
|
+
global XCODE_ARCHS_DEFAULT_CACHE
|
117
|
+
if XCODE_ARCHS_DEFAULT_CACHE:
|
118
|
+
return XCODE_ARCHS_DEFAULT_CACHE
|
119
|
+
xcode_version, _ = XcodeVersion()
|
120
|
+
if xcode_version < "0500":
|
121
|
+
XCODE_ARCHS_DEFAULT_CACHE = XcodeArchsDefault(
|
122
|
+
"$(ARCHS_STANDARD)",
|
123
|
+
XcodeArchsVariableMapping(["i386"]),
|
124
|
+
XcodeArchsVariableMapping(["i386"]),
|
125
|
+
XcodeArchsVariableMapping(["armv7"]),
|
126
|
+
)
|
127
|
+
elif xcode_version < "0510":
|
128
|
+
XCODE_ARCHS_DEFAULT_CACHE = XcodeArchsDefault(
|
129
|
+
"$(ARCHS_STANDARD_INCLUDING_64_BIT)",
|
130
|
+
XcodeArchsVariableMapping(["x86_64"], ["x86_64"]),
|
131
|
+
XcodeArchsVariableMapping(["i386"], ["i386", "x86_64"]),
|
132
|
+
XcodeArchsVariableMapping(
|
133
|
+
["armv7", "armv7s"], ["armv7", "armv7s", "arm64"]
|
134
|
+
),
|
135
|
+
)
|
136
|
+
else:
|
137
|
+
XCODE_ARCHS_DEFAULT_CACHE = XcodeArchsDefault(
|
138
|
+
"$(ARCHS_STANDARD)",
|
139
|
+
XcodeArchsVariableMapping(["x86_64"], ["x86_64"]),
|
140
|
+
XcodeArchsVariableMapping(["i386", "x86_64"], ["i386", "x86_64"]),
|
141
|
+
XcodeArchsVariableMapping(
|
142
|
+
["armv7", "armv7s", "arm64"], ["armv7", "armv7s", "arm64"]
|
143
|
+
),
|
144
|
+
)
|
145
|
+
return XCODE_ARCHS_DEFAULT_CACHE
|
146
|
+
|
147
|
+
|
148
|
+
class XcodeSettings:
|
149
|
+
"""A class that understands the gyp 'xcode_settings' object."""
|
150
|
+
|
151
|
+
# Populated lazily by _SdkPath(). Shared by all XcodeSettings, so cached
|
152
|
+
# at class-level for efficiency.
|
153
|
+
_sdk_path_cache = {}
|
154
|
+
_platform_path_cache = {}
|
155
|
+
_sdk_root_cache = {}
|
156
|
+
|
157
|
+
# Populated lazily by GetExtraPlistItems(). Shared by all XcodeSettings, so
|
158
|
+
# cached at class-level for efficiency.
|
159
|
+
_plist_cache = {}
|
160
|
+
|
161
|
+
# Populated lazily by GetIOSPostbuilds. Shared by all XcodeSettings, so
|
162
|
+
# cached at class-level for efficiency.
|
163
|
+
_codesigning_key_cache = {}
|
164
|
+
|
165
|
+
def __init__(self, spec):
|
166
|
+
self.spec = spec
|
167
|
+
|
168
|
+
self.isIOS = False
|
169
|
+
self.mac_toolchain_dir = None
|
170
|
+
self.header_map_path = None
|
171
|
+
|
172
|
+
# Per-target 'xcode_settings' are pushed down into configs earlier by gyp.
|
173
|
+
# This means self.xcode_settings[config] always contains all settings
|
174
|
+
# for that config -- the per-target settings as well. Settings that are
|
175
|
+
# the same for all configs are implicitly per-target settings.
|
176
|
+
self.xcode_settings = {}
|
177
|
+
configs = spec["configurations"]
|
178
|
+
for configname, config in configs.items():
|
179
|
+
self.xcode_settings[configname] = config.get("xcode_settings", {})
|
180
|
+
self._ConvertConditionalKeys(configname)
|
181
|
+
if self.xcode_settings[configname].get("IPHONEOS_DEPLOYMENT_TARGET", None):
|
182
|
+
self.isIOS = True
|
183
|
+
|
184
|
+
# This is only non-None temporarily during the execution of some methods.
|
185
|
+
self.configname = None
|
186
|
+
|
187
|
+
# Used by _AdjustLibrary to match .a and .dylib entries in libraries.
|
188
|
+
self.library_re = re.compile(r"^lib([^/]+)\.(a|dylib)$")
|
189
|
+
|
190
|
+
def _ConvertConditionalKeys(self, configname):
|
191
|
+
"""Converts or warns on conditional keys. Xcode supports conditional keys,
|
192
|
+
such as CODE_SIGN_IDENTITY[sdk=iphoneos*]. This is a partial implementation
|
193
|
+
with some keys converted while the rest force a warning."""
|
194
|
+
settings = self.xcode_settings[configname]
|
195
|
+
conditional_keys = [key for key in settings if key.endswith("]")]
|
196
|
+
for key in conditional_keys:
|
197
|
+
# If you need more, speak up at http://crbug.com/122592
|
198
|
+
if key.endswith("[sdk=iphoneos*]"):
|
199
|
+
if configname.endswith("iphoneos"):
|
200
|
+
new_key = key.split("[")[0]
|
201
|
+
settings[new_key] = settings[key]
|
202
|
+
else:
|
203
|
+
print(
|
204
|
+
"Warning: Conditional keys not implemented, ignoring:",
|
205
|
+
" ".join(conditional_keys),
|
206
|
+
)
|
207
|
+
del settings[key]
|
208
|
+
|
209
|
+
def _Settings(self):
|
210
|
+
assert self.configname
|
211
|
+
return self.xcode_settings[self.configname]
|
212
|
+
|
213
|
+
def _Test(self, test_key, cond_key, default):
|
214
|
+
return self._Settings().get(test_key, default) == cond_key
|
215
|
+
|
216
|
+
def _Appendf(self, lst, test_key, format_str, default=None):
|
217
|
+
if test_key in self._Settings():
|
218
|
+
lst.append(format_str % str(self._Settings()[test_key]))
|
219
|
+
elif default:
|
220
|
+
lst.append(format_str % str(default))
|
221
|
+
|
222
|
+
def _WarnUnimplemented(self, test_key):
|
223
|
+
if test_key in self._Settings():
|
224
|
+
print('Warning: Ignoring not yet implemented key "%s".' % test_key)
|
225
|
+
|
226
|
+
def IsBinaryOutputFormat(self, configname):
|
227
|
+
default = "binary" if self.isIOS else "xml"
|
228
|
+
format = self.xcode_settings[configname].get("INFOPLIST_OUTPUT_FORMAT", default)
|
229
|
+
return format == "binary"
|
230
|
+
|
231
|
+
def IsIosFramework(self):
|
232
|
+
return self.spec["type"] == "shared_library" and self._IsBundle() and self.isIOS
|
233
|
+
|
234
|
+
def _IsBundle(self):
|
235
|
+
return (
|
236
|
+
int(self.spec.get("mac_bundle", 0)) != 0
|
237
|
+
or self._IsXCTest()
|
238
|
+
or self._IsXCUiTest()
|
239
|
+
)
|
240
|
+
|
241
|
+
def _IsXCTest(self):
|
242
|
+
return int(self.spec.get("mac_xctest_bundle", 0)) != 0
|
243
|
+
|
244
|
+
def _IsXCUiTest(self):
|
245
|
+
return int(self.spec.get("mac_xcuitest_bundle", 0)) != 0
|
246
|
+
|
247
|
+
def _IsIosAppExtension(self):
|
248
|
+
return int(self.spec.get("ios_app_extension", 0)) != 0
|
249
|
+
|
250
|
+
def _IsIosWatchKitExtension(self):
|
251
|
+
return int(self.spec.get("ios_watchkit_extension", 0)) != 0
|
252
|
+
|
253
|
+
def _IsIosWatchApp(self):
|
254
|
+
return int(self.spec.get("ios_watch_app", 0)) != 0
|
255
|
+
|
256
|
+
def GetFrameworkVersion(self):
|
257
|
+
"""Returns the framework version of the current target. Only valid for
|
258
|
+
bundles."""
|
259
|
+
assert self._IsBundle()
|
260
|
+
return self.GetPerTargetSetting("FRAMEWORK_VERSION", default="A")
|
261
|
+
|
262
|
+
def GetWrapperExtension(self):
|
263
|
+
"""Returns the bundle extension (.app, .framework, .plugin, etc). Only
|
264
|
+
valid for bundles."""
|
265
|
+
assert self._IsBundle()
|
266
|
+
if self.spec["type"] in ("loadable_module", "shared_library"):
|
267
|
+
default_wrapper_extension = {
|
268
|
+
"loadable_module": "bundle",
|
269
|
+
"shared_library": "framework",
|
270
|
+
}[self.spec["type"]]
|
271
|
+
wrapper_extension = self.GetPerTargetSetting(
|
272
|
+
"WRAPPER_EXTENSION", default=default_wrapper_extension
|
273
|
+
)
|
274
|
+
return "." + self.spec.get("product_extension", wrapper_extension)
|
275
|
+
elif self.spec["type"] == "executable":
|
276
|
+
if self._IsIosAppExtension() or self._IsIosWatchKitExtension():
|
277
|
+
return "." + self.spec.get("product_extension", "appex")
|
278
|
+
else:
|
279
|
+
return "." + self.spec.get("product_extension", "app")
|
280
|
+
else:
|
281
|
+
assert False, "Don't know extension for '{}', target '{}'".format(
|
282
|
+
self.spec["type"],
|
283
|
+
self.spec["target_name"],
|
284
|
+
)
|
285
|
+
|
286
|
+
def GetProductName(self):
|
287
|
+
"""Returns PRODUCT_NAME."""
|
288
|
+
return self.spec.get("product_name", self.spec["target_name"])
|
289
|
+
|
290
|
+
def GetFullProductName(self):
|
291
|
+
"""Returns FULL_PRODUCT_NAME."""
|
292
|
+
if self._IsBundle():
|
293
|
+
return self.GetWrapperName()
|
294
|
+
else:
|
295
|
+
return self._GetStandaloneBinaryPath()
|
296
|
+
|
297
|
+
def GetWrapperName(self):
|
298
|
+
"""Returns the directory name of the bundle represented by this target.
|
299
|
+
Only valid for bundles."""
|
300
|
+
assert self._IsBundle()
|
301
|
+
return self.GetProductName() + self.GetWrapperExtension()
|
302
|
+
|
303
|
+
def GetBundleContentsFolderPath(self):
|
304
|
+
"""Returns the qualified path to the bundle's contents folder. E.g.
|
305
|
+
Chromium.app/Contents or Foo.bundle/Versions/A. Only valid for bundles."""
|
306
|
+
if self.isIOS:
|
307
|
+
return self.GetWrapperName()
|
308
|
+
assert self._IsBundle()
|
309
|
+
if self.spec["type"] == "shared_library":
|
310
|
+
return os.path.join(
|
311
|
+
self.GetWrapperName(), "Versions", self.GetFrameworkVersion()
|
312
|
+
)
|
313
|
+
else:
|
314
|
+
# loadable_modules have a 'Contents' folder like executables.
|
315
|
+
return os.path.join(self.GetWrapperName(), "Contents")
|
316
|
+
|
317
|
+
def GetBundleResourceFolder(self):
|
318
|
+
"""Returns the qualified path to the bundle's resource folder. E.g.
|
319
|
+
Chromium.app/Contents/Resources. Only valid for bundles."""
|
320
|
+
assert self._IsBundle()
|
321
|
+
if self.isIOS:
|
322
|
+
return self.GetBundleContentsFolderPath()
|
323
|
+
return os.path.join(self.GetBundleContentsFolderPath(), "Resources")
|
324
|
+
|
325
|
+
def GetBundleExecutableFolderPath(self):
|
326
|
+
"""Returns the qualified path to the bundle's executables folder. E.g.
|
327
|
+
Chromium.app/Contents/MacOS. Only valid for bundles."""
|
328
|
+
assert self._IsBundle()
|
329
|
+
if self.spec["type"] in ("shared_library") or self.isIOS:
|
330
|
+
return self.GetBundleContentsFolderPath()
|
331
|
+
elif self.spec["type"] in ("executable", "loadable_module"):
|
332
|
+
return os.path.join(self.GetBundleContentsFolderPath(), "MacOS")
|
333
|
+
|
334
|
+
def GetBundleJavaFolderPath(self):
|
335
|
+
"""Returns the qualified path to the bundle's Java resource folder.
|
336
|
+
E.g. Chromium.app/Contents/Resources/Java. Only valid for bundles."""
|
337
|
+
assert self._IsBundle()
|
338
|
+
return os.path.join(self.GetBundleResourceFolder(), "Java")
|
339
|
+
|
340
|
+
def GetBundleFrameworksFolderPath(self):
|
341
|
+
"""Returns the qualified path to the bundle's frameworks folder. E.g,
|
342
|
+
Chromium.app/Contents/Frameworks. Only valid for bundles."""
|
343
|
+
assert self._IsBundle()
|
344
|
+
return os.path.join(self.GetBundleContentsFolderPath(), "Frameworks")
|
345
|
+
|
346
|
+
def GetBundleSharedFrameworksFolderPath(self):
|
347
|
+
"""Returns the qualified path to the bundle's frameworks folder. E.g,
|
348
|
+
Chromium.app/Contents/SharedFrameworks. Only valid for bundles."""
|
349
|
+
assert self._IsBundle()
|
350
|
+
return os.path.join(self.GetBundleContentsFolderPath(), "SharedFrameworks")
|
351
|
+
|
352
|
+
def GetBundleSharedSupportFolderPath(self):
|
353
|
+
"""Returns the qualified path to the bundle's shared support folder. E.g,
|
354
|
+
Chromium.app/Contents/SharedSupport. Only valid for bundles."""
|
355
|
+
assert self._IsBundle()
|
356
|
+
if self.spec["type"] == "shared_library":
|
357
|
+
return self.GetBundleResourceFolder()
|
358
|
+
else:
|
359
|
+
return os.path.join(self.GetBundleContentsFolderPath(), "SharedSupport")
|
360
|
+
|
361
|
+
def GetBundlePlugInsFolderPath(self):
|
362
|
+
"""Returns the qualified path to the bundle's plugins folder. E.g,
|
363
|
+
Chromium.app/Contents/PlugIns. Only valid for bundles."""
|
364
|
+
assert self._IsBundle()
|
365
|
+
return os.path.join(self.GetBundleContentsFolderPath(), "PlugIns")
|
366
|
+
|
367
|
+
def GetBundleXPCServicesFolderPath(self):
|
368
|
+
"""Returns the qualified path to the bundle's XPC services folder. E.g,
|
369
|
+
Chromium.app/Contents/XPCServices. Only valid for bundles."""
|
370
|
+
assert self._IsBundle()
|
371
|
+
return os.path.join(self.GetBundleContentsFolderPath(), "XPCServices")
|
372
|
+
|
373
|
+
def GetBundlePlistPath(self):
|
374
|
+
"""Returns the qualified path to the bundle's plist file. E.g.
|
375
|
+
Chromium.app/Contents/Info.plist. Only valid for bundles."""
|
376
|
+
assert self._IsBundle()
|
377
|
+
if (
|
378
|
+
self.spec["type"] in ("executable", "loadable_module")
|
379
|
+
or self.IsIosFramework()
|
380
|
+
):
|
381
|
+
return os.path.join(self.GetBundleContentsFolderPath(), "Info.plist")
|
382
|
+
else:
|
383
|
+
return os.path.join(
|
384
|
+
self.GetBundleContentsFolderPath(), "Resources", "Info.plist"
|
385
|
+
)
|
386
|
+
|
387
|
+
def GetProductType(self):
|
388
|
+
"""Returns the PRODUCT_TYPE of this target."""
|
389
|
+
if self._IsIosAppExtension():
|
390
|
+
assert self._IsBundle(), (
|
391
|
+
"ios_app_extension flag requires mac_bundle "
|
392
|
+
"(target %s)" % self.spec["target_name"]
|
393
|
+
)
|
394
|
+
return "com.apple.product-type.app-extension"
|
395
|
+
if self._IsIosWatchKitExtension():
|
396
|
+
assert self._IsBundle(), (
|
397
|
+
"ios_watchkit_extension flag requires "
|
398
|
+
"mac_bundle (target %s)" % self.spec["target_name"]
|
399
|
+
)
|
400
|
+
return "com.apple.product-type.watchkit-extension"
|
401
|
+
if self._IsIosWatchApp():
|
402
|
+
assert self._IsBundle(), (
|
403
|
+
"ios_watch_app flag requires mac_bundle "
|
404
|
+
"(target %s)" % self.spec["target_name"]
|
405
|
+
)
|
406
|
+
return "com.apple.product-type.application.watchapp"
|
407
|
+
if self._IsXCUiTest():
|
408
|
+
assert self._IsBundle(), (
|
409
|
+
"mac_xcuitest_bundle flag requires mac_bundle "
|
410
|
+
"(target %s)" % self.spec["target_name"]
|
411
|
+
)
|
412
|
+
return "com.apple.product-type.bundle.ui-testing"
|
413
|
+
if self._IsBundle():
|
414
|
+
return {
|
415
|
+
"executable": "com.apple.product-type.application",
|
416
|
+
"loadable_module": "com.apple.product-type.bundle",
|
417
|
+
"shared_library": "com.apple.product-type.framework",
|
418
|
+
}[self.spec["type"]]
|
419
|
+
else:
|
420
|
+
return {
|
421
|
+
"executable": "com.apple.product-type.tool",
|
422
|
+
"loadable_module": "com.apple.product-type.library.dynamic",
|
423
|
+
"shared_library": "com.apple.product-type.library.dynamic",
|
424
|
+
"static_library": "com.apple.product-type.library.static",
|
425
|
+
}[self.spec["type"]]
|
426
|
+
|
427
|
+
def GetMachOType(self):
|
428
|
+
"""Returns the MACH_O_TYPE of this target."""
|
429
|
+
# Weird, but matches Xcode.
|
430
|
+
if not self._IsBundle() and self.spec["type"] == "executable":
|
431
|
+
return ""
|
432
|
+
return {
|
433
|
+
"executable": "mh_execute",
|
434
|
+
"static_library": "staticlib",
|
435
|
+
"shared_library": "mh_dylib",
|
436
|
+
"loadable_module": "mh_bundle",
|
437
|
+
}[self.spec["type"]]
|
438
|
+
|
439
|
+
def _GetBundleBinaryPath(self):
|
440
|
+
"""Returns the name of the bundle binary of by this target.
|
441
|
+
E.g. Chromium.app/Contents/MacOS/Chromium. Only valid for bundles."""
|
442
|
+
assert self._IsBundle()
|
443
|
+
return os.path.join(
|
444
|
+
self.GetBundleExecutableFolderPath(), self.GetExecutableName()
|
445
|
+
)
|
446
|
+
|
447
|
+
def _GetStandaloneExecutableSuffix(self):
|
448
|
+
if "product_extension" in self.spec:
|
449
|
+
return "." + self.spec["product_extension"]
|
450
|
+
return {
|
451
|
+
"executable": "",
|
452
|
+
"static_library": ".a",
|
453
|
+
"shared_library": ".dylib",
|
454
|
+
"loadable_module": ".so",
|
455
|
+
}[self.spec["type"]]
|
456
|
+
|
457
|
+
def _GetStandaloneExecutablePrefix(self):
|
458
|
+
return self.spec.get(
|
459
|
+
"product_prefix",
|
460
|
+
{
|
461
|
+
"executable": "",
|
462
|
+
"static_library": "lib",
|
463
|
+
"shared_library": "lib",
|
464
|
+
# Non-bundled loadable_modules are called foo.so for some reason
|
465
|
+
# (that is, .so and no prefix) with the xcode build -- match that.
|
466
|
+
"loadable_module": "",
|
467
|
+
}[self.spec["type"]],
|
468
|
+
)
|
469
|
+
|
470
|
+
def _GetStandaloneBinaryPath(self):
|
471
|
+
"""Returns the name of the non-bundle binary represented by this target.
|
472
|
+
E.g. hello_world. Only valid for non-bundles."""
|
473
|
+
assert not self._IsBundle()
|
474
|
+
assert self.spec["type"] in (
|
475
|
+
"executable",
|
476
|
+
"shared_library",
|
477
|
+
"static_library",
|
478
|
+
"loadable_module",
|
479
|
+
), ("Unexpected type %s" % self.spec["type"])
|
480
|
+
target = self.spec["target_name"]
|
481
|
+
if self.spec["type"] == "static_library":
|
482
|
+
if target[:3] == "lib":
|
483
|
+
target = target[3:]
|
484
|
+
elif self.spec["type"] in ("loadable_module", "shared_library"):
|
485
|
+
if target[:3] == "lib":
|
486
|
+
target = target[3:]
|
487
|
+
|
488
|
+
target_prefix = self._GetStandaloneExecutablePrefix()
|
489
|
+
target = self.spec.get("product_name", target)
|
490
|
+
target_ext = self._GetStandaloneExecutableSuffix()
|
491
|
+
return target_prefix + target + target_ext
|
492
|
+
|
493
|
+
def GetExecutableName(self):
|
494
|
+
"""Returns the executable name of the bundle represented by this target.
|
495
|
+
E.g. Chromium."""
|
496
|
+
if self._IsBundle():
|
497
|
+
return self.spec.get("product_name", self.spec["target_name"])
|
498
|
+
else:
|
499
|
+
return self._GetStandaloneBinaryPath()
|
500
|
+
|
501
|
+
def GetExecutablePath(self):
|
502
|
+
"""Returns the qualified path to the primary executable of the bundle
|
503
|
+
represented by this target. E.g. Chromium.app/Contents/MacOS/Chromium."""
|
504
|
+
if self._IsBundle():
|
505
|
+
return self._GetBundleBinaryPath()
|
506
|
+
else:
|
507
|
+
return self._GetStandaloneBinaryPath()
|
508
|
+
|
509
|
+
def GetActiveArchs(self, configname):
|
510
|
+
"""Returns the architectures this target should be built for."""
|
511
|
+
config_settings = self.xcode_settings[configname]
|
512
|
+
xcode_archs_default = GetXcodeArchsDefault()
|
513
|
+
return xcode_archs_default.ActiveArchs(
|
514
|
+
config_settings.get("ARCHS"),
|
515
|
+
config_settings.get("VALID_ARCHS"),
|
516
|
+
config_settings.get("SDKROOT"),
|
517
|
+
)
|
518
|
+
|
519
|
+
def _GetSdkVersionInfoItem(self, sdk, infoitem):
|
520
|
+
# xcodebuild requires Xcode and can't run on Command Line Tools-only
|
521
|
+
# systems from 10.7 onward.
|
522
|
+
# Since the CLT has no SDK paths anyway, returning None is the
|
523
|
+
# most sensible route and should still do the right thing.
|
524
|
+
try:
|
525
|
+
return GetStdoutQuiet(["xcrun", "--sdk", sdk, infoitem])
|
526
|
+
except GypError:
|
527
|
+
pass
|
528
|
+
|
529
|
+
def _SdkRoot(self, configname):
|
530
|
+
if configname is None:
|
531
|
+
configname = self.configname
|
532
|
+
return self.GetPerConfigSetting("SDKROOT", configname, default="")
|
533
|
+
|
534
|
+
def _XcodePlatformPath(self, configname=None):
|
535
|
+
sdk_root = self._SdkRoot(configname)
|
536
|
+
if sdk_root not in XcodeSettings._platform_path_cache:
|
537
|
+
platform_path = self._GetSdkVersionInfoItem(
|
538
|
+
sdk_root, "--show-sdk-platform-path"
|
539
|
+
)
|
540
|
+
XcodeSettings._platform_path_cache[sdk_root] = platform_path
|
541
|
+
return XcodeSettings._platform_path_cache[sdk_root]
|
542
|
+
|
543
|
+
def _SdkPath(self, configname=None):
|
544
|
+
sdk_root = self._SdkRoot(configname)
|
545
|
+
if sdk_root.startswith("/"):
|
546
|
+
return sdk_root
|
547
|
+
return self._XcodeSdkPath(sdk_root)
|
548
|
+
|
549
|
+
def _XcodeSdkPath(self, sdk_root):
|
550
|
+
if sdk_root not in XcodeSettings._sdk_path_cache:
|
551
|
+
sdk_path = self._GetSdkVersionInfoItem(sdk_root, "--show-sdk-path")
|
552
|
+
XcodeSettings._sdk_path_cache[sdk_root] = sdk_path
|
553
|
+
if sdk_root:
|
554
|
+
XcodeSettings._sdk_root_cache[sdk_path] = sdk_root
|
555
|
+
return XcodeSettings._sdk_path_cache[sdk_root]
|
556
|
+
|
557
|
+
def _AppendPlatformVersionMinFlags(self, lst):
|
558
|
+
self._Appendf(lst, "MACOSX_DEPLOYMENT_TARGET", "-mmacosx-version-min=%s")
|
559
|
+
if "IPHONEOS_DEPLOYMENT_TARGET" in self._Settings():
|
560
|
+
# TODO: Implement this better?
|
561
|
+
sdk_path_basename = os.path.basename(self._SdkPath())
|
562
|
+
if sdk_path_basename.lower().startswith("iphonesimulator"):
|
563
|
+
self._Appendf(
|
564
|
+
lst, "IPHONEOS_DEPLOYMENT_TARGET", "-mios-simulator-version-min=%s"
|
565
|
+
)
|
566
|
+
else:
|
567
|
+
self._Appendf(
|
568
|
+
lst, "IPHONEOS_DEPLOYMENT_TARGET", "-miphoneos-version-min=%s"
|
569
|
+
)
|
570
|
+
|
571
|
+
def GetCflags(self, configname, arch=None):
|
572
|
+
"""Returns flags that need to be added to .c, .cc, .m, and .mm
|
573
|
+
compilations."""
|
574
|
+
# This functions (and the similar ones below) do not offer complete
|
575
|
+
# emulation of all xcode_settings keys. They're implemented on demand.
|
576
|
+
|
577
|
+
self.configname = configname
|
578
|
+
cflags = []
|
579
|
+
|
580
|
+
sdk_root = self._SdkPath()
|
581
|
+
if "SDKROOT" in self._Settings() and sdk_root:
|
582
|
+
cflags.append("-isysroot %s" % sdk_root)
|
583
|
+
|
584
|
+
if self.header_map_path:
|
585
|
+
cflags.append("-I%s" % self.header_map_path)
|
586
|
+
|
587
|
+
if self._Test("CLANG_WARN_CONSTANT_CONVERSION", "YES", default="NO"):
|
588
|
+
cflags.append("-Wconstant-conversion")
|
589
|
+
|
590
|
+
if self._Test("GCC_CHAR_IS_UNSIGNED_CHAR", "YES", default="NO"):
|
591
|
+
cflags.append("-funsigned-char")
|
592
|
+
|
593
|
+
if self._Test("GCC_CW_ASM_SYNTAX", "YES", default="YES"):
|
594
|
+
cflags.append("-fasm-blocks")
|
595
|
+
|
596
|
+
if "GCC_DYNAMIC_NO_PIC" in self._Settings():
|
597
|
+
if self._Settings()["GCC_DYNAMIC_NO_PIC"] == "YES":
|
598
|
+
cflags.append("-mdynamic-no-pic")
|
599
|
+
else:
|
600
|
+
pass
|
601
|
+
# TODO: In this case, it depends on the target. xcode passes
|
602
|
+
# mdynamic-no-pic by default for executable and possibly static lib
|
603
|
+
# according to mento
|
604
|
+
|
605
|
+
if self._Test("GCC_ENABLE_PASCAL_STRINGS", "YES", default="YES"):
|
606
|
+
cflags.append("-mpascal-strings")
|
607
|
+
|
608
|
+
self._Appendf(cflags, "GCC_OPTIMIZATION_LEVEL", "-O%s", default="s")
|
609
|
+
|
610
|
+
if self._Test("GCC_GENERATE_DEBUGGING_SYMBOLS", "YES", default="YES"):
|
611
|
+
dbg_format = self._Settings().get("DEBUG_INFORMATION_FORMAT", "dwarf")
|
612
|
+
if dbg_format == "dwarf":
|
613
|
+
cflags.append("-gdwarf-2")
|
614
|
+
elif dbg_format == "stabs":
|
615
|
+
raise NotImplementedError("stabs debug format is not supported yet.")
|
616
|
+
elif dbg_format == "dwarf-with-dsym":
|
617
|
+
cflags.append("-gdwarf-2")
|
618
|
+
else:
|
619
|
+
raise NotImplementedError("Unknown debug format %s" % dbg_format)
|
620
|
+
|
621
|
+
if self._Settings().get("GCC_STRICT_ALIASING") == "YES":
|
622
|
+
cflags.append("-fstrict-aliasing")
|
623
|
+
elif self._Settings().get("GCC_STRICT_ALIASING") == "NO":
|
624
|
+
cflags.append("-fno-strict-aliasing")
|
625
|
+
|
626
|
+
if self._Test("GCC_SYMBOLS_PRIVATE_EXTERN", "YES", default="NO"):
|
627
|
+
cflags.append("-fvisibility=hidden")
|
628
|
+
|
629
|
+
if self._Test("GCC_TREAT_WARNINGS_AS_ERRORS", "YES", default="NO"):
|
630
|
+
cflags.append("-Werror")
|
631
|
+
|
632
|
+
if self._Test("GCC_WARN_ABOUT_MISSING_NEWLINE", "YES", default="NO"):
|
633
|
+
cflags.append("-Wnewline-eof")
|
634
|
+
|
635
|
+
# In Xcode, this is only activated when GCC_COMPILER_VERSION is clang or
|
636
|
+
# llvm-gcc. It also requires a fairly recent libtool, and
|
637
|
+
# if the system clang isn't used, DYLD_LIBRARY_PATH needs to contain the
|
638
|
+
# path to the libLTO.dylib that matches the used clang.
|
639
|
+
if self._Test("LLVM_LTO", "YES", default="NO"):
|
640
|
+
cflags.append("-flto")
|
641
|
+
|
642
|
+
self._AppendPlatformVersionMinFlags(cflags)
|
643
|
+
|
644
|
+
# TODO:
|
645
|
+
if self._Test("COPY_PHASE_STRIP", "YES", default="NO"):
|
646
|
+
self._WarnUnimplemented("COPY_PHASE_STRIP")
|
647
|
+
self._WarnUnimplemented("GCC_DEBUGGING_SYMBOLS")
|
648
|
+
self._WarnUnimplemented("GCC_ENABLE_OBJC_EXCEPTIONS")
|
649
|
+
|
650
|
+
# TODO: This is exported correctly, but assigning to it is not supported.
|
651
|
+
self._WarnUnimplemented("MACH_O_TYPE")
|
652
|
+
self._WarnUnimplemented("PRODUCT_TYPE")
|
653
|
+
|
654
|
+
# If GYP_CROSSCOMPILE (--cross-compiling), disable architecture-specific
|
655
|
+
# additions and assume these will be provided as required via CC_host,
|
656
|
+
# CXX_host, CC_target and CXX_target.
|
657
|
+
if not gyp.common.CrossCompileRequested():
|
658
|
+
if arch is not None:
|
659
|
+
archs = [arch]
|
660
|
+
else:
|
661
|
+
assert self.configname
|
662
|
+
archs = self.GetActiveArchs(self.configname)
|
663
|
+
if len(archs) != 1:
|
664
|
+
# TODO: Supporting fat binaries will be annoying.
|
665
|
+
self._WarnUnimplemented("ARCHS")
|
666
|
+
archs = ["i386"]
|
667
|
+
cflags.append("-arch " + archs[0])
|
668
|
+
|
669
|
+
if archs[0] in ("i386", "x86_64"):
|
670
|
+
if self._Test("GCC_ENABLE_SSE3_EXTENSIONS", "YES", default="NO"):
|
671
|
+
cflags.append("-msse3")
|
672
|
+
if self._Test(
|
673
|
+
"GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS", "YES", default="NO"
|
674
|
+
):
|
675
|
+
cflags.append("-mssse3") # Note 3rd 's'.
|
676
|
+
if self._Test("GCC_ENABLE_SSE41_EXTENSIONS", "YES", default="NO"):
|
677
|
+
cflags.append("-msse4.1")
|
678
|
+
if self._Test("GCC_ENABLE_SSE42_EXTENSIONS", "YES", default="NO"):
|
679
|
+
cflags.append("-msse4.2")
|
680
|
+
|
681
|
+
cflags += self._Settings().get("WARNING_CFLAGS", [])
|
682
|
+
|
683
|
+
if self._IsXCTest():
|
684
|
+
platform_root = self._XcodePlatformPath(configname)
|
685
|
+
if platform_root:
|
686
|
+
cflags.append("-F" + platform_root + "/Developer/Library/Frameworks/")
|
687
|
+
|
688
|
+
if sdk_root:
|
689
|
+
framework_root = sdk_root
|
690
|
+
else:
|
691
|
+
framework_root = ""
|
692
|
+
config = self.spec["configurations"][self.configname]
|
693
|
+
framework_dirs = config.get("mac_framework_dirs", [])
|
694
|
+
for directory in framework_dirs:
|
695
|
+
cflags.append("-F" + directory.replace("$(SDKROOT)", framework_root))
|
696
|
+
|
697
|
+
self.configname = None
|
698
|
+
return cflags
|
699
|
+
|
700
|
+
def GetCflagsC(self, configname):
|
701
|
+
"""Returns flags that need to be added to .c, and .m compilations."""
|
702
|
+
self.configname = configname
|
703
|
+
cflags_c = []
|
704
|
+
if self._Settings().get("GCC_C_LANGUAGE_STANDARD", "") == "ansi":
|
705
|
+
cflags_c.append("-ansi")
|
706
|
+
else:
|
707
|
+
self._Appendf(cflags_c, "GCC_C_LANGUAGE_STANDARD", "-std=%s")
|
708
|
+
cflags_c += self._Settings().get("OTHER_CFLAGS", [])
|
709
|
+
self.configname = None
|
710
|
+
return cflags_c
|
711
|
+
|
712
|
+
def GetCflagsCC(self, configname):
|
713
|
+
"""Returns flags that need to be added to .cc, and .mm compilations."""
|
714
|
+
self.configname = configname
|
715
|
+
cflags_cc = []
|
716
|
+
|
717
|
+
clang_cxx_language_standard = self._Settings().get(
|
718
|
+
"CLANG_CXX_LANGUAGE_STANDARD"
|
719
|
+
)
|
720
|
+
# Note: Don't make c++0x to c++11 so that c++0x can be used with older
|
721
|
+
# clangs that don't understand c++11 yet (like Xcode 4.2's).
|
722
|
+
if clang_cxx_language_standard:
|
723
|
+
cflags_cc.append("-std=%s" % clang_cxx_language_standard)
|
724
|
+
|
725
|
+
self._Appendf(cflags_cc, "CLANG_CXX_LIBRARY", "-stdlib=%s")
|
726
|
+
|
727
|
+
if self._Test("GCC_ENABLE_CPP_RTTI", "NO", default="YES"):
|
728
|
+
cflags_cc.append("-fno-rtti")
|
729
|
+
if self._Test("GCC_ENABLE_CPP_EXCEPTIONS", "NO", default="YES"):
|
730
|
+
cflags_cc.append("-fno-exceptions")
|
731
|
+
if self._Test("GCC_INLINES_ARE_PRIVATE_EXTERN", "YES", default="NO"):
|
732
|
+
cflags_cc.append("-fvisibility-inlines-hidden")
|
733
|
+
if self._Test("GCC_THREADSAFE_STATICS", "NO", default="YES"):
|
734
|
+
cflags_cc.append("-fno-threadsafe-statics")
|
735
|
+
# Note: This flag is a no-op for clang, it only has an effect for gcc.
|
736
|
+
if self._Test("GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO", "NO", default="YES"):
|
737
|
+
cflags_cc.append("-Wno-invalid-offsetof")
|
738
|
+
|
739
|
+
other_ccflags = []
|
740
|
+
|
741
|
+
for flag in self._Settings().get("OTHER_CPLUSPLUSFLAGS", ["$(inherited)"]):
|
742
|
+
# TODO: More general variable expansion. Missing in many other places too.
|
743
|
+
if flag in ("$inherited", "$(inherited)", "${inherited}"):
|
744
|
+
flag = "$OTHER_CFLAGS"
|
745
|
+
if flag in ("$OTHER_CFLAGS", "$(OTHER_CFLAGS)", "${OTHER_CFLAGS}"):
|
746
|
+
other_ccflags += self._Settings().get("OTHER_CFLAGS", [])
|
747
|
+
else:
|
748
|
+
other_ccflags.append(flag)
|
749
|
+
cflags_cc += other_ccflags
|
750
|
+
|
751
|
+
self.configname = None
|
752
|
+
return cflags_cc
|
753
|
+
|
754
|
+
def _AddObjectiveCGarbageCollectionFlags(self, flags):
|
755
|
+
gc_policy = self._Settings().get("GCC_ENABLE_OBJC_GC", "unsupported")
|
756
|
+
if gc_policy == "supported":
|
757
|
+
flags.append("-fobjc-gc")
|
758
|
+
elif gc_policy == "required":
|
759
|
+
flags.append("-fobjc-gc-only")
|
760
|
+
|
761
|
+
def _AddObjectiveCARCFlags(self, flags):
|
762
|
+
if self._Test("CLANG_ENABLE_OBJC_ARC", "YES", default="NO"):
|
763
|
+
flags.append("-fobjc-arc")
|
764
|
+
|
765
|
+
def _AddObjectiveCMissingPropertySynthesisFlags(self, flags):
|
766
|
+
if self._Test(
|
767
|
+
"CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS", "YES", default="NO"
|
768
|
+
):
|
769
|
+
flags.append("-Wobjc-missing-property-synthesis")
|
770
|
+
|
771
|
+
def GetCflagsObjC(self, configname):
|
772
|
+
"""Returns flags that need to be added to .m compilations."""
|
773
|
+
self.configname = configname
|
774
|
+
cflags_objc = []
|
775
|
+
self._AddObjectiveCGarbageCollectionFlags(cflags_objc)
|
776
|
+
self._AddObjectiveCARCFlags(cflags_objc)
|
777
|
+
self._AddObjectiveCMissingPropertySynthesisFlags(cflags_objc)
|
778
|
+
self.configname = None
|
779
|
+
return cflags_objc
|
780
|
+
|
781
|
+
def GetCflagsObjCC(self, configname):
|
782
|
+
"""Returns flags that need to be added to .mm compilations."""
|
783
|
+
self.configname = configname
|
784
|
+
cflags_objcc = []
|
785
|
+
self._AddObjectiveCGarbageCollectionFlags(cflags_objcc)
|
786
|
+
self._AddObjectiveCARCFlags(cflags_objcc)
|
787
|
+
self._AddObjectiveCMissingPropertySynthesisFlags(cflags_objcc)
|
788
|
+
if self._Test("GCC_OBJC_CALL_CXX_CDTORS", "YES", default="NO"):
|
789
|
+
cflags_objcc.append("-fobjc-call-cxx-cdtors")
|
790
|
+
self.configname = None
|
791
|
+
return cflags_objcc
|
792
|
+
|
793
|
+
def GetInstallNameBase(self):
|
794
|
+
"""Return DYLIB_INSTALL_NAME_BASE for this target."""
|
795
|
+
# Xcode sets this for shared_libraries, and for nonbundled loadable_modules.
|
796
|
+
if self.spec["type"] != "shared_library" and (
|
797
|
+
self.spec["type"] != "loadable_module" or self._IsBundle()
|
798
|
+
):
|
799
|
+
return None
|
800
|
+
install_base = self.GetPerTargetSetting(
|
801
|
+
"DYLIB_INSTALL_NAME_BASE",
|
802
|
+
default="/Library/Frameworks" if self._IsBundle() else "/usr/local/lib",
|
803
|
+
)
|
804
|
+
return install_base
|
805
|
+
|
806
|
+
def _StandardizePath(self, path):
|
807
|
+
"""Do :standardizepath processing for path."""
|
808
|
+
# I'm not quite sure what :standardizepath does. Just call normpath(),
|
809
|
+
# but don't let @executable_path/../foo collapse to foo.
|
810
|
+
if "/" in path:
|
811
|
+
prefix, rest = "", path
|
812
|
+
if path.startswith("@"):
|
813
|
+
prefix, rest = path.split("/", 1)
|
814
|
+
rest = os.path.normpath(rest) # :standardizepath
|
815
|
+
path = os.path.join(prefix, rest)
|
816
|
+
return path
|
817
|
+
|
818
|
+
def GetInstallName(self):
|
819
|
+
"""Return LD_DYLIB_INSTALL_NAME for this target."""
|
820
|
+
# Xcode sets this for shared_libraries, and for nonbundled loadable_modules.
|
821
|
+
if self.spec["type"] != "shared_library" and (
|
822
|
+
self.spec["type"] != "loadable_module" or self._IsBundle()
|
823
|
+
):
|
824
|
+
return None
|
825
|
+
|
826
|
+
default_install_name = (
|
827
|
+
"$(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH)"
|
828
|
+
)
|
829
|
+
install_name = self.GetPerTargetSetting(
|
830
|
+
"LD_DYLIB_INSTALL_NAME", default=default_install_name
|
831
|
+
)
|
832
|
+
|
833
|
+
# Hardcode support for the variables used in chromium for now, to
|
834
|
+
# unblock people using the make build.
|
835
|
+
if "$" in install_name:
|
836
|
+
assert install_name in (
|
837
|
+
"$(DYLIB_INSTALL_NAME_BASE:standardizepath)/"
|
838
|
+
"$(WRAPPER_NAME)/$(PRODUCT_NAME)",
|
839
|
+
default_install_name,
|
840
|
+
), (
|
841
|
+
"Variables in LD_DYLIB_INSTALL_NAME are not generally supported "
|
842
|
+
"yet in target '%s' (got '%s')"
|
843
|
+
% (self.spec["target_name"], install_name)
|
844
|
+
)
|
845
|
+
|
846
|
+
install_name = install_name.replace(
|
847
|
+
"$(DYLIB_INSTALL_NAME_BASE:standardizepath)",
|
848
|
+
self._StandardizePath(self.GetInstallNameBase()),
|
849
|
+
)
|
850
|
+
if self._IsBundle():
|
851
|
+
# These are only valid for bundles, hence the |if|.
|
852
|
+
install_name = install_name.replace(
|
853
|
+
"$(WRAPPER_NAME)", self.GetWrapperName()
|
854
|
+
)
|
855
|
+
install_name = install_name.replace(
|
856
|
+
"$(PRODUCT_NAME)", self.GetProductName()
|
857
|
+
)
|
858
|
+
else:
|
859
|
+
assert "$(WRAPPER_NAME)" not in install_name
|
860
|
+
assert "$(PRODUCT_NAME)" not in install_name
|
861
|
+
|
862
|
+
install_name = install_name.replace(
|
863
|
+
"$(EXECUTABLE_PATH)", self.GetExecutablePath()
|
864
|
+
)
|
865
|
+
return install_name
|
866
|
+
|
867
|
+
def _MapLinkerFlagFilename(self, ldflag, gyp_to_build_path):
|
868
|
+
"""Checks if ldflag contains a filename and if so remaps it from
|
869
|
+
gyp-directory-relative to build-directory-relative."""
|
870
|
+
# This list is expanded on demand.
|
871
|
+
# They get matched as:
|
872
|
+
# -exported_symbols_list file
|
873
|
+
# -Wl,exported_symbols_list file
|
874
|
+
# -Wl,exported_symbols_list,file
|
875
|
+
LINKER_FILE = r"(\S+)"
|
876
|
+
WORD = r"\S+"
|
877
|
+
linker_flags = [
|
878
|
+
["-exported_symbols_list", LINKER_FILE], # Needed for NaCl.
|
879
|
+
["-unexported_symbols_list", LINKER_FILE],
|
880
|
+
["-reexported_symbols_list", LINKER_FILE],
|
881
|
+
["-sectcreate", WORD, WORD, LINKER_FILE], # Needed for remoting.
|
882
|
+
]
|
883
|
+
for flag_pattern in linker_flags:
|
884
|
+
regex = re.compile("(?:-Wl,)?" + "[ ,]".join(flag_pattern))
|
885
|
+
m = regex.match(ldflag)
|
886
|
+
if m:
|
887
|
+
ldflag = (
|
888
|
+
ldflag[: m.start(1)]
|
889
|
+
+ gyp_to_build_path(m.group(1))
|
890
|
+
+ ldflag[m.end(1) :]
|
891
|
+
)
|
892
|
+
# Required for ffmpeg (no idea why they don't use LIBRARY_SEARCH_PATHS,
|
893
|
+
# TODO(thakis): Update ffmpeg.gyp):
|
894
|
+
if ldflag.startswith("-L"):
|
895
|
+
ldflag = "-L" + gyp_to_build_path(ldflag[len("-L") :])
|
896
|
+
return ldflag
|
897
|
+
|
898
|
+
def GetLdflags(self, configname, product_dir, gyp_to_build_path, arch=None):
|
899
|
+
"""Returns flags that need to be passed to the linker.
|
900
|
+
|
901
|
+
Args:
|
902
|
+
configname: The name of the configuration to get ld flags for.
|
903
|
+
product_dir: The directory where products such static and dynamic
|
904
|
+
libraries are placed. This is added to the library search path.
|
905
|
+
gyp_to_build_path: A function that converts paths relative to the
|
906
|
+
current gyp file to paths relative to the build directory.
|
907
|
+
"""
|
908
|
+
self.configname = configname
|
909
|
+
ldflags = []
|
910
|
+
|
911
|
+
# The xcode build is relative to a gyp file's directory, and OTHER_LDFLAGS
|
912
|
+
# can contain entries that depend on this. Explicitly absolutify these.
|
913
|
+
for ldflag in self._Settings().get("OTHER_LDFLAGS", []):
|
914
|
+
ldflags.append(self._MapLinkerFlagFilename(ldflag, gyp_to_build_path))
|
915
|
+
|
916
|
+
if self._Test("DEAD_CODE_STRIPPING", "YES", default="NO"):
|
917
|
+
ldflags.append("-Wl,-dead_strip")
|
918
|
+
|
919
|
+
if self._Test("PREBINDING", "YES", default="NO"):
|
920
|
+
ldflags.append("-Wl,-prebind")
|
921
|
+
|
922
|
+
self._Appendf(
|
923
|
+
ldflags, "DYLIB_COMPATIBILITY_VERSION", "-compatibility_version %s"
|
924
|
+
)
|
925
|
+
self._Appendf(ldflags, "DYLIB_CURRENT_VERSION", "-current_version %s")
|
926
|
+
|
927
|
+
self._AppendPlatformVersionMinFlags(ldflags)
|
928
|
+
|
929
|
+
if "SDKROOT" in self._Settings() and self._SdkPath():
|
930
|
+
ldflags.append("-isysroot " + self._SdkPath())
|
931
|
+
|
932
|
+
for library_path in self._Settings().get("LIBRARY_SEARCH_PATHS", []):
|
933
|
+
ldflags.append("-L" + gyp_to_build_path(library_path))
|
934
|
+
|
935
|
+
if "ORDER_FILE" in self._Settings():
|
936
|
+
ldflags.append(
|
937
|
+
"-Wl,-order_file "
|
938
|
+
+ "-Wl,"
|
939
|
+
+ gyp_to_build_path(self._Settings()["ORDER_FILE"])
|
940
|
+
)
|
941
|
+
|
942
|
+
if not gyp.common.CrossCompileRequested():
|
943
|
+
if arch is not None:
|
944
|
+
archs = [arch]
|
945
|
+
else:
|
946
|
+
assert self.configname
|
947
|
+
archs = self.GetActiveArchs(self.configname)
|
948
|
+
if len(archs) != 1:
|
949
|
+
# TODO: Supporting fat binaries will be annoying.
|
950
|
+
self._WarnUnimplemented("ARCHS")
|
951
|
+
archs = ["i386"]
|
952
|
+
ldflags.append("-arch " + archs[0])
|
953
|
+
|
954
|
+
# Xcode adds the product directory by default.
|
955
|
+
# Rewrite -L. to -L./ to work around http://www.openradar.me/25313838
|
956
|
+
ldflags.append("-L" + (product_dir if product_dir != "." else "./"))
|
957
|
+
|
958
|
+
install_name = self.GetInstallName()
|
959
|
+
if install_name and self.spec["type"] != "loadable_module":
|
960
|
+
ldflags.append("-install_name " + install_name.replace(" ", r"\ "))
|
961
|
+
|
962
|
+
for rpath in self._Settings().get("LD_RUNPATH_SEARCH_PATHS", []):
|
963
|
+
ldflags.append("-Wl,-rpath," + rpath)
|
964
|
+
|
965
|
+
sdk_root = self._SdkPath()
|
966
|
+
if not sdk_root:
|
967
|
+
sdk_root = ""
|
968
|
+
config = self.spec["configurations"][self.configname]
|
969
|
+
framework_dirs = config.get("mac_framework_dirs", [])
|
970
|
+
for directory in framework_dirs:
|
971
|
+
ldflags.append("-F" + directory.replace("$(SDKROOT)", sdk_root))
|
972
|
+
|
973
|
+
if self._IsXCTest():
|
974
|
+
platform_root = self._XcodePlatformPath(configname)
|
975
|
+
if sdk_root and platform_root:
|
976
|
+
ldflags.append("-F" + platform_root + "/Developer/Library/Frameworks/")
|
977
|
+
ldflags.append("-framework XCTest")
|
978
|
+
|
979
|
+
is_extension = self._IsIosAppExtension() or self._IsIosWatchKitExtension()
|
980
|
+
if sdk_root and is_extension:
|
981
|
+
# Adds the link flags for extensions. These flags are common for all
|
982
|
+
# extensions and provide loader and main function.
|
983
|
+
# These flags reflect the compilation options used by xcode to compile
|
984
|
+
# extensions.
|
985
|
+
xcode_version, _ = XcodeVersion()
|
986
|
+
if xcode_version < "0900":
|
987
|
+
ldflags.append("-lpkstart")
|
988
|
+
ldflags.append(
|
989
|
+
sdk_root
|
990
|
+
+ "/System/Library/PrivateFrameworks/PlugInKit.framework/PlugInKit"
|
991
|
+
)
|
992
|
+
else:
|
993
|
+
ldflags.append("-e _NSExtensionMain")
|
994
|
+
ldflags.append("-fapplication-extension")
|
995
|
+
|
996
|
+
self._Appendf(ldflags, "CLANG_CXX_LIBRARY", "-stdlib=%s")
|
997
|
+
|
998
|
+
self.configname = None
|
999
|
+
return ldflags
|
1000
|
+
|
1001
|
+
def GetLibtoolflags(self, configname):
|
1002
|
+
"""Returns flags that need to be passed to the static linker.
|
1003
|
+
|
1004
|
+
Args:
|
1005
|
+
configname: The name of the configuration to get ld flags for.
|
1006
|
+
"""
|
1007
|
+
self.configname = configname
|
1008
|
+
libtoolflags = []
|
1009
|
+
|
1010
|
+
for libtoolflag in self._Settings().get("OTHER_LDFLAGS", []):
|
1011
|
+
libtoolflags.append(libtoolflag)
|
1012
|
+
# TODO(thakis): ARCHS?
|
1013
|
+
|
1014
|
+
self.configname = None
|
1015
|
+
return libtoolflags
|
1016
|
+
|
1017
|
+
def GetPerTargetSettings(self):
|
1018
|
+
"""Gets a list of all the per-target settings. This will only fetch keys
|
1019
|
+
whose values are the same across all configurations."""
|
1020
|
+
first_pass = True
|
1021
|
+
result = {}
|
1022
|
+
for configname in sorted(self.xcode_settings.keys()):
|
1023
|
+
if first_pass:
|
1024
|
+
result = dict(self.xcode_settings[configname])
|
1025
|
+
first_pass = False
|
1026
|
+
else:
|
1027
|
+
for key, value in self.xcode_settings[configname].items():
|
1028
|
+
if key not in result:
|
1029
|
+
continue
|
1030
|
+
elif result[key] != value:
|
1031
|
+
del result[key]
|
1032
|
+
return result
|
1033
|
+
|
1034
|
+
def GetPerConfigSetting(self, setting, configname, default=None):
|
1035
|
+
if configname in self.xcode_settings:
|
1036
|
+
return self.xcode_settings[configname].get(setting, default)
|
1037
|
+
else:
|
1038
|
+
return self.GetPerTargetSetting(setting, default)
|
1039
|
+
|
1040
|
+
def GetPerTargetSetting(self, setting, default=None):
|
1041
|
+
"""Tries to get xcode_settings.setting from spec. Assumes that the setting
|
1042
|
+
has the same value in all configurations and throws otherwise."""
|
1043
|
+
is_first_pass = True
|
1044
|
+
result = None
|
1045
|
+
for configname in sorted(self.xcode_settings.keys()):
|
1046
|
+
if is_first_pass:
|
1047
|
+
result = self.xcode_settings[configname].get(setting, None)
|
1048
|
+
is_first_pass = False
|
1049
|
+
else:
|
1050
|
+
assert result == self.xcode_settings[configname].get(setting, None), (
|
1051
|
+
"Expected per-target setting for '%s', got per-config setting "
|
1052
|
+
"(target %s)" % (setting, self.spec["target_name"])
|
1053
|
+
)
|
1054
|
+
if result is None:
|
1055
|
+
return default
|
1056
|
+
return result
|
1057
|
+
|
1058
|
+
def _GetStripPostbuilds(self, configname, output_binary, quiet):
|
1059
|
+
"""Returns a list of shell commands that contain the shell commands
|
1060
|
+
necessary to strip this target's binary. These should be run as postbuilds
|
1061
|
+
before the actual postbuilds run."""
|
1062
|
+
self.configname = configname
|
1063
|
+
|
1064
|
+
result = []
|
1065
|
+
if self._Test("DEPLOYMENT_POSTPROCESSING", "YES", default="NO") and self._Test(
|
1066
|
+
"STRIP_INSTALLED_PRODUCT", "YES", default="NO"
|
1067
|
+
):
|
1068
|
+
|
1069
|
+
default_strip_style = "debugging"
|
1070
|
+
if (
|
1071
|
+
self.spec["type"] == "loadable_module" or self._IsIosAppExtension()
|
1072
|
+
) and self._IsBundle():
|
1073
|
+
default_strip_style = "non-global"
|
1074
|
+
elif self.spec["type"] == "executable":
|
1075
|
+
default_strip_style = "all"
|
1076
|
+
|
1077
|
+
strip_style = self._Settings().get("STRIP_STYLE", default_strip_style)
|
1078
|
+
strip_flags = {"all": "", "non-global": "-x", "debugging": "-S"}[
|
1079
|
+
strip_style
|
1080
|
+
]
|
1081
|
+
|
1082
|
+
explicit_strip_flags = self._Settings().get("STRIPFLAGS", "")
|
1083
|
+
if explicit_strip_flags:
|
1084
|
+
strip_flags += " " + _NormalizeEnvVarReferences(explicit_strip_flags)
|
1085
|
+
|
1086
|
+
if not quiet:
|
1087
|
+
result.append("echo STRIP\\(%s\\)" % self.spec["target_name"])
|
1088
|
+
result.append(f"strip {strip_flags} {output_binary}")
|
1089
|
+
|
1090
|
+
self.configname = None
|
1091
|
+
return result
|
1092
|
+
|
1093
|
+
def _GetDebugInfoPostbuilds(self, configname, output, output_binary, quiet):
|
1094
|
+
"""Returns a list of shell commands that contain the shell commands
|
1095
|
+
necessary to massage this target's debug information. These should be run
|
1096
|
+
as postbuilds before the actual postbuilds run."""
|
1097
|
+
self.configname = configname
|
1098
|
+
|
1099
|
+
# For static libraries, no dSYMs are created.
|
1100
|
+
result = []
|
1101
|
+
if (
|
1102
|
+
self._Test("GCC_GENERATE_DEBUGGING_SYMBOLS", "YES", default="YES")
|
1103
|
+
and self._Test(
|
1104
|
+
"DEBUG_INFORMATION_FORMAT", "dwarf-with-dsym", default="dwarf"
|
1105
|
+
)
|
1106
|
+
and self.spec["type"] != "static_library"
|
1107
|
+
):
|
1108
|
+
if not quiet:
|
1109
|
+
result.append("echo DSYMUTIL\\(%s\\)" % self.spec["target_name"])
|
1110
|
+
result.append("dsymutil {} -o {}".format(output_binary, output + ".dSYM"))
|
1111
|
+
|
1112
|
+
self.configname = None
|
1113
|
+
return result
|
1114
|
+
|
1115
|
+
def _GetTargetPostbuilds(self, configname, output, output_binary, quiet=False):
|
1116
|
+
"""Returns a list of shell commands that contain the shell commands
|
1117
|
+
to run as postbuilds for this target, before the actual postbuilds."""
|
1118
|
+
# dSYMs need to build before stripping happens.
|
1119
|
+
return self._GetDebugInfoPostbuilds(
|
1120
|
+
configname, output, output_binary, quiet
|
1121
|
+
) + self._GetStripPostbuilds(configname, output_binary, quiet)
|
1122
|
+
|
1123
|
+
def _GetIOSPostbuilds(self, configname, output_binary):
|
1124
|
+
"""Return a shell command to codesign the iOS output binary so it can
|
1125
|
+
be deployed to a device. This should be run as the very last step of the
|
1126
|
+
build."""
|
1127
|
+
if not (
|
1128
|
+
self.isIOS
|
1129
|
+
and (self.spec["type"] == "executable" or self._IsXCTest())
|
1130
|
+
or self.IsIosFramework()
|
1131
|
+
):
|
1132
|
+
return []
|
1133
|
+
|
1134
|
+
postbuilds = []
|
1135
|
+
product_name = self.GetFullProductName()
|
1136
|
+
settings = self.xcode_settings[configname]
|
1137
|
+
|
1138
|
+
# Xcode expects XCTests to be copied into the TEST_HOST dir.
|
1139
|
+
if self._IsXCTest():
|
1140
|
+
source = os.path.join("${BUILT_PRODUCTS_DIR}", product_name)
|
1141
|
+
test_host = os.path.dirname(settings.get("TEST_HOST"))
|
1142
|
+
xctest_destination = os.path.join(test_host, "PlugIns", product_name)
|
1143
|
+
postbuilds.extend([f"ditto {source} {xctest_destination}"])
|
1144
|
+
|
1145
|
+
key = self._GetIOSCodeSignIdentityKey(settings)
|
1146
|
+
if not key:
|
1147
|
+
return postbuilds
|
1148
|
+
|
1149
|
+
# Warn for any unimplemented signing xcode keys.
|
1150
|
+
unimpl = ["OTHER_CODE_SIGN_FLAGS"]
|
1151
|
+
unimpl = set(unimpl) & set(self.xcode_settings[configname].keys())
|
1152
|
+
if unimpl:
|
1153
|
+
print(
|
1154
|
+
"Warning: Some codesign keys not implemented, ignoring: %s"
|
1155
|
+
% ", ".join(sorted(unimpl))
|
1156
|
+
)
|
1157
|
+
|
1158
|
+
if self._IsXCTest():
|
1159
|
+
# For device xctests, Xcode copies two extra frameworks into $TEST_HOST.
|
1160
|
+
test_host = os.path.dirname(settings.get("TEST_HOST"))
|
1161
|
+
frameworks_dir = os.path.join(test_host, "Frameworks")
|
1162
|
+
platform_root = self._XcodePlatformPath(configname)
|
1163
|
+
frameworks = [
|
1164
|
+
"Developer/Library/PrivateFrameworks/IDEBundleInjection.framework",
|
1165
|
+
"Developer/Library/Frameworks/XCTest.framework",
|
1166
|
+
]
|
1167
|
+
for framework in frameworks:
|
1168
|
+
source = os.path.join(platform_root, framework)
|
1169
|
+
destination = os.path.join(frameworks_dir, os.path.basename(framework))
|
1170
|
+
postbuilds.extend([f"ditto {source} {destination}"])
|
1171
|
+
|
1172
|
+
# Then re-sign everything with 'preserve=True'
|
1173
|
+
postbuilds.extend(
|
1174
|
+
[
|
1175
|
+
'%s code-sign-bundle "%s" "%s" "%s" "%s" %s'
|
1176
|
+
% (
|
1177
|
+
os.path.join("${TARGET_BUILD_DIR}", "gyp-mac-tool"),
|
1178
|
+
key,
|
1179
|
+
settings.get("CODE_SIGN_ENTITLEMENTS", ""),
|
1180
|
+
settings.get("PROVISIONING_PROFILE", ""),
|
1181
|
+
destination,
|
1182
|
+
True,
|
1183
|
+
)
|
1184
|
+
]
|
1185
|
+
)
|
1186
|
+
plugin_dir = os.path.join(test_host, "PlugIns")
|
1187
|
+
targets = [os.path.join(plugin_dir, product_name), test_host]
|
1188
|
+
for target in targets:
|
1189
|
+
postbuilds.extend(
|
1190
|
+
[
|
1191
|
+
'%s code-sign-bundle "%s" "%s" "%s" "%s" %s'
|
1192
|
+
% (
|
1193
|
+
os.path.join("${TARGET_BUILD_DIR}", "gyp-mac-tool"),
|
1194
|
+
key,
|
1195
|
+
settings.get("CODE_SIGN_ENTITLEMENTS", ""),
|
1196
|
+
settings.get("PROVISIONING_PROFILE", ""),
|
1197
|
+
target,
|
1198
|
+
True,
|
1199
|
+
)
|
1200
|
+
]
|
1201
|
+
)
|
1202
|
+
|
1203
|
+
postbuilds.extend(
|
1204
|
+
[
|
1205
|
+
'%s code-sign-bundle "%s" "%s" "%s" "%s" %s'
|
1206
|
+
% (
|
1207
|
+
os.path.join("${TARGET_BUILD_DIR}", "gyp-mac-tool"),
|
1208
|
+
key,
|
1209
|
+
settings.get("CODE_SIGN_ENTITLEMENTS", ""),
|
1210
|
+
settings.get("PROVISIONING_PROFILE", ""),
|
1211
|
+
os.path.join("${BUILT_PRODUCTS_DIR}", product_name),
|
1212
|
+
False,
|
1213
|
+
)
|
1214
|
+
]
|
1215
|
+
)
|
1216
|
+
return postbuilds
|
1217
|
+
|
1218
|
+
def _GetIOSCodeSignIdentityKey(self, settings):
|
1219
|
+
identity = settings.get("CODE_SIGN_IDENTITY")
|
1220
|
+
if not identity:
|
1221
|
+
return None
|
1222
|
+
if identity not in XcodeSettings._codesigning_key_cache:
|
1223
|
+
output = subprocess.check_output(
|
1224
|
+
["security", "find-identity", "-p", "codesigning", "-v"]
|
1225
|
+
)
|
1226
|
+
for line in output.splitlines():
|
1227
|
+
if identity in line:
|
1228
|
+
fingerprint = line.split()[1]
|
1229
|
+
cache = XcodeSettings._codesigning_key_cache
|
1230
|
+
assert identity not in cache or fingerprint == cache[identity], (
|
1231
|
+
"Multiple codesigning fingerprints for identity: %s" % identity
|
1232
|
+
)
|
1233
|
+
XcodeSettings._codesigning_key_cache[identity] = fingerprint
|
1234
|
+
return XcodeSettings._codesigning_key_cache.get(identity, "")
|
1235
|
+
|
1236
|
+
def AddImplicitPostbuilds(
|
1237
|
+
self, configname, output, output_binary, postbuilds=[], quiet=False
|
1238
|
+
):
|
1239
|
+
"""Returns a list of shell commands that should run before and after
|
1240
|
+
|postbuilds|."""
|
1241
|
+
assert output_binary is not None
|
1242
|
+
pre = self._GetTargetPostbuilds(configname, output, output_binary, quiet)
|
1243
|
+
post = self._GetIOSPostbuilds(configname, output_binary)
|
1244
|
+
return pre + postbuilds + post
|
1245
|
+
|
1246
|
+
def _AdjustLibrary(self, library, config_name=None):
|
1247
|
+
if library.endswith(".framework"):
|
1248
|
+
l_flag = "-framework " + os.path.splitext(os.path.basename(library))[0]
|
1249
|
+
else:
|
1250
|
+
m = self.library_re.match(library)
|
1251
|
+
if m:
|
1252
|
+
l_flag = "-l" + m.group(1)
|
1253
|
+
else:
|
1254
|
+
l_flag = library
|
1255
|
+
|
1256
|
+
sdk_root = self._SdkPath(config_name)
|
1257
|
+
if not sdk_root:
|
1258
|
+
sdk_root = ""
|
1259
|
+
# Xcode 7 started shipping with ".tbd" (text based stubs) files instead of
|
1260
|
+
# ".dylib" without providing a real support for them. What it does, for
|
1261
|
+
# "/usr/lib" libraries, is do "-L/usr/lib -lname" which is dependent on the
|
1262
|
+
# library order and cause collision when building Chrome.
|
1263
|
+
#
|
1264
|
+
# Instead substitute ".tbd" to ".dylib" in the generated project when the
|
1265
|
+
# following conditions are both true:
|
1266
|
+
# - library is referenced in the gyp file as "$(SDKROOT)/**/*.dylib",
|
1267
|
+
# - the ".dylib" file does not exists but a ".tbd" file do.
|
1268
|
+
library = l_flag.replace("$(SDKROOT)", sdk_root)
|
1269
|
+
if l_flag.startswith("$(SDKROOT)"):
|
1270
|
+
basename, ext = os.path.splitext(library)
|
1271
|
+
if ext == ".dylib" and not os.path.exists(library):
|
1272
|
+
tbd_library = basename + ".tbd"
|
1273
|
+
if os.path.exists(tbd_library):
|
1274
|
+
library = tbd_library
|
1275
|
+
return library
|
1276
|
+
|
1277
|
+
def AdjustLibraries(self, libraries, config_name=None):
|
1278
|
+
"""Transforms entries like 'Cocoa.framework' in libraries into entries like
|
1279
|
+
'-framework Cocoa', 'libcrypto.dylib' into '-lcrypto', etc.
|
1280
|
+
"""
|
1281
|
+
libraries = [self._AdjustLibrary(library, config_name) for library in libraries]
|
1282
|
+
return libraries
|
1283
|
+
|
1284
|
+
def _BuildMachineOSBuild(self):
|
1285
|
+
return GetStdout(["sw_vers", "-buildVersion"])
|
1286
|
+
|
1287
|
+
def _XcodeIOSDeviceFamily(self, configname):
|
1288
|
+
family = self.xcode_settings[configname].get("TARGETED_DEVICE_FAMILY", "1")
|
1289
|
+
return [int(x) for x in family.split(",")]
|
1290
|
+
|
1291
|
+
def GetExtraPlistItems(self, configname=None):
|
1292
|
+
"""Returns a dictionary with extra items to insert into Info.plist."""
|
1293
|
+
if configname not in XcodeSettings._plist_cache:
|
1294
|
+
cache = {}
|
1295
|
+
cache["BuildMachineOSBuild"] = self._BuildMachineOSBuild()
|
1296
|
+
|
1297
|
+
xcode_version, xcode_build = XcodeVersion()
|
1298
|
+
cache["DTXcode"] = xcode_version
|
1299
|
+
cache["DTXcodeBuild"] = xcode_build
|
1300
|
+
compiler = self.xcode_settings[configname].get("GCC_VERSION")
|
1301
|
+
if compiler is not None:
|
1302
|
+
cache["DTCompiler"] = compiler
|
1303
|
+
|
1304
|
+
sdk_root = self._SdkRoot(configname)
|
1305
|
+
if not sdk_root:
|
1306
|
+
sdk_root = self._DefaultSdkRoot()
|
1307
|
+
sdk_version = self._GetSdkVersionInfoItem(sdk_root, "--show-sdk-version")
|
1308
|
+
cache["DTSDKName"] = sdk_root + (sdk_version or "")
|
1309
|
+
if xcode_version >= "0720":
|
1310
|
+
cache["DTSDKBuild"] = self._GetSdkVersionInfoItem(
|
1311
|
+
sdk_root, "--show-sdk-build-version"
|
1312
|
+
)
|
1313
|
+
elif xcode_version >= "0430":
|
1314
|
+
cache["DTSDKBuild"] = sdk_version
|
1315
|
+
else:
|
1316
|
+
cache["DTSDKBuild"] = cache["BuildMachineOSBuild"]
|
1317
|
+
|
1318
|
+
if self.isIOS:
|
1319
|
+
cache["MinimumOSVersion"] = self.xcode_settings[configname].get(
|
1320
|
+
"IPHONEOS_DEPLOYMENT_TARGET"
|
1321
|
+
)
|
1322
|
+
cache["DTPlatformName"] = sdk_root
|
1323
|
+
cache["DTPlatformVersion"] = sdk_version
|
1324
|
+
|
1325
|
+
if configname.endswith("iphoneos"):
|
1326
|
+
cache["CFBundleSupportedPlatforms"] = ["iPhoneOS"]
|
1327
|
+
cache["DTPlatformBuild"] = cache["DTSDKBuild"]
|
1328
|
+
else:
|
1329
|
+
cache["CFBundleSupportedPlatforms"] = ["iPhoneSimulator"]
|
1330
|
+
# This is weird, but Xcode sets DTPlatformBuild to an empty field
|
1331
|
+
# for simulator builds.
|
1332
|
+
cache["DTPlatformBuild"] = ""
|
1333
|
+
XcodeSettings._plist_cache[configname] = cache
|
1334
|
+
|
1335
|
+
# Include extra plist items that are per-target, not per global
|
1336
|
+
# XcodeSettings.
|
1337
|
+
items = dict(XcodeSettings._plist_cache[configname])
|
1338
|
+
if self.isIOS:
|
1339
|
+
items["UIDeviceFamily"] = self._XcodeIOSDeviceFamily(configname)
|
1340
|
+
return items
|
1341
|
+
|
1342
|
+
def _DefaultSdkRoot(self):
|
1343
|
+
"""Returns the default SDKROOT to use.
|
1344
|
+
|
1345
|
+
Prior to version 5.0.0, if SDKROOT was not explicitly set in the Xcode
|
1346
|
+
project, then the environment variable was empty. Starting with this
|
1347
|
+
version, Xcode uses the name of the newest SDK installed.
|
1348
|
+
"""
|
1349
|
+
xcode_version, _ = XcodeVersion()
|
1350
|
+
if xcode_version < "0500":
|
1351
|
+
return ""
|
1352
|
+
default_sdk_path = self._XcodeSdkPath("")
|
1353
|
+
default_sdk_root = XcodeSettings._sdk_root_cache.get(default_sdk_path)
|
1354
|
+
if default_sdk_root:
|
1355
|
+
return default_sdk_root
|
1356
|
+
try:
|
1357
|
+
all_sdks = GetStdout(["xcodebuild", "-showsdks"])
|
1358
|
+
except GypError:
|
1359
|
+
# If xcodebuild fails, there will be no valid SDKs
|
1360
|
+
return ""
|
1361
|
+
for line in all_sdks.splitlines():
|
1362
|
+
items = line.split()
|
1363
|
+
if len(items) >= 3 and items[-2] == "-sdk":
|
1364
|
+
sdk_root = items[-1]
|
1365
|
+
sdk_path = self._XcodeSdkPath(sdk_root)
|
1366
|
+
if sdk_path == default_sdk_path:
|
1367
|
+
return sdk_root
|
1368
|
+
return ""
|
1369
|
+
|
1370
|
+
|
1371
|
+
class MacPrefixHeader:
|
1372
|
+
"""A class that helps with emulating Xcode's GCC_PREFIX_HEADER feature.
|
1373
|
+
|
1374
|
+
This feature consists of several pieces:
|
1375
|
+
* If GCC_PREFIX_HEADER is present, all compilations in that project get an
|
1376
|
+
additional |-include path_to_prefix_header| cflag.
|
1377
|
+
* If GCC_PRECOMPILE_PREFIX_HEADER is present too, then the prefix header is
|
1378
|
+
instead compiled, and all other compilations in the project get an
|
1379
|
+
additional |-include path_to_compiled_header| instead.
|
1380
|
+
+ Compiled prefix headers have the extension gch. There is one gch file for
|
1381
|
+
every language used in the project (c, cc, m, mm), since gch files for
|
1382
|
+
different languages aren't compatible.
|
1383
|
+
+ gch files themselves are built with the target's normal cflags, but they
|
1384
|
+
obviously don't get the |-include| flag. Instead, they need a -x flag that
|
1385
|
+
describes their language.
|
1386
|
+
+ All o files in the target need to depend on the gch file, to make sure
|
1387
|
+
it's built before any o file is built.
|
1388
|
+
|
1389
|
+
This class helps with some of these tasks, but it needs help from the build
|
1390
|
+
system for writing dependencies to the gch files, for writing build commands
|
1391
|
+
for the gch files, and for figuring out the location of the gch files.
|
1392
|
+
"""
|
1393
|
+
|
1394
|
+
def __init__(
|
1395
|
+
self, xcode_settings, gyp_path_to_build_path, gyp_path_to_build_output
|
1396
|
+
):
|
1397
|
+
"""If xcode_settings is None, all methods on this class are no-ops.
|
1398
|
+
|
1399
|
+
Args:
|
1400
|
+
gyp_path_to_build_path: A function that takes a gyp-relative path,
|
1401
|
+
and returns a path relative to the build directory.
|
1402
|
+
gyp_path_to_build_output: A function that takes a gyp-relative path and
|
1403
|
+
a language code ('c', 'cc', 'm', or 'mm'), and that returns a path
|
1404
|
+
to where the output of precompiling that path for that language
|
1405
|
+
should be placed (without the trailing '.gch').
|
1406
|
+
"""
|
1407
|
+
# This doesn't support per-configuration prefix headers. Good enough
|
1408
|
+
# for now.
|
1409
|
+
self.header = None
|
1410
|
+
self.compile_headers = False
|
1411
|
+
if xcode_settings:
|
1412
|
+
self.header = xcode_settings.GetPerTargetSetting("GCC_PREFIX_HEADER")
|
1413
|
+
self.compile_headers = (
|
1414
|
+
xcode_settings.GetPerTargetSetting(
|
1415
|
+
"GCC_PRECOMPILE_PREFIX_HEADER", default="NO"
|
1416
|
+
)
|
1417
|
+
!= "NO"
|
1418
|
+
)
|
1419
|
+
self.compiled_headers = {}
|
1420
|
+
if self.header:
|
1421
|
+
if self.compile_headers:
|
1422
|
+
for lang in ["c", "cc", "m", "mm"]:
|
1423
|
+
self.compiled_headers[lang] = gyp_path_to_build_output(
|
1424
|
+
self.header, lang
|
1425
|
+
)
|
1426
|
+
self.header = gyp_path_to_build_path(self.header)
|
1427
|
+
|
1428
|
+
def _CompiledHeader(self, lang, arch):
|
1429
|
+
assert self.compile_headers
|
1430
|
+
h = self.compiled_headers[lang]
|
1431
|
+
if arch:
|
1432
|
+
h += "." + arch
|
1433
|
+
return h
|
1434
|
+
|
1435
|
+
def GetInclude(self, lang, arch=None):
|
1436
|
+
"""Gets the cflags to include the prefix header for language |lang|."""
|
1437
|
+
if self.compile_headers and lang in self.compiled_headers:
|
1438
|
+
return "-include %s" % self._CompiledHeader(lang, arch)
|
1439
|
+
elif self.header:
|
1440
|
+
return "-include %s" % self.header
|
1441
|
+
else:
|
1442
|
+
return ""
|
1443
|
+
|
1444
|
+
def _Gch(self, lang, arch):
|
1445
|
+
"""Returns the actual file name of the prefix header for language |lang|."""
|
1446
|
+
assert self.compile_headers
|
1447
|
+
return self._CompiledHeader(lang, arch) + ".gch"
|
1448
|
+
|
1449
|
+
def GetObjDependencies(self, sources, objs, arch=None):
|
1450
|
+
"""Given a list of source files and the corresponding object files, returns
|
1451
|
+
a list of (source, object, gch) tuples, where |gch| is the build-directory
|
1452
|
+
relative path to the gch file each object file depends on. |compilable[i]|
|
1453
|
+
has to be the source file belonging to |objs[i]|."""
|
1454
|
+
if not self.header or not self.compile_headers:
|
1455
|
+
return []
|
1456
|
+
|
1457
|
+
result = []
|
1458
|
+
for source, obj in zip(sources, objs):
|
1459
|
+
ext = os.path.splitext(source)[1]
|
1460
|
+
lang = {
|
1461
|
+
".c": "c",
|
1462
|
+
".cpp": "cc",
|
1463
|
+
".cc": "cc",
|
1464
|
+
".cxx": "cc",
|
1465
|
+
".m": "m",
|
1466
|
+
".mm": "mm",
|
1467
|
+
}.get(ext, None)
|
1468
|
+
if lang:
|
1469
|
+
result.append((source, obj, self._Gch(lang, arch)))
|
1470
|
+
return result
|
1471
|
+
|
1472
|
+
def GetPchBuildCommands(self, arch=None):
|
1473
|
+
"""Returns [(path_to_gch, language_flag, language, header)].
|
1474
|
+
|path_to_gch| and |header| are relative to the build directory.
|
1475
|
+
"""
|
1476
|
+
if not self.header or not self.compile_headers:
|
1477
|
+
return []
|
1478
|
+
return [
|
1479
|
+
(self._Gch("c", arch), "-x c-header", "c", self.header),
|
1480
|
+
(self._Gch("cc", arch), "-x c++-header", "cc", self.header),
|
1481
|
+
(self._Gch("m", arch), "-x objective-c-header", "m", self.header),
|
1482
|
+
(self._Gch("mm", arch), "-x objective-c++-header", "mm", self.header),
|
1483
|
+
]
|
1484
|
+
|
1485
|
+
|
1486
|
+
def XcodeVersion():
|
1487
|
+
"""Returns a tuple of version and build version of installed Xcode."""
|
1488
|
+
# `xcodebuild -version` output looks like
|
1489
|
+
# Xcode 4.6.3
|
1490
|
+
# Build version 4H1503
|
1491
|
+
# or like
|
1492
|
+
# Xcode 3.2.6
|
1493
|
+
# Component versions: DevToolsCore-1809.0; DevToolsSupport-1806.0
|
1494
|
+
# BuildVersion: 10M2518
|
1495
|
+
# Convert that to ('0463', '4H1503') or ('0326', '10M2518').
|
1496
|
+
global XCODE_VERSION_CACHE
|
1497
|
+
if XCODE_VERSION_CACHE:
|
1498
|
+
return XCODE_VERSION_CACHE
|
1499
|
+
version = ""
|
1500
|
+
build = ""
|
1501
|
+
try:
|
1502
|
+
version_list = GetStdoutQuiet(["xcodebuild", "-version"]).splitlines()
|
1503
|
+
# In some circumstances xcodebuild exits 0 but doesn't return
|
1504
|
+
# the right results; for example, a user on 10.7 or 10.8 with
|
1505
|
+
# a bogus path set via xcode-select
|
1506
|
+
# In that case this may be a CLT-only install so fall back to
|
1507
|
+
# checking that version.
|
1508
|
+
if len(version_list) < 2:
|
1509
|
+
raise GypError("xcodebuild returned unexpected results")
|
1510
|
+
version = version_list[0].split()[-1] # Last word on first line
|
1511
|
+
build = version_list[-1].split()[-1] # Last word on last line
|
1512
|
+
except GypError: # Xcode not installed so look for XCode Command Line Tools
|
1513
|
+
version = CLTVersion() # macOS Catalina returns 11.0.0.0.1.1567737322
|
1514
|
+
if not version:
|
1515
|
+
raise GypError("No Xcode or CLT version detected!")
|
1516
|
+
# Be careful to convert "4.2.3" to "0423" and "11.0.0" to "1100":
|
1517
|
+
version = version.split(".")[:3] # Just major, minor, micro
|
1518
|
+
version[0] = version[0].zfill(2) # Add a leading zero if major is one digit
|
1519
|
+
version = ("".join(version) + "00")[:4] # Limit to exactly four characters
|
1520
|
+
XCODE_VERSION_CACHE = (version, build)
|
1521
|
+
return XCODE_VERSION_CACHE
|
1522
|
+
|
1523
|
+
|
1524
|
+
# This function ported from the logic in Homebrew's CLT version check
|
1525
|
+
def CLTVersion():
|
1526
|
+
"""Returns the version of command-line tools from pkgutil."""
|
1527
|
+
# pkgutil output looks like
|
1528
|
+
# package-id: com.apple.pkg.CLTools_Executables
|
1529
|
+
# version: 5.0.1.0.1.1382131676
|
1530
|
+
# volume: /
|
1531
|
+
# location: /
|
1532
|
+
# install-time: 1382544035
|
1533
|
+
# groups: com.apple.FindSystemFiles.pkg-group
|
1534
|
+
# com.apple.DevToolsBoth.pkg-group
|
1535
|
+
# com.apple.DevToolsNonRelocatableShared.pkg-group
|
1536
|
+
STANDALONE_PKG_ID = "com.apple.pkg.DeveloperToolsCLILeo"
|
1537
|
+
FROM_XCODE_PKG_ID = "com.apple.pkg.DeveloperToolsCLI"
|
1538
|
+
MAVERICKS_PKG_ID = "com.apple.pkg.CLTools_Executables"
|
1539
|
+
|
1540
|
+
regex = re.compile("version: (?P<version>.+)")
|
1541
|
+
for key in [MAVERICKS_PKG_ID, STANDALONE_PKG_ID, FROM_XCODE_PKG_ID]:
|
1542
|
+
try:
|
1543
|
+
output = GetStdout(["/usr/sbin/pkgutil", "--pkg-info", key])
|
1544
|
+
return re.search(regex, output).groupdict()["version"]
|
1545
|
+
except GypError:
|
1546
|
+
continue
|
1547
|
+
|
1548
|
+
regex = re.compile(r'Command Line Tools for Xcode\s+(?P<version>\S+)')
|
1549
|
+
try:
|
1550
|
+
output = GetStdout(["/usr/sbin/softwareupdate", "--history"])
|
1551
|
+
return re.search(regex, output).groupdict()["version"]
|
1552
|
+
except GypError:
|
1553
|
+
return None
|
1554
|
+
|
1555
|
+
|
1556
|
+
def GetStdoutQuiet(cmdlist):
|
1557
|
+
"""Returns the content of standard output returned by invoking |cmdlist|.
|
1558
|
+
Ignores the stderr.
|
1559
|
+
Raises |GypError| if the command return with a non-zero return code."""
|
1560
|
+
job = subprocess.Popen(cmdlist, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
1561
|
+
out = job.communicate()[0].decode("utf-8")
|
1562
|
+
if job.returncode != 0:
|
1563
|
+
raise GypError("Error %d running %s" % (job.returncode, cmdlist[0]))
|
1564
|
+
return out.rstrip("\n")
|
1565
|
+
|
1566
|
+
|
1567
|
+
def GetStdout(cmdlist):
|
1568
|
+
"""Returns the content of standard output returned by invoking |cmdlist|.
|
1569
|
+
Raises |GypError| if the command return with a non-zero return code."""
|
1570
|
+
job = subprocess.Popen(cmdlist, stdout=subprocess.PIPE)
|
1571
|
+
out = job.communicate()[0].decode("utf-8")
|
1572
|
+
if job.returncode != 0:
|
1573
|
+
sys.stderr.write(out + "\n")
|
1574
|
+
raise GypError("Error %d running %s" % (job.returncode, cmdlist[0]))
|
1575
|
+
return out.rstrip("\n")
|
1576
|
+
|
1577
|
+
|
1578
|
+
def MergeGlobalXcodeSettingsToSpec(global_dict, spec):
|
1579
|
+
"""Merges the global xcode_settings dictionary into each configuration of the
|
1580
|
+
target represented by spec. For keys that are both in the global and the local
|
1581
|
+
xcode_settings dict, the local key gets precedence.
|
1582
|
+
"""
|
1583
|
+
# The xcode generator special-cases global xcode_settings and does something
|
1584
|
+
# that amounts to merging in the global xcode_settings into each local
|
1585
|
+
# xcode_settings dict.
|
1586
|
+
global_xcode_settings = global_dict.get("xcode_settings", {})
|
1587
|
+
for config in spec["configurations"].values():
|
1588
|
+
if "xcode_settings" in config:
|
1589
|
+
new_settings = global_xcode_settings.copy()
|
1590
|
+
new_settings.update(config["xcode_settings"])
|
1591
|
+
config["xcode_settings"] = new_settings
|
1592
|
+
|
1593
|
+
|
1594
|
+
def IsMacBundle(flavor, spec):
|
1595
|
+
"""Returns if |spec| should be treated as a bundle.
|
1596
|
+
|
1597
|
+
Bundles are directories with a certain subdirectory structure, instead of
|
1598
|
+
just a single file. Bundle rules do not produce a binary but also package
|
1599
|
+
resources into that directory."""
|
1600
|
+
is_mac_bundle = (
|
1601
|
+
int(spec.get("mac_xctest_bundle", 0)) != 0
|
1602
|
+
or int(spec.get("mac_xcuitest_bundle", 0)) != 0
|
1603
|
+
or (int(spec.get("mac_bundle", 0)) != 0 and flavor == "mac")
|
1604
|
+
)
|
1605
|
+
|
1606
|
+
if is_mac_bundle:
|
1607
|
+
assert spec["type"] != "none", (
|
1608
|
+
'mac_bundle targets cannot have type none (target "%s")'
|
1609
|
+
% spec["target_name"]
|
1610
|
+
)
|
1611
|
+
return is_mac_bundle
|
1612
|
+
|
1613
|
+
|
1614
|
+
def GetMacBundleResources(product_dir, xcode_settings, resources):
|
1615
|
+
"""Yields (output, resource) pairs for every resource in |resources|.
|
1616
|
+
Only call this for mac bundle targets.
|
1617
|
+
|
1618
|
+
Args:
|
1619
|
+
product_dir: Path to the directory containing the output bundle,
|
1620
|
+
relative to the build directory.
|
1621
|
+
xcode_settings: The XcodeSettings of the current target.
|
1622
|
+
resources: A list of bundle resources, relative to the build directory.
|
1623
|
+
"""
|
1624
|
+
dest = os.path.join(product_dir, xcode_settings.GetBundleResourceFolder())
|
1625
|
+
for res in resources:
|
1626
|
+
output = dest
|
1627
|
+
|
1628
|
+
# The make generator doesn't support it, so forbid it everywhere
|
1629
|
+
# to keep the generators more interchangeable.
|
1630
|
+
assert " " not in res, "Spaces in resource filenames not supported (%s)" % res
|
1631
|
+
|
1632
|
+
# Split into (path,file).
|
1633
|
+
res_parts = os.path.split(res)
|
1634
|
+
|
1635
|
+
# Now split the path into (prefix,maybe.lproj).
|
1636
|
+
lproj_parts = os.path.split(res_parts[0])
|
1637
|
+
# If the resource lives in a .lproj bundle, add that to the destination.
|
1638
|
+
if lproj_parts[1].endswith(".lproj"):
|
1639
|
+
output = os.path.join(output, lproj_parts[1])
|
1640
|
+
|
1641
|
+
output = os.path.join(output, res_parts[1])
|
1642
|
+
# Compiled XIB files are referred to by .nib.
|
1643
|
+
if output.endswith(".xib"):
|
1644
|
+
output = os.path.splitext(output)[0] + ".nib"
|
1645
|
+
# Compiled storyboard files are referred to by .storyboardc.
|
1646
|
+
if output.endswith(".storyboard"):
|
1647
|
+
output = os.path.splitext(output)[0] + ".storyboardc"
|
1648
|
+
|
1649
|
+
yield output, res
|
1650
|
+
|
1651
|
+
|
1652
|
+
def GetMacInfoPlist(product_dir, xcode_settings, gyp_path_to_build_path):
|
1653
|
+
"""Returns (info_plist, dest_plist, defines, extra_env), where:
|
1654
|
+
* |info_plist| is the source plist path, relative to the
|
1655
|
+
build directory,
|
1656
|
+
* |dest_plist| is the destination plist path, relative to the
|
1657
|
+
build directory,
|
1658
|
+
* |defines| is a list of preprocessor defines (empty if the plist
|
1659
|
+
shouldn't be preprocessed,
|
1660
|
+
* |extra_env| is a dict of env variables that should be exported when
|
1661
|
+
invoking |mac_tool copy-info-plist|.
|
1662
|
+
|
1663
|
+
Only call this for mac bundle targets.
|
1664
|
+
|
1665
|
+
Args:
|
1666
|
+
product_dir: Path to the directory containing the output bundle,
|
1667
|
+
relative to the build directory.
|
1668
|
+
xcode_settings: The XcodeSettings of the current target.
|
1669
|
+
gyp_to_build_path: A function that converts paths relative to the
|
1670
|
+
current gyp file to paths relative to the build directory.
|
1671
|
+
"""
|
1672
|
+
info_plist = xcode_settings.GetPerTargetSetting("INFOPLIST_FILE")
|
1673
|
+
if not info_plist:
|
1674
|
+
return None, None, [], {}
|
1675
|
+
|
1676
|
+
# The make generator doesn't support it, so forbid it everywhere
|
1677
|
+
# to keep the generators more interchangeable.
|
1678
|
+
assert " " not in info_plist, (
|
1679
|
+
"Spaces in Info.plist filenames not supported (%s)" % info_plist
|
1680
|
+
)
|
1681
|
+
|
1682
|
+
info_plist = gyp_path_to_build_path(info_plist)
|
1683
|
+
|
1684
|
+
# If explicitly set to preprocess the plist, invoke the C preprocessor and
|
1685
|
+
# specify any defines as -D flags.
|
1686
|
+
if (
|
1687
|
+
xcode_settings.GetPerTargetSetting("INFOPLIST_PREPROCESS", default="NO")
|
1688
|
+
== "YES"
|
1689
|
+
):
|
1690
|
+
# Create an intermediate file based on the path.
|
1691
|
+
defines = shlex.split(
|
1692
|
+
xcode_settings.GetPerTargetSetting(
|
1693
|
+
"INFOPLIST_PREPROCESSOR_DEFINITIONS", default=""
|
1694
|
+
)
|
1695
|
+
)
|
1696
|
+
else:
|
1697
|
+
defines = []
|
1698
|
+
|
1699
|
+
dest_plist = os.path.join(product_dir, xcode_settings.GetBundlePlistPath())
|
1700
|
+
extra_env = xcode_settings.GetPerTargetSettings()
|
1701
|
+
|
1702
|
+
return info_plist, dest_plist, defines, extra_env
|
1703
|
+
|
1704
|
+
|
1705
|
+
def _GetXcodeEnv(
|
1706
|
+
xcode_settings, built_products_dir, srcroot, configuration, additional_settings=None
|
1707
|
+
):
|
1708
|
+
"""Return the environment variables that Xcode would set. See
|
1709
|
+
http://developer.apple.com/library/mac/#documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html#//apple_ref/doc/uid/TP40003931-CH3-SW153
|
1710
|
+
for a full list.
|
1711
|
+
|
1712
|
+
Args:
|
1713
|
+
xcode_settings: An XcodeSettings object. If this is None, this function
|
1714
|
+
returns an empty dict.
|
1715
|
+
built_products_dir: Absolute path to the built products dir.
|
1716
|
+
srcroot: Absolute path to the source root.
|
1717
|
+
configuration: The build configuration name.
|
1718
|
+
additional_settings: An optional dict with more values to add to the
|
1719
|
+
result.
|
1720
|
+
"""
|
1721
|
+
|
1722
|
+
if not xcode_settings:
|
1723
|
+
return {}
|
1724
|
+
|
1725
|
+
# This function is considered a friend of XcodeSettings, so let it reach into
|
1726
|
+
# its implementation details.
|
1727
|
+
spec = xcode_settings.spec
|
1728
|
+
|
1729
|
+
# These are filled in on an as-needed basis.
|
1730
|
+
env = {
|
1731
|
+
"BUILT_FRAMEWORKS_DIR": built_products_dir,
|
1732
|
+
"BUILT_PRODUCTS_DIR": built_products_dir,
|
1733
|
+
"CONFIGURATION": configuration,
|
1734
|
+
"PRODUCT_NAME": xcode_settings.GetProductName(),
|
1735
|
+
# For FULL_PRODUCT_NAME see:
|
1736
|
+
# /Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/Specifications/MacOSX\ Product\ Types.xcspec # noqa: E501
|
1737
|
+
"SRCROOT": srcroot,
|
1738
|
+
"SOURCE_ROOT": "${SRCROOT}",
|
1739
|
+
# This is not true for static libraries, but currently the env is only
|
1740
|
+
# written for bundles:
|
1741
|
+
"TARGET_BUILD_DIR": built_products_dir,
|
1742
|
+
"TEMP_DIR": "${TMPDIR}",
|
1743
|
+
"XCODE_VERSION_ACTUAL": XcodeVersion()[0],
|
1744
|
+
}
|
1745
|
+
if xcode_settings.GetPerConfigSetting("SDKROOT", configuration):
|
1746
|
+
env["SDKROOT"] = xcode_settings._SdkPath(configuration)
|
1747
|
+
else:
|
1748
|
+
env["SDKROOT"] = ""
|
1749
|
+
|
1750
|
+
if xcode_settings.mac_toolchain_dir:
|
1751
|
+
env["DEVELOPER_DIR"] = xcode_settings.mac_toolchain_dir
|
1752
|
+
|
1753
|
+
if spec["type"] in (
|
1754
|
+
"executable",
|
1755
|
+
"static_library",
|
1756
|
+
"shared_library",
|
1757
|
+
"loadable_module",
|
1758
|
+
):
|
1759
|
+
env["EXECUTABLE_NAME"] = xcode_settings.GetExecutableName()
|
1760
|
+
env["EXECUTABLE_PATH"] = xcode_settings.GetExecutablePath()
|
1761
|
+
env["FULL_PRODUCT_NAME"] = xcode_settings.GetFullProductName()
|
1762
|
+
mach_o_type = xcode_settings.GetMachOType()
|
1763
|
+
if mach_o_type:
|
1764
|
+
env["MACH_O_TYPE"] = mach_o_type
|
1765
|
+
env["PRODUCT_TYPE"] = xcode_settings.GetProductType()
|
1766
|
+
if xcode_settings._IsBundle():
|
1767
|
+
# xcodeproj_file.py sets the same Xcode subfolder value for this as for
|
1768
|
+
# FRAMEWORKS_FOLDER_PATH so Xcode builds will actually use FFP's value.
|
1769
|
+
env["BUILT_FRAMEWORKS_DIR"] = os.path.join(
|
1770
|
+
built_products_dir + os.sep + xcode_settings.GetBundleFrameworksFolderPath()
|
1771
|
+
)
|
1772
|
+
env["CONTENTS_FOLDER_PATH"] = xcode_settings.GetBundleContentsFolderPath()
|
1773
|
+
env["EXECUTABLE_FOLDER_PATH"] = xcode_settings.GetBundleExecutableFolderPath()
|
1774
|
+
env[
|
1775
|
+
"UNLOCALIZED_RESOURCES_FOLDER_PATH"
|
1776
|
+
] = xcode_settings.GetBundleResourceFolder()
|
1777
|
+
env["JAVA_FOLDER_PATH"] = xcode_settings.GetBundleJavaFolderPath()
|
1778
|
+
env["FRAMEWORKS_FOLDER_PATH"] = xcode_settings.GetBundleFrameworksFolderPath()
|
1779
|
+
env[
|
1780
|
+
"SHARED_FRAMEWORKS_FOLDER_PATH"
|
1781
|
+
] = xcode_settings.GetBundleSharedFrameworksFolderPath()
|
1782
|
+
env[
|
1783
|
+
"SHARED_SUPPORT_FOLDER_PATH"
|
1784
|
+
] = xcode_settings.GetBundleSharedSupportFolderPath()
|
1785
|
+
env["PLUGINS_FOLDER_PATH"] = xcode_settings.GetBundlePlugInsFolderPath()
|
1786
|
+
env["XPCSERVICES_FOLDER_PATH"] = xcode_settings.GetBundleXPCServicesFolderPath()
|
1787
|
+
env["INFOPLIST_PATH"] = xcode_settings.GetBundlePlistPath()
|
1788
|
+
env["WRAPPER_NAME"] = xcode_settings.GetWrapperName()
|
1789
|
+
|
1790
|
+
install_name = xcode_settings.GetInstallName()
|
1791
|
+
if install_name:
|
1792
|
+
env["LD_DYLIB_INSTALL_NAME"] = install_name
|
1793
|
+
install_name_base = xcode_settings.GetInstallNameBase()
|
1794
|
+
if install_name_base:
|
1795
|
+
env["DYLIB_INSTALL_NAME_BASE"] = install_name_base
|
1796
|
+
xcode_version, _ = XcodeVersion()
|
1797
|
+
if xcode_version >= "0500" and not env.get("SDKROOT"):
|
1798
|
+
sdk_root = xcode_settings._SdkRoot(configuration)
|
1799
|
+
if not sdk_root:
|
1800
|
+
sdk_root = xcode_settings._XcodeSdkPath("")
|
1801
|
+
if sdk_root is None:
|
1802
|
+
sdk_root = ""
|
1803
|
+
env["SDKROOT"] = sdk_root
|
1804
|
+
|
1805
|
+
if not additional_settings:
|
1806
|
+
additional_settings = {}
|
1807
|
+
else:
|
1808
|
+
# Flatten lists to strings.
|
1809
|
+
for k in additional_settings:
|
1810
|
+
if not isinstance(additional_settings[k], str):
|
1811
|
+
additional_settings[k] = " ".join(additional_settings[k])
|
1812
|
+
additional_settings.update(env)
|
1813
|
+
|
1814
|
+
for k in additional_settings:
|
1815
|
+
additional_settings[k] = _NormalizeEnvVarReferences(additional_settings[k])
|
1816
|
+
|
1817
|
+
return additional_settings
|
1818
|
+
|
1819
|
+
|
1820
|
+
def _NormalizeEnvVarReferences(str):
|
1821
|
+
"""Takes a string containing variable references in the form ${FOO}, $(FOO),
|
1822
|
+
or $FOO, and returns a string with all variable references in the form ${FOO}.
|
1823
|
+
"""
|
1824
|
+
# $FOO -> ${FOO}
|
1825
|
+
str = re.sub(r"\$([a-zA-Z_][a-zA-Z0-9_]*)", r"${\1}", str)
|
1826
|
+
|
1827
|
+
# $(FOO) -> ${FOO}
|
1828
|
+
matches = re.findall(r"(\$\(([a-zA-Z0-9\-_]+)\))", str)
|
1829
|
+
for match in matches:
|
1830
|
+
to_replace, variable = match
|
1831
|
+
assert "$(" not in match, "$($(FOO)) variables not supported: " + match
|
1832
|
+
str = str.replace(to_replace, "${" + variable + "}")
|
1833
|
+
|
1834
|
+
return str
|
1835
|
+
|
1836
|
+
|
1837
|
+
def ExpandEnvVars(string, expansions):
|
1838
|
+
"""Expands ${VARIABLES}, $(VARIABLES), and $VARIABLES in string per the
|
1839
|
+
expansions list. If the variable expands to something that references
|
1840
|
+
another variable, this variable is expanded as well if it's in env --
|
1841
|
+
until no variables present in env are left."""
|
1842
|
+
for k, v in reversed(expansions):
|
1843
|
+
string = string.replace("${" + k + "}", v)
|
1844
|
+
string = string.replace("$(" + k + ")", v)
|
1845
|
+
string = string.replace("$" + k, v)
|
1846
|
+
return string
|
1847
|
+
|
1848
|
+
|
1849
|
+
def _TopologicallySortedEnvVarKeys(env):
|
1850
|
+
"""Takes a dict |env| whose values are strings that can refer to other keys,
|
1851
|
+
for example env['foo'] = '$(bar) and $(baz)'. Returns a list L of all keys of
|
1852
|
+
env such that key2 is after key1 in L if env[key2] refers to env[key1].
|
1853
|
+
|
1854
|
+
Throws an Exception in case of dependency cycles.
|
1855
|
+
"""
|
1856
|
+
# Since environment variables can refer to other variables, the evaluation
|
1857
|
+
# order is important. Below is the logic to compute the dependency graph
|
1858
|
+
# and sort it.
|
1859
|
+
regex = re.compile(r"\$\{([a-zA-Z0-9\-_]+)\}")
|
1860
|
+
|
1861
|
+
def GetEdges(node):
|
1862
|
+
# Use a definition of edges such that user_of_variable -> used_varible.
|
1863
|
+
# This happens to be easier in this case, since a variable's
|
1864
|
+
# definition contains all variables it references in a single string.
|
1865
|
+
# We can then reverse the result of the topological sort at the end.
|
1866
|
+
# Since: reverse(topsort(DAG)) = topsort(reverse_edges(DAG))
|
1867
|
+
matches = {v for v in regex.findall(env[node]) if v in env}
|
1868
|
+
for dependee in matches:
|
1869
|
+
assert "${" not in dependee, "Nested variables not supported: " + dependee
|
1870
|
+
return matches
|
1871
|
+
|
1872
|
+
try:
|
1873
|
+
# Topologically sort, and then reverse, because we used an edge definition
|
1874
|
+
# that's inverted from the expected result of this function (see comment
|
1875
|
+
# above).
|
1876
|
+
order = gyp.common.TopologicallySorted(env.keys(), GetEdges)
|
1877
|
+
order.reverse()
|
1878
|
+
return order
|
1879
|
+
except gyp.common.CycleError as e:
|
1880
|
+
raise GypError(
|
1881
|
+
"Xcode environment variables are cyclically dependent: " + str(e.nodes)
|
1882
|
+
)
|
1883
|
+
|
1884
|
+
|
1885
|
+
def GetSortedXcodeEnv(
|
1886
|
+
xcode_settings, built_products_dir, srcroot, configuration, additional_settings=None
|
1887
|
+
):
|
1888
|
+
env = _GetXcodeEnv(
|
1889
|
+
xcode_settings, built_products_dir, srcroot, configuration, additional_settings
|
1890
|
+
)
|
1891
|
+
return [(key, env[key]) for key in _TopologicallySortedEnvVarKeys(env)]
|
1892
|
+
|
1893
|
+
|
1894
|
+
def GetSpecPostbuildCommands(spec, quiet=False):
|
1895
|
+
"""Returns the list of postbuilds explicitly defined on |spec|, in a form
|
1896
|
+
executable by a shell."""
|
1897
|
+
postbuilds = []
|
1898
|
+
for postbuild in spec.get("postbuilds", []):
|
1899
|
+
if not quiet:
|
1900
|
+
postbuilds.append(
|
1901
|
+
"echo POSTBUILD\\(%s\\) %s"
|
1902
|
+
% (spec["target_name"], postbuild["postbuild_name"])
|
1903
|
+
)
|
1904
|
+
postbuilds.append(gyp.common.EncodePOSIXShellList(postbuild["action"]))
|
1905
|
+
return postbuilds
|
1906
|
+
|
1907
|
+
|
1908
|
+
def _HasIOSTarget(targets):
|
1909
|
+
"""Returns true if any target contains the iOS specific key
|
1910
|
+
IPHONEOS_DEPLOYMENT_TARGET."""
|
1911
|
+
for target_dict in targets.values():
|
1912
|
+
for config in target_dict["configurations"].values():
|
1913
|
+
if config.get("xcode_settings", {}).get("IPHONEOS_DEPLOYMENT_TARGET"):
|
1914
|
+
return True
|
1915
|
+
return False
|
1916
|
+
|
1917
|
+
|
1918
|
+
def _AddIOSDeviceConfigurations(targets):
|
1919
|
+
"""Clone all targets and append -iphoneos to the name. Configure these targets
|
1920
|
+
to build for iOS devices and use correct architectures for those builds."""
|
1921
|
+
for target_dict in targets.values():
|
1922
|
+
toolset = target_dict["toolset"]
|
1923
|
+
configs = target_dict["configurations"]
|
1924
|
+
for config_name, simulator_config_dict in dict(configs).items():
|
1925
|
+
iphoneos_config_dict = copy.deepcopy(simulator_config_dict)
|
1926
|
+
configs[config_name + "-iphoneos"] = iphoneos_config_dict
|
1927
|
+
configs[config_name + "-iphonesimulator"] = simulator_config_dict
|
1928
|
+
if toolset == "target":
|
1929
|
+
simulator_config_dict["xcode_settings"]["SDKROOT"] = "iphonesimulator"
|
1930
|
+
iphoneos_config_dict["xcode_settings"]["SDKROOT"] = "iphoneos"
|
1931
|
+
return targets
|
1932
|
+
|
1933
|
+
|
1934
|
+
def CloneConfigurationForDeviceAndEmulator(target_dicts):
|
1935
|
+
"""If |target_dicts| contains any iOS targets, automatically create -iphoneos
|
1936
|
+
targets for iOS device builds."""
|
1937
|
+
if _HasIOSTarget(target_dicts):
|
1938
|
+
return _AddIOSDeviceConfigurations(target_dicts)
|
1939
|
+
return target_dicts
|