[infra] Workaround dart format hang on Windows

https://github.com/dart-lang/sdk/issues/46947

Change-Id: Ia632fbc73627504f96ef06fa99fff1f343ef6698
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212047
Reviewed-by: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
Alexander Thomas
2021-09-01 11:09:57 +00:00
parent c13b0bbe97
commit 588180725b
+18 -1
View File
@@ -14,6 +14,7 @@ import os.path
from typing import Callable
import scm
import subprocess
import tempfile
import platform
USE_PYTHON3 = True
@@ -139,7 +140,23 @@ def _CheckDartFormat(input_api, output_api):
'--output=none',
'--summary=none',
]
if contents:
# TODO(https://github.com/dart-lang/sdk/issues/46947): Remove this hack.
if windows and contents:
f = tempfile.NamedTemporaryFile(
encoding='utf-8',
delete=False,
mode='w',
suffix='.dart',
)
try:
f.write(contents)
f.close()
args.append(f.name)
process = subprocess.run(args)
finally:
os.unlink(f.name)
elif contents:
process = subprocess.run(args, input=contents, text=True)
else:
args.append(filename)