Skip to content

Commit 759dade

Browse files
authored
Avoid overwriting idendtical files when installing headers (emscripten-core#18524)
I noticed this suspicious flake on one of the bots and I think this should fix it: ``` In file included from /b/s/w/ir/x/w/install/emscripten/test/sqlite/benchmark.c:11: /b/s/w/ir/x/w/install/emscripten/cache/sysroot/include/sqlite3.h:10539:2: error: unterminated conditional directive ^ 1 error generated. ```
1 parent 2e2ea41 commit 759dade

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

test/test_other.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2026,7 +2026,7 @@ def test_libpng(self):
20262026
emcc_args=['--embed-file', 'pngtest.png', '-sUSE_LIBPNG'])
20272027

20282028
@node_pthreads
2029-
def test_zzz_libpng_with_pthreads(self):
2029+
def test_libpng_with_pthreads(self):
20302030
shutil.copyfile(test_file('third_party/libpng/pngtest.png'), 'pngtest.png')
20312031
self.do_runf(test_file('third_party/libpng/pngtest.c'), 'libpng passes test',
20322032
emcc_args=['--embed-file', 'pngtest.png', '-sUSE_LIBPNG', '-sUSE_PTHREADS'])

tools/ports/__init__.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ def dir_is_newer(dir_a, dir_b):
7979
return newest_a[1] > newest_b[1]
8080

8181

82+
def maybe_copy(src, dest):
83+
"""Just like shutil.copyfile, but will do nothing if the destination already
84+
exists and has the same contents as the source.
85+
86+
In the case where a library is built in multiple different configurations,
87+
we want to avoids racing between processes that are reading headers (without
88+
holding the cache lock) (e.g. normal compile steps) and a process that is
89+
building/installing a new flavor of a given library. In this case the
90+
headers will be "re-installed" but we skip the actual filesystem mods
91+
to avoid racing with other processes that might be reading these files.
92+
"""
93+
if os.path.exists(dest) and utils.read_file(src) == utils.read_file(dest):
94+
return
95+
shutil.copyfile(src, dest)
96+
97+
8298
class Ports:
8399
"""emscripten-ports library management (https://github.com/emscripten-ports).
84100
"""
@@ -110,7 +126,7 @@ def install_headers(src_dir, pattern='*.h', target=None):
110126
assert matches, f'no headers found to install in {src_dir}'
111127
for f in matches:
112128
logger.debug('installing: ' + os.path.join(dest, os.path.basename(f)))
113-
shutil.copyfile(f, os.path.join(dest, os.path.basename(f)))
129+
maybe_copy(f, os.path.join(dest, os.path.basename(f)))
114130

115131
@staticmethod
116132
def build_port(src_dir, output_path, port_name, includes=[], flags=[], cxxflags=[], exclude_files=[], exclude_dirs=[], srcs=[]): # noqa

0 commit comments

Comments
 (0)