wsba-hockey 1.0.3__py3-none-any.whl → 1.0.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. wsba_hockey/__init__.py +1 -1
  2. wsba_hockey/data_pipelines.py +183 -0
  3. wsba_hockey/evidence/weakside-breakout/node_modules/duckdb/vendor.py +146 -0
  4. wsba_hockey/evidence/weakside-breakout/node_modules/flatted/python/flatted.py +149 -0
  5. wsba_hockey/evidence/weakside-breakout/node_modules/flatted/python/test.py +63 -0
  6. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  7. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +367 -0
  8. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  9. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1270 -0
  10. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
  11. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  12. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +153 -0
  13. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +271 -0
  14. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
  15. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +690 -0
  16. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/common.py +661 -0
  17. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +78 -0
  18. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +165 -0
  19. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +109 -0
  20. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  21. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  22. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +808 -0
  23. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1173 -0
  24. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1321 -0
  25. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +120 -0
  26. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +103 -0
  27. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +464 -0
  28. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
  29. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +58 -0
  30. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2714 -0
  31. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3981 -0
  32. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  33. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2936 -0
  34. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +55 -0
  35. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1394 -0
  36. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +25 -0
  37. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/input.py +3130 -0
  38. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +98 -0
  39. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +771 -0
  40. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1271 -0
  41. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  42. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  43. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +374 -0
  44. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1939 -0
  45. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +302 -0
  46. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3197 -0
  47. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
  48. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/test_gyp.py +261 -0
  49. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/graphviz.py +102 -0
  50. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_gyp.py +156 -0
  51. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_sln.py +181 -0
  52. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_vcproj.py +339 -0
  53. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/test/fixtures/test-charmap.py +31 -0
  54. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/update-gyp.py +64 -0
  55. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  56. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +367 -0
  57. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  58. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1270 -0
  59. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
  60. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  61. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +153 -0
  62. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +271 -0
  63. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
  64. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +666 -0
  65. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/common.py +654 -0
  66. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +78 -0
  67. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +165 -0
  68. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +109 -0
  69. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  70. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  71. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +808 -0
  72. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1173 -0
  73. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1321 -0
  74. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +120 -0
  75. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +103 -0
  76. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +464 -0
  77. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
  78. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +58 -0
  79. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2518 -0
  80. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3978 -0
  81. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  82. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2936 -0
  83. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +55 -0
  84. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1394 -0
  85. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +25 -0
  86. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/input.py +3137 -0
  87. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +98 -0
  88. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +771 -0
  89. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1271 -0
  90. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  91. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  92. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +374 -0
  93. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1939 -0
  94. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +302 -0
  95. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3197 -0
  96. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
  97. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/setup.py +42 -0
  98. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/test_gyp.py +260 -0
  99. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/graphviz.py +102 -0
  100. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_gyp.py +156 -0
  101. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_sln.py +181 -0
  102. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_vcproj.py +339 -0
  103. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/test/fixtures/test-charmap.py +31 -0
  104. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/update-gyp.py +46 -0
  105. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/game_stats/app.py +400 -0
  106. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/game_stats/name_fix.py +47 -0
  107. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/app.py +108 -0
  108. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/plot.py +93 -0
  109. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/rink_plot.py +245 -0
  110. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/app.py +145 -0
  111. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/plot.py +77 -0
  112. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/rink_plot.py +245 -0
  113. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/app.py +389 -0
  114. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/plot.py +70 -0
  115. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/rink_plot.py +245 -0
  116. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/app.py +110 -0
  117. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/plot.py +58 -0
  118. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/rink_plot.py +245 -0
  119. wsba_hockey/tools/agg.py +243 -54
  120. wsba_hockey/tools/plotting.py +25 -25
  121. wsba_hockey/tools/scraping.py +154 -263
  122. wsba_hockey/tools/xg_model.py +369 -315
  123. wsba_hockey/workspace.py +22 -117
  124. wsba_hockey/wsba_main.py +499 -167
  125. {wsba_hockey-1.0.3.dist-info → wsba_hockey-1.0.5.dist-info}/METADATA +1 -1
  126. wsba_hockey-1.0.5.dist-info/RECORD +135 -0
  127. {wsba_hockey-1.0.3.dist-info → wsba_hockey-1.0.5.dist-info}/WHEEL +1 -1
  128. wsba_hockey/stats/calculate_viz/shot_impact.py +0 -2
  129. wsba_hockey-1.0.3.dist-info/RECORD +0 -19
  130. {wsba_hockey-1.0.3.dist-info → wsba_hockey-1.0.5.dist-info}/licenses/LICENSE +0 -0
  131. {wsba_hockey-1.0.3.dist-info → wsba_hockey-1.0.5.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,174 @@
1
+ # This file comes from
2
+ # https://github.com/martine/ninja/blob/master/misc/ninja_syntax.py
3
+ # Do not edit! Edit the upstream one instead.
4
+
5
+ """Python module for generating .ninja files.
6
+
7
+ Note that this is emphatically not a required piece of Ninja; it's
8
+ just a helpful utility for build-file-generation systems that already
9
+ use Python.
10
+ """
11
+
12
+ import textwrap
13
+
14
+
15
+ def escape_path(word):
16
+ return word.replace("$ ", "$$ ").replace(" ", "$ ").replace(":", "$:")
17
+
18
+
19
+ class Writer:
20
+ def __init__(self, output, width=78):
21
+ self.output = output
22
+ self.width = width
23
+
24
+ def newline(self):
25
+ self.output.write("\n")
26
+
27
+ def comment(self, text):
28
+ for line in textwrap.wrap(text, self.width - 2):
29
+ self.output.write("# " + line + "\n")
30
+
31
+ def variable(self, key, value, indent=0):
32
+ if value is None:
33
+ return
34
+ if isinstance(value, list):
35
+ value = " ".join(filter(None, value)) # Filter out empty strings.
36
+ self._line(f"{key} = {value}", indent)
37
+
38
+ def pool(self, name, depth):
39
+ self._line("pool %s" % name)
40
+ self.variable("depth", depth, indent=1)
41
+
42
+ def rule(
43
+ self,
44
+ name,
45
+ command,
46
+ description=None,
47
+ depfile=None,
48
+ generator=False,
49
+ pool=None,
50
+ restat=False,
51
+ rspfile=None,
52
+ rspfile_content=None,
53
+ deps=None,
54
+ ):
55
+ self._line("rule %s" % name)
56
+ self.variable("command", command, indent=1)
57
+ if description:
58
+ self.variable("description", description, indent=1)
59
+ if depfile:
60
+ self.variable("depfile", depfile, indent=1)
61
+ if generator:
62
+ self.variable("generator", "1", indent=1)
63
+ if pool:
64
+ self.variable("pool", pool, indent=1)
65
+ if restat:
66
+ self.variable("restat", "1", indent=1)
67
+ if rspfile:
68
+ self.variable("rspfile", rspfile, indent=1)
69
+ if rspfile_content:
70
+ self.variable("rspfile_content", rspfile_content, indent=1)
71
+ if deps:
72
+ self.variable("deps", deps, indent=1)
73
+
74
+ def build(
75
+ self, outputs, rule, inputs=None, implicit=None, order_only=None, variables=None
76
+ ):
77
+ outputs = self._as_list(outputs)
78
+ all_inputs = self._as_list(inputs)[:]
79
+ out_outputs = list(map(escape_path, outputs))
80
+ all_inputs = list(map(escape_path, all_inputs))
81
+
82
+ if implicit:
83
+ implicit = map(escape_path, self._as_list(implicit))
84
+ all_inputs.append("|")
85
+ all_inputs.extend(implicit)
86
+ if order_only:
87
+ order_only = map(escape_path, self._as_list(order_only))
88
+ all_inputs.append("||")
89
+ all_inputs.extend(order_only)
90
+
91
+ self._line(
92
+ "build {}: {}".format(" ".join(out_outputs), " ".join([rule] + all_inputs))
93
+ )
94
+
95
+ if variables:
96
+ if isinstance(variables, dict):
97
+ iterator = iter(variables.items())
98
+ else:
99
+ iterator = iter(variables)
100
+
101
+ for key, val in iterator:
102
+ self.variable(key, val, indent=1)
103
+
104
+ return outputs
105
+
106
+ def include(self, path):
107
+ self._line("include %s" % path)
108
+
109
+ def subninja(self, path):
110
+ self._line("subninja %s" % path)
111
+
112
+ def default(self, paths):
113
+ self._line("default %s" % " ".join(self._as_list(paths)))
114
+
115
+ def _count_dollars_before_index(self, s, i):
116
+ """Returns the number of '$' characters right in front of s[i]."""
117
+ dollar_count = 0
118
+ dollar_index = i - 1
119
+ while dollar_index > 0 and s[dollar_index] == "$":
120
+ dollar_count += 1
121
+ dollar_index -= 1
122
+ return dollar_count
123
+
124
+ def _line(self, text, indent=0):
125
+ """Write 'text' word-wrapped at self.width characters."""
126
+ leading_space = " " * indent
127
+ while len(leading_space) + len(text) > self.width:
128
+ # The text is too wide; wrap if possible.
129
+
130
+ # Find the rightmost space that would obey our width constraint and
131
+ # that's not an escaped space.
132
+ available_space = self.width - len(leading_space) - len(" $")
133
+ space = available_space
134
+ while True:
135
+ space = text.rfind(" ", 0, space)
136
+ if space < 0 or self._count_dollars_before_index(text, space) % 2 == 0:
137
+ break
138
+
139
+ if space < 0:
140
+ # No such space; just use the first unescaped space we can find.
141
+ space = available_space - 1
142
+ while True:
143
+ space = text.find(" ", space + 1)
144
+ if (
145
+ space < 0
146
+ or self._count_dollars_before_index(text, space) % 2 == 0
147
+ ):
148
+ break
149
+ if space < 0:
150
+ # Give up on breaking.
151
+ break
152
+
153
+ self.output.write(leading_space + text[0:space] + " $\n")
154
+ text = text[space + 1 :]
155
+
156
+ # Subsequent lines are continuations, so indent them.
157
+ leading_space = " " * (indent + 2)
158
+
159
+ self.output.write(leading_space + text + "\n")
160
+
161
+ def _as_list(self, input):
162
+ if input is None:
163
+ return []
164
+ if isinstance(input, list):
165
+ return input
166
+ return [input]
167
+
168
+
169
+ def escape(string):
170
+ """Escape a string such that it can be embedded into a Ninja file without
171
+ further interpretation."""
172
+ assert "\n" not in string, "Ninja syntax does not allow newlines"
173
+ # We only have one special metacharacter: '$'.
174
+ return string.replace("$", "$$")
@@ -0,0 +1,61 @@
1
+ # Copyright 2014 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
+ """A clone of the default copy.deepcopy that doesn't handle cyclic
6
+ structures or complex types except for dicts and lists. This is
7
+ because gyp copies so large structure that small copy overhead ends up
8
+ taking seconds in a project the size of Chromium."""
9
+
10
+
11
+ class Error(Exception):
12
+ pass
13
+
14
+
15
+ __all__ = ["Error", "deepcopy"]
16
+
17
+
18
+ def deepcopy(x):
19
+ """Deep copy operation on gyp objects such as strings, ints, dicts
20
+ and lists. More than twice as fast as copy.deepcopy but much less
21
+ generic."""
22
+
23
+ try:
24
+ return _deepcopy_dispatch[type(x)](x)
25
+ except KeyError:
26
+ raise Error(
27
+ "Unsupported type %s for deepcopy. Use copy.deepcopy "
28
+ + "or expand simple_copy support." % type(x)
29
+ )
30
+
31
+
32
+ _deepcopy_dispatch = d = {}
33
+
34
+
35
+ def _deepcopy_atomic(x):
36
+ return x
37
+
38
+
39
+ types = bool, float, int, str, type, type(None)
40
+
41
+ for x in types:
42
+ d[x] = _deepcopy_atomic
43
+
44
+
45
+ def _deepcopy_list(x):
46
+ return [deepcopy(a) for a in x]
47
+
48
+
49
+ d[list] = _deepcopy_list
50
+
51
+
52
+ def _deepcopy_dict(x):
53
+ y = {}
54
+ for key, value in x.items():
55
+ y[deepcopy(key)] = deepcopy(value)
56
+ return y
57
+
58
+
59
+ d[dict] = _deepcopy_dict
60
+
61
+ del d
@@ -0,0 +1,374 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # Copyright (c) 2012 Google Inc. All rights reserved.
4
+ # Use of this source code is governed by a BSD-style license that can be
5
+ # found in the LICENSE file.
6
+
7
+ """Utility functions for Windows builds.
8
+
9
+ These functions are executed via gyp-win-tool when using the ninja generator.
10
+ """
11
+
12
+
13
+ import os
14
+ import re
15
+ import shutil
16
+ import subprocess
17
+ import stat
18
+ import string
19
+ import sys
20
+
21
+ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
22
+
23
+ # A regex matching an argument corresponding to the output filename passed to
24
+ # link.exe.
25
+ _LINK_EXE_OUT_ARG = re.compile("/OUT:(?P<out>.+)$", re.IGNORECASE)
26
+
27
+
28
+ def main(args):
29
+ executor = WinTool()
30
+ exit_code = executor.Dispatch(args)
31
+ if exit_code is not None:
32
+ sys.exit(exit_code)
33
+
34
+
35
+ class WinTool:
36
+ """This class performs all the Windows tooling steps. The methods can either
37
+ be executed directly, or dispatched from an argument list."""
38
+
39
+ def _UseSeparateMspdbsrv(self, env, args):
40
+ """Allows to use a unique instance of mspdbsrv.exe per linker instead of a
41
+ shared one."""
42
+ if len(args) < 1:
43
+ raise Exception("Not enough arguments")
44
+
45
+ if args[0] != "link.exe":
46
+ return
47
+
48
+ # Use the output filename passed to the linker to generate an endpoint name
49
+ # for mspdbsrv.exe.
50
+ endpoint_name = None
51
+ for arg in args:
52
+ m = _LINK_EXE_OUT_ARG.match(arg)
53
+ if m:
54
+ endpoint_name = re.sub(
55
+ r"\W+", "", "%s_%d" % (m.group("out"), os.getpid())
56
+ )
57
+ break
58
+
59
+ if endpoint_name is None:
60
+ return
61
+
62
+ # Adds the appropriate environment variable. This will be read by link.exe
63
+ # to know which instance of mspdbsrv.exe it should connect to (if it's
64
+ # not set then the default endpoint is used).
65
+ env["_MSPDBSRV_ENDPOINT_"] = endpoint_name
66
+
67
+ def Dispatch(self, args):
68
+ """Dispatches a string command to a method."""
69
+ if len(args) < 1:
70
+ raise Exception("Not enough arguments")
71
+
72
+ method = "Exec%s" % self._CommandifyName(args[0])
73
+ return getattr(self, method)(*args[1:])
74
+
75
+ def _CommandifyName(self, name_string):
76
+ """Transforms a tool name like recursive-mirror to RecursiveMirror."""
77
+ return name_string.title().replace("-", "")
78
+
79
+ def _GetEnv(self, arch):
80
+ """Gets the saved environment from a file for a given architecture."""
81
+ # The environment is saved as an "environment block" (see CreateProcess
82
+ # and msvs_emulation for details). We convert to a dict here.
83
+ # Drop last 2 NULs, one for list terminator, one for trailing vs. separator.
84
+ pairs = open(arch).read()[:-2].split("\0")
85
+ kvs = [item.split("=", 1) for item in pairs]
86
+ return dict(kvs)
87
+
88
+ def ExecStamp(self, path):
89
+ """Simple stamp command."""
90
+ open(path, "w").close()
91
+
92
+ def ExecRecursiveMirror(self, source, dest):
93
+ """Emulation of rm -rf out && cp -af in out."""
94
+ if os.path.exists(dest):
95
+ if os.path.isdir(dest):
96
+
97
+ def _on_error(fn, path, excinfo):
98
+ # The operation failed, possibly because the file is set to
99
+ # read-only. If that's why, make it writable and try the op again.
100
+ if not os.access(path, os.W_OK):
101
+ os.chmod(path, stat.S_IWRITE)
102
+ fn(path)
103
+
104
+ shutil.rmtree(dest, onerror=_on_error)
105
+ else:
106
+ if not os.access(dest, os.W_OK):
107
+ # Attempt to make the file writable before deleting it.
108
+ os.chmod(dest, stat.S_IWRITE)
109
+ os.unlink(dest)
110
+
111
+ if os.path.isdir(source):
112
+ shutil.copytree(source, dest)
113
+ else:
114
+ shutil.copy2(source, dest)
115
+
116
+ def ExecLinkWrapper(self, arch, use_separate_mspdbsrv, *args):
117
+ """Filter diagnostic output from link that looks like:
118
+ ' Creating library ui.dll.lib and object ui.dll.exp'
119
+ This happens when there are exports from the dll or exe.
120
+ """
121
+ env = self._GetEnv(arch)
122
+ if use_separate_mspdbsrv == "True":
123
+ self._UseSeparateMspdbsrv(env, args)
124
+ if sys.platform == "win32":
125
+ args = list(args) # *args is a tuple by default, which is read-only.
126
+ args[0] = args[0].replace("/", "\\")
127
+ # https://docs.python.org/2/library/subprocess.html:
128
+ # "On Unix with shell=True [...] if args is a sequence, the first item
129
+ # specifies the command string, and any additional items will be treated as
130
+ # additional arguments to the shell itself. That is to say, Popen does the
131
+ # equivalent of:
132
+ # Popen(['/bin/sh', '-c', args[0], args[1], ...])"
133
+ # For that reason, since going through the shell doesn't seem necessary on
134
+ # non-Windows don't do that there.
135
+ link = subprocess.Popen(
136
+ args,
137
+ shell=sys.platform == "win32",
138
+ env=env,
139
+ stdout=subprocess.PIPE,
140
+ stderr=subprocess.STDOUT,
141
+ )
142
+ out = link.communicate()[0].decode("utf-8")
143
+ for line in out.splitlines():
144
+ if (
145
+ not line.startswith(" Creating library ")
146
+ and not line.startswith("Generating code")
147
+ and not line.startswith("Finished generating code")
148
+ ):
149
+ print(line)
150
+ return link.returncode
151
+
152
+ def ExecLinkWithManifests(
153
+ self,
154
+ arch,
155
+ embed_manifest,
156
+ out,
157
+ ldcmd,
158
+ resname,
159
+ mt,
160
+ rc,
161
+ intermediate_manifest,
162
+ *manifests
163
+ ):
164
+ """A wrapper for handling creating a manifest resource and then executing
165
+ a link command."""
166
+ # The 'normal' way to do manifests is to have link generate a manifest
167
+ # based on gathering dependencies from the object files, then merge that
168
+ # manifest with other manifests supplied as sources, convert the merged
169
+ # manifest to a resource, and then *relink*, including the compiled
170
+ # version of the manifest resource. This breaks incremental linking, and
171
+ # is generally overly complicated. Instead, we merge all the manifests
172
+ # provided (along with one that includes what would normally be in the
173
+ # linker-generated one, see msvs_emulation.py), and include that into the
174
+ # first and only link. We still tell link to generate a manifest, but we
175
+ # only use that to assert that our simpler process did not miss anything.
176
+ variables = {
177
+ "python": sys.executable,
178
+ "arch": arch,
179
+ "out": out,
180
+ "ldcmd": ldcmd,
181
+ "resname": resname,
182
+ "mt": mt,
183
+ "rc": rc,
184
+ "intermediate_manifest": intermediate_manifest,
185
+ "manifests": " ".join(manifests),
186
+ }
187
+ add_to_ld = ""
188
+ if manifests:
189
+ subprocess.check_call(
190
+ "%(python)s gyp-win-tool manifest-wrapper %(arch)s %(mt)s -nologo "
191
+ "-manifest %(manifests)s -out:%(out)s.manifest" % variables
192
+ )
193
+ if embed_manifest == "True":
194
+ subprocess.check_call(
195
+ "%(python)s gyp-win-tool manifest-to-rc %(arch)s %(out)s.manifest"
196
+ " %(out)s.manifest.rc %(resname)s" % variables
197
+ )
198
+ subprocess.check_call(
199
+ "%(python)s gyp-win-tool rc-wrapper %(arch)s %(rc)s "
200
+ "%(out)s.manifest.rc" % variables
201
+ )
202
+ add_to_ld = " %(out)s.manifest.res" % variables
203
+ subprocess.check_call(ldcmd + add_to_ld)
204
+
205
+ # Run mt.exe on the theoretically complete manifest we generated, merging
206
+ # it with the one the linker generated to confirm that the linker
207
+ # generated one does not add anything. This is strictly unnecessary for
208
+ # correctness, it's only to verify that e.g. /MANIFESTDEPENDENCY was not
209
+ # used in a #pragma comment.
210
+ if manifests:
211
+ # Merge the intermediate one with ours to .assert.manifest, then check
212
+ # that .assert.manifest is identical to ours.
213
+ subprocess.check_call(
214
+ "%(python)s gyp-win-tool manifest-wrapper %(arch)s %(mt)s -nologo "
215
+ "-manifest %(out)s.manifest %(intermediate_manifest)s "
216
+ "-out:%(out)s.assert.manifest" % variables
217
+ )
218
+ assert_manifest = "%(out)s.assert.manifest" % variables
219
+ our_manifest = "%(out)s.manifest" % variables
220
+ # Load and normalize the manifests. mt.exe sometimes removes whitespace,
221
+ # and sometimes doesn't unfortunately.
222
+ with open(our_manifest) as our_f:
223
+ with open(assert_manifest) as assert_f:
224
+ translator = str.maketrans('', '', string.whitespace)
225
+ our_data = our_f.read().translate(translator)
226
+ assert_data = assert_f.read().translate(translator)
227
+ if our_data != assert_data:
228
+ os.unlink(out)
229
+
230
+ def dump(filename):
231
+ print(filename, file=sys.stderr)
232
+ print("-----", file=sys.stderr)
233
+ with open(filename) as f:
234
+ print(f.read(), file=sys.stderr)
235
+ print("-----", file=sys.stderr)
236
+
237
+ dump(intermediate_manifest)
238
+ dump(our_manifest)
239
+ dump(assert_manifest)
240
+ sys.stderr.write(
241
+ 'Linker generated manifest "%s" added to final manifest "%s" '
242
+ '(result in "%s"). '
243
+ "Were /MANIFEST switches used in #pragma statements? "
244
+ % (intermediate_manifest, our_manifest, assert_manifest)
245
+ )
246
+ return 1
247
+
248
+ def ExecManifestWrapper(self, arch, *args):
249
+ """Run manifest tool with environment set. Strip out undesirable warning
250
+ (some XML blocks are recognized by the OS loader, but not the manifest
251
+ tool)."""
252
+ env = self._GetEnv(arch)
253
+ popen = subprocess.Popen(
254
+ args, shell=True, env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
255
+ )
256
+ out = popen.communicate()[0].decode("utf-8")
257
+ for line in out.splitlines():
258
+ if line and "manifest authoring warning 81010002" not in line:
259
+ print(line)
260
+ return popen.returncode
261
+
262
+ def ExecManifestToRc(self, arch, *args):
263
+ """Creates a resource file pointing a SxS assembly manifest.
264
+ |args| is tuple containing path to resource file, path to manifest file
265
+ and resource name which can be "1" (for executables) or "2" (for DLLs)."""
266
+ manifest_path, resource_path, resource_name = args
267
+ with open(resource_path, "w") as output:
268
+ output.write(
269
+ '#include <windows.h>\n%s RT_MANIFEST "%s"'
270
+ % (resource_name, os.path.abspath(manifest_path).replace("\\", "/"))
271
+ )
272
+
273
+ def ExecMidlWrapper(self, arch, outdir, tlb, h, dlldata, iid, proxy, idl, *flags):
274
+ """Filter noisy filenames output from MIDL compile step that isn't
275
+ quietable via command line flags.
276
+ """
277
+ args = (
278
+ ["midl", "/nologo"]
279
+ + list(flags)
280
+ + [
281
+ "/out",
282
+ outdir,
283
+ "/tlb",
284
+ tlb,
285
+ "/h",
286
+ h,
287
+ "/dlldata",
288
+ dlldata,
289
+ "/iid",
290
+ iid,
291
+ "/proxy",
292
+ proxy,
293
+ idl,
294
+ ]
295
+ )
296
+ env = self._GetEnv(arch)
297
+ popen = subprocess.Popen(
298
+ args, shell=True, env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
299
+ )
300
+ out = popen.communicate()[0].decode("utf-8")
301
+ # Filter junk out of stdout, and write filtered versions. Output we want
302
+ # to filter is pairs of lines that look like this:
303
+ # Processing C:\Program Files (x86)\Microsoft SDKs\...\include\objidl.idl
304
+ # objidl.idl
305
+ lines = out.splitlines()
306
+ prefixes = ("Processing ", "64 bit Processing ")
307
+ processing = {os.path.basename(x) for x in lines if x.startswith(prefixes)}
308
+ for line in lines:
309
+ if not line.startswith(prefixes) and line not in processing:
310
+ print(line)
311
+ return popen.returncode
312
+
313
+ def ExecAsmWrapper(self, arch, *args):
314
+ """Filter logo banner from invocations of asm.exe."""
315
+ env = self._GetEnv(arch)
316
+ popen = subprocess.Popen(
317
+ args, shell=True, env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
318
+ )
319
+ out = popen.communicate()[0].decode("utf-8")
320
+ for line in out.splitlines():
321
+ if (
322
+ not line.startswith("Copyright (C) Microsoft Corporation")
323
+ and not line.startswith("Microsoft (R) Macro Assembler")
324
+ and not line.startswith(" Assembling: ")
325
+ and line
326
+ ):
327
+ print(line)
328
+ return popen.returncode
329
+
330
+ def ExecRcWrapper(self, arch, *args):
331
+ """Filter logo banner from invocations of rc.exe. Older versions of RC
332
+ don't support the /nologo flag."""
333
+ env = self._GetEnv(arch)
334
+ popen = subprocess.Popen(
335
+ args, shell=True, env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
336
+ )
337
+ out = popen.communicate()[0].decode("utf-8")
338
+ for line in out.splitlines():
339
+ if (
340
+ not line.startswith("Microsoft (R) Windows (R) Resource Compiler")
341
+ and not line.startswith("Copyright (C) Microsoft Corporation")
342
+ and line
343
+ ):
344
+ print(line)
345
+ return popen.returncode
346
+
347
+ def ExecActionWrapper(self, arch, rspfile, *dir):
348
+ """Runs an action command line from a response file using the environment
349
+ for |arch|. If |dir| is supplied, use that as the working directory."""
350
+ env = self._GetEnv(arch)
351
+ # TODO(scottmg): This is a temporary hack to get some specific variables
352
+ # through to actions that are set after gyp-time. http://crbug.com/333738.
353
+ for k, v in os.environ.items():
354
+ if k not in env:
355
+ env[k] = v
356
+ args = open(rspfile).read()
357
+ dir = dir[0] if dir else None
358
+ return subprocess.call(args, shell=True, env=env, cwd=dir)
359
+
360
+ def ExecClCompile(self, project_dir, selected_files):
361
+ """Executed by msvs-ninja projects when the 'ClCompile' target is used to
362
+ build selected C/C++ files."""
363
+ project_dir = os.path.relpath(project_dir, BASE_DIR)
364
+ selected_files = selected_files.split(";")
365
+ ninja_targets = [
366
+ os.path.join(project_dir, filename) + "^^" for filename in selected_files
367
+ ]
368
+ cmd = ["ninja.exe"]
369
+ cmd.extend(ninja_targets)
370
+ return subprocess.call(cmd, shell=True, cwd=BASE_DIR)
371
+
372
+
373
+ if __name__ == "__main__":
374
+ sys.exit(main(sys.argv[1:]))