43
43
import time
44
44
import unittest
45
45
import webbrowser
46
+ from pathlib import Path
46
47
from http .server import HTTPServer , SimpleHTTPRequestHandler
47
48
from urllib .parse import unquote , unquote_plus
48
49
65
66
66
67
def path_from_root (* pathelems ):
67
68
"""Construct a path relative to the emscripten root directory."""
68
- return os . path . join ( __rootpath__ , * pathelems )
69
+ return str ( Path ( __rootpath__ , * pathelems ) )
69
70
70
71
71
72
sys .path .append (path_from_root ('third_party/websockify' ))
@@ -111,7 +112,7 @@ def delete_contents(pathname):
111
112
112
113
def test_file (* path_components ):
113
114
"""Construct a path relative to the emscripten "tests" directory."""
114
- return os . path . join ( TEST_ROOT , * path_components )
115
+ return str ( Path ( TEST_ROOT , * path_components ) )
115
116
116
117
117
118
# checks if browser testing is enabled
@@ -241,8 +242,8 @@ def modified(self):
241
242
242
243
243
244
def ensure_dir (dirname ):
244
- if not os . path . isdir (dirname ):
245
- os . makedirs ( dirname )
245
+ dirname = Path (dirname )
246
+ dirname . mkdir ( parents = True , exist_ok = True )
246
247
247
248
248
249
def limit_size (string , maxbytes = 800000 * 20 , maxlines = 100000 , max_line = 5000 ):
@@ -259,14 +260,16 @@ def limit_size(string, maxbytes=800000 * 20, maxlines=100000, max_line=5000):
259
260
260
261
261
262
def create_file (name , contents , binary = False ):
262
- assert not os .path .isabs (name )
263
- mode = 'wb' if binary else 'w'
264
- with open (name , mode ) as f :
265
- f .write (contents )
263
+ name = Path (name )
264
+ assert not name .is_absolute ()
265
+ if binary :
266
+ name .write_bytes (contents )
267
+ else :
268
+ name .write_text (contents )
266
269
267
270
268
271
def make_executable (name ):
269
- os .chmod (name , stat .S_IREAD | stat .S_IWRITE | stat .S_IEXEC )
272
+ Path ( name ) .chmod (stat .S_IREAD | stat .S_IWRITE | stat .S_IEXEC )
270
273
271
274
272
275
# The core test modes
@@ -595,7 +598,7 @@ def build(self, filename, libraries=[], includes=[], force_c=False,
595
598
if shared .suffix (filename ) not in ('.i' , '.ii' ):
596
599
# Add the location of the test file to include path.
597
600
cmd += ['-I.' ]
598
- cmd += ['-I' + include for include in includes ]
601
+ cmd += ['-I' + str ( include ) for include in includes ]
599
602
600
603
self .run_process (cmd , stderr = self .stderr_redirect if not DEBUG else None )
601
604
self .assertExists (output )
@@ -1100,8 +1103,8 @@ def get_poppler_library(self, env_init=None):
1100
1103
self .set_setting ('ERROR_ON_UNDEFINED_SYMBOLS' , 0 )
1101
1104
1102
1105
self .emcc_args += [
1103
- '-I' + test_file ('third_party' , ' freetype' , ' include' ),
1104
- '-I' + test_file ('third_party' , ' poppler' , ' include' )
1106
+ '-I' + test_file ('third_party/ freetype/ include' ),
1107
+ '-I' + test_file ('third_party/ poppler/ include' )
1105
1108
]
1106
1109
1107
1110
freetype = self .get_freetype_library ()
@@ -1613,10 +1616,11 @@ def build_library(name,
1613
1616
generated_libs = [generated_libs ]
1614
1617
source_dir = test_file (name .replace ('_native' , '' ))
1615
1618
1616
- project_dir = os . path . join (build_dir , name )
1619
+ project_dir = Path (build_dir , name )
1617
1620
if os .path .exists (project_dir ):
1618
1621
shutil .rmtree (project_dir )
1619
- shutil .copytree (source_dir , project_dir ) # Useful in debugging sometimes to comment this out, and two lines above
1622
+ # Useful in debugging sometimes to comment this out, and two lines above
1623
+ shutil .copytree (source_dir , project_dir )
1620
1624
1621
1625
generated_libs = [os .path .join (project_dir , lib ) for lib in generated_libs ]
1622
1626
if native :
0 commit comments