Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
263 lines (204 loc) · 9.85 KB

File metadata and controls

263 lines (204 loc) · 9.85 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/usr/bin/env python3
#
## Licensed to the .NET Foundation under one or more agreements.
## The .NET Foundation licenses this file to you under the MIT license.
#
##
# Title :jitformat.py
#
################################################################################
# Script to install and run jit-format over jit source for all configurations.
################################################################################
import argparse
import jitutil
import logging
import os
import shutil
import subprocess
import sys
import tarfile
import tempfile
import zipfile
class ChangeDir:
def __init__(self, dir):
self.dir = dir
self.cwd = None
def __enter__(self):
self.cwd = os.getcwd()
os.chdir(self.dir)
def __exit__(self, exc_type, exc_val, exc_tb):
os.chdir(self.cwd)
class TempDir:
def __init__(self, path=None):
self.dir = tempfile.mkdtemp() if path is None else path
self.cwd = None
def __enter__(self):
self.cwd = os.getcwd()
os.chdir(self.dir)
return self.dir
def __exit__(self, exc_type, exc_val, exc_tb):
os.chdir(self.cwd)
def expandPath(path):
return os.path.abspath(os.path.expanduser(path))
def del_rw(action, name, exc):
os.chmod(name, 0o651)
os.remove(name)
def cleanup(jitUtilsPath, bootstrapPath):
if os.path.isdir(jitUtilsPath):
logging.info("Deleting " + jitUtilsPath)
shutil.rmtree(jitUtilsPath, onerror=del_rw)
if os.path.isfile(bootstrapPath):
logging.info("Deleting " + bootstrapPath)
os.remove(bootstrapPath)
def main(argv):
logging.basicConfig(format="[%(asctime)s] %(message)s", datefmt="%H:%M:%S")
logger = logging.getLogger()
logger.setLevel(logging.INFO)
parser = argparse.ArgumentParser()
required = parser.add_argument_group('required arguments')
required.add_argument('-a', '--arch', type=str,
default=None, help='architecture to run jit-format on')
required.add_argument('-o', '--os', type=str,
default=None, help='operating system')
required.add_argument('-c', '--coreclr', type=str,
default=None, help='full path to coreclr')
args, unknown = parser.parse_known_args(argv)
if unknown:
logging.warn('Ignoring argument(s): {}'.format(','.join(unknown)))
if args.coreclr is None:
logging.error('Specify --coreclr')
return -1
if args.os is None:
logging.error('Specify --os')
return -1
if args.arch is None:
logging.error('Specify --arch')
return -1
if not os.path.isdir(expandPath(args.coreclr)):
logging.error('Bad path to coreclr')
return -1
coreclr = args.coreclr.replace('/', os.sep)
platform = args.os
arch = args.arch
my_env = os.environ
# Download formatting tools
repoRoot = os.path.dirname(os.path.dirname(coreclr))
formattingScriptFolder = os.path.join(repoRoot, "eng", "formatting")
formattingDownloadScriptCommand = []
if platform == 'linux' or platform == 'osx':
formattingDownloadScriptCommand = [os.path.join(formattingScriptFolder, "download-tools.sh")]
elif platform == 'windows':
formattingDownloadScriptCommand = ["powershell", os.path.join(formattingScriptFolder, "download-tools.ps1")]
proc = subprocess.Popen(formattingDownloadScriptCommand)
if proc.wait() != 0:
logging.error("Formatting tool download failed")
return -1
my_env["PATH"] = os.path.join(repoRoot, "artifacts", "tools") + os.pathsep + my_env["PATH"]
# Download bootstrap
bootstrapFilename = ""
jitUtilsPath = os.path.join(coreclr, "jitutils")
cleanup(jitUtilsPath, '')
if platform == 'linux' or platform == 'osx':
bootstrapFilename = "bootstrap.sh"
elif platform == 'windows':
bootstrapFilename = "bootstrap.cmd"
bootstrapUrl = "https://raw.githubusercontent.com/dotnet/jitutils/main/" + bootstrapFilename
with TempDir() as temp_location:
bootstrapPath = os.path.join(temp_location, bootstrapFilename)
assert len(os.listdir(os.path.dirname(bootstrapPath))) == 0
if not jitutil.download_one_url(bootstrapUrl, bootstrapPath):
logging.error("Did not download bootstrap!")
return -1
if platform == 'windows':
# Need to ensure we have Windows line endings on the downloaded script file,
# which is downloaded with Unix line endings.
logging.info('Convert {} to Windows line endings'.format(bootstrapPath))
content = None
with open(bootstrapPath, 'rb') as open_file:
content = open_file.read()
content = content.replace(b'\n', b'\r\n')
with open(bootstrapPath, 'wb') as open_file:
open_file.write(content)
# On *nix platforms, we need to make the bootstrap file executable
if platform == 'linux' or platform == 'osx':
logging.info("Making bootstrap executable")
os.chmod(bootstrapPath, 0o751)
# Run bootstrap
if platform == 'linux' or platform == 'osx':
logging.info('Running: bash {}'.format(bootstrapPath))
proc = subprocess.Popen(['bash', bootstrapPath], env=my_env)
output,error = proc.communicate()
elif platform == 'windows':
logging.info('Running: {}'.format(bootstrapPath))
proc = subprocess.Popen([bootstrapPath], env=my_env)
output,error = proc.communicate()
if proc.returncode != 0:
cleanup('', bootstrapPath)
logging.error("Bootstrap failed")
return -1
# Run jit-format
returncode = 0
jitutilsBin = os.path.join(os.path.dirname(bootstrapPath), "jitutils", "bin")
my_env["PATH"] = jitutilsBin + os.pathsep + my_env["PATH"]
if not os.path.isdir(jitutilsBin):
logging.error("Jitutils not built!")
return -1
jitformat = jitutilsBin
if platform == 'linux' or platform == 'osx':
jitformat = os.path.join(jitformat, "jit-format")
elif platform == 'windows':
jitformat = os.path.join(jitformat,"jit-format.exe")
errorMessage = ""
builds = ["Checked", "Debug", "Release"]
projects = ["dll", "standalone", "crossgen"]
for build in builds:
for project in projects:
command = jitformat + " -a " + arch + " -b " + build + " -o " + platform + " -c " + coreclr + " --verbose --projects " + project
logging.info('Running: {}'.format(command))
proc = subprocess.Popen([jitformat, "-a", arch, "-b", build, "-o", platform, "-c", coreclr, "--verbose", "--projects", project], env=my_env)
output,error = proc.communicate()
errorcode = proc.returncode
if errorcode != 0:
errorMessage += "\tjit-format -a " + arch + " -b " + build + " -o " + platform
errorMessage += " -c <absolute-path-to-coreclr> --verbose --fix --projects " + project +"\n"
returncode = errorcode
# Fix mode doesn't return an error, so we have to run the build, then run with
# --fix to generate the patch. This means that it is likely only the first run
# of jit-format will return a formatting failure.
if errorcode == -2:
# If errorcode was -2, no need to run clang-tidy again
proc = subprocess.Popen([jitformat, "--fix", "--untidy", "-a", arch, "-b", build, "-o", platform, "-c", coreclr, "--verbose", "--projects", project], env=my_env)
output,error = proc.communicate()
else:
# Otherwise, must run both
proc = subprocess.Popen([jitformat, "--fix", "-a", arch, "-b", build, "-o", platform, "-c", coreclr, "--verbose", "--projects", project], env=my_env)
output,error = proc.communicate()
patchFilePath = os.path.join(coreclr, "format.patch")
if returncode != 0:
# Create a patch file
logging.info("Creating patch file {}".format(patchFilePath))
jitSrcPath = os.path.join(coreclr, "jit")
patchFile = open(patchFilePath, "w")
proc = subprocess.Popen(["git", "diff", "--patch", "-U20", "--", jitSrcPath], env=my_env, stdout=patchFile)
output,error = proc.communicate()
cleanup(jitUtilsPath, bootstrapPath)
if returncode != 0:
logging.info("There were errors in formatting. Please run jit-format locally with: \n")
logging.info(errorMessage)
logging.info("\nOr download and apply generated patch:")
logging.info("1. From the GitHub 'Checks' page on the Pull Request, with the failing Formatting")
logging.info(" job selected (e.g., 'Formatting Linux x64'), click the 'View more details on")
logging.info(" Azure Pipelines' link.")
logging.info("2. Select the '1 artifact produced' at the end of the log.")
logging.info("3. Artifacts are located in alphabetical order, target artifact name is")
logging.info(" 'format.<OS>.<architecture>.patch.'. Find appropriate format patch artifact.")
logging.info("4. On the right side of the artifact there is a 'More actions' menu shown by a")
logging.info(" vertical three-dot symbol. Click on it and select 'Download artifacts' option.")
logging.info("5. Unzip the patch file.")
logging.info("6. git apply format.patch")
if (returncode != 0) and (os.environ.get("TF_BUILD") == "True"):
print("##vso[task.logissue type=error](NETCORE_ENGINEERING_TELEMETRY=Build) Format job found errors, please apply the format patch.")
return returncode
if __name__ == '__main__':
return_code = main(sys.argv[1:])
sys.exit(return_code)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.