Skip to content

Commit e9caf13

Browse files
committed
Experimental support for bulding system libraries via ninja
The primary advantage of doing this is that it avoids having force a completely rebuild of a system library when you want to rebuilt it. Instead not have precise dependencies.
1 parent 28f9210 commit e9caf13

13 files changed

+192
-46
lines changed

embuilder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def main():
237237
if do_clear:
238238
library.erase()
239239
if do_build:
240-
library.get_path()
240+
library.build()
241241
elif what == 'sysroot':
242242
if do_clear:
243243
shared.Cache.erase_file('sysroot_install.stamp')

tools/cache.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ def get_lib_dir(self, absolute, varies=True):
108108
path = Path(path, '-'.join(subdir))
109109
return path
110110

111-
def get_lib_name(self, name, varies=True):
112-
return str(self.get_lib_dir(absolute=False, varies=varies).joinpath(name))
111+
def get_lib_name(self, name, varies=True, absolute=False):
112+
return str(self.get_lib_dir(absolute=absolute, varies=varies).joinpath(name))
113113

114114
def erase_lib(self, name):
115115
self.erase_file(self.get_lib_name(name))
@@ -127,7 +127,7 @@ def get_lib(self, libname, *args, **kwargs):
127127

128128
# Request a cached file. If it isn't in the cache, it will be created with
129129
# the given creator function
130-
def get(self, shortname, creator, what=None, force=False):
130+
def get(self, shortname, creator, what=None, force=False, quiet=False):
131131
cachename = Path(self.dirname, shortname)
132132
# Check for existence before taking the lock in case we can avoid the
133133
# lock completely.
@@ -152,6 +152,7 @@ def get(self, shortname, creator, what=None, force=False):
152152
utils.safe_ensure_dirs(cachename.parent)
153153
creator(str(cachename))
154154
assert cachename.exists()
155-
logger.info(' - ok')
155+
if not quiet:
156+
logger.info(' - ok')
156157

157158
return str(cachename)

tools/gen_struct_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def inspect_headers(headers, cflags):
246246
# TODO(sbc): If we can remove EM_EXCLUSIVE_CACHE_ACCESS then this would not longer be needed.
247247
shared.check_sanity()
248248

249-
compiler_rt = system_libs.Library.get_usable_variations()['libcompiler_rt'].get_path()
249+
compiler_rt = system_libs.Library.get_usable_variations()['libcompiler_rt'].build()
250250

251251
# Close all unneeded FDs.
252252
os.close(src_file[0])

tools/ports/__init__.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,28 @@ def build_port(src_dir, output_path, port_name, includes=[], flags=[], exclude_f
126126
for include in includes:
127127
cflags.append('-I' + include)
128128

129-
commands = []
130-
objects = []
131-
for src in srcs:
132-
relpath = os.path.relpath(src, src_dir)
133-
obj = os.path.join(build_dir, relpath) + '.o'
134-
dirname = os.path.dirname(obj)
135-
if not os.path.exists(dirname):
136-
os.makedirs(dirname)
137-
commands.append([shared.EMCC, '-c', src, '-o', obj] + cflags)
138-
objects.append(obj)
139-
140-
system_libs.run_build_commands(commands)
141-
system_libs.create_lib(output_path, objects)
129+
if system_libs.USE_NINJA:
130+
if not os.path.exists(build_dir):
131+
os.makedirs(build_dir)
132+
ninja_file = os.path.join(build_dir, 'build.ninja')
133+
system_libs.ensure_sysroot()
134+
system_libs.create_ninja_file(srcs, ninja_file, output_path, cflags=cflags)
135+
system_libs.run_ninja(build_dir)
136+
else:
137+
commands = []
138+
objects = []
139+
for src in srcs:
140+
relpath = os.path.relpath(src, src_dir)
141+
obj = os.path.join(build_dir, relpath) + '.o'
142+
dirname = os.path.dirname(obj)
143+
if not os.path.exists(dirname):
144+
os.makedirs(dirname)
145+
commands.append([shared.EMCC, '-c', src, '-o', obj] + cflags)
146+
objects.append(obj)
147+
148+
system_libs.run_build_commands(commands)
149+
system_libs.create_lib(output_path, objects)
150+
142151
return output_path
143152

144153
@staticmethod
@@ -274,6 +283,12 @@ def clear_project_build(name):
274283
utils.delete_dir(build_dir)
275284
return build_dir
276285

286+
@staticmethod
287+
def write_file(filename, contents):
288+
if os.path.exists(filename) and utils.read_file(filename) == contents:
289+
return
290+
utils.write_file(filename, contents)
291+
277292

278293
def dependency_order(port_list):
279294
# Perform topological sort of ports according to the dependency DAG

tools/ports/boost_headers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import logging
77
import os
8-
from pathlib import Path
98

109
TAG = '1.75.0'
1110
HASH = '8c38be1ebef1b8ada358ad6b7c9ec17f5e0a300e8085db3473a13e19712c95eeb3c3defacd3c53482eb96368987c4b022efa8da2aac2431a154e40153d3c3dcd'
@@ -31,7 +30,7 @@ def create(final):
3130
# this is needed as emscripted ports expect this, even if it is not used
3231
dummy_file = os.path.join(source_path, 'dummy.cpp')
3332
shared.safe_ensure_dirs(os.path.dirname(dummy_file))
34-
Path(dummy_file).write_text('static void dummy() {}')
33+
ports.write_file(dummy_file, 'static void dummy() {}')
3534

3635
ports.build_port(source_path, final, 'boost_headers', srcs=['dummy.cpp'])
3736

tools/ports/freetype.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# found in the LICENSE file.
55

66
import os
7-
from pathlib import Path
87

98
TAG = 'version_1'
109
HASH = '0d0b1280ba0501ad0a23cf1daa1f86821c722218b59432734d3087a89acd22aabd5c3e5e1269700dcd41e87073046e906060f167c032eb91a3ac8c5808a02783'
@@ -19,7 +18,7 @@ def get(ports, settings, shared):
1918

2019
def create(final):
2120
source_path = os.path.join(ports.get_dir(), 'freetype', 'FreeType-' + TAG)
22-
Path(source_path, 'include/ftconfig.h').write_text(ftconf_h)
21+
ports.write_file(os.path.join(source_path, 'include/ftconfig.h'), ftconf_h)
2322
ports.install_header_dir(os.path.join(source_path, 'include'),
2423
target=os.path.join('freetype2'))
2524

tools/ports/libjpeg.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import os
77
import logging
8-
from pathlib import Path
98

109
VERSION = '9c'
1110
HASH = 'b2affe9a1688bd49fc033f4682c4a242d4ee612f1affaef532f5adcb4602efc4433c4a52a4b3d69e7440ff1f6413b1b041b419bc90efd6d697999961a9a6afb7'
@@ -24,7 +23,7 @@ def get(ports, settings, shared):
2423
def create(final):
2524
logging.info('building port: libjpeg')
2625
source_path = os.path.join(ports.get_dir(), 'libjpeg', 'jpeg-9c')
27-
Path(source_path, 'jconfig.h').write_text(jconfig_h)
26+
ports.write_file(os.path.join(source_path, 'jconfig.h'), jconfig_h)
2827
ports.install_headers(source_path)
2928
excludes = [
3029
'ansi2knr.c', 'cjpeg.c', 'ckconfig.c', 'djpeg.c', 'example.c',

tools/ports/libmodplug.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import os
77
import logging
8-
from pathlib import Path
98

109
TAG = '11022021'
1110
HASH = 'f770031ad6c2152cbed8c8eab8edf2be1d27f9e74bc255a9930c17019944ee5fdda5308ea992c66a78af9fe1d8dca090f6c956910ce323f8728247c10e44036b'
@@ -25,7 +24,7 @@ def create(final):
2524
src_dir = os.path.join(source_path, 'src')
2625
libmodplug_path = os.path.join(src_dir, 'libmodplug')
2726

28-
Path(source_path, 'config.h').write_text(config_h)
27+
ports.write_file(os.path.join(source_path, 'config.h'), config_h)
2928

3029
flags = [
3130
'-Wno-deprecated-register',

tools/ports/libpng.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import os
77
import logging
8-
from pathlib import Path
98

109
TAG = '1.6.37'
1110
HASH = '2ce2b855af307ca92a6e053f521f5d262c36eb836b4810cb53c809aa3ea2dcc08f834aee0ffd66137768a54397e28e92804534a74abb6fc9f6f3127f14c9c338'
@@ -30,7 +29,7 @@ def create(final):
3029
logging.info('building port: libpng')
3130

3231
source_path = os.path.join(ports.get_dir(), 'libpng', 'libpng-' + TAG)
33-
Path(source_path, 'pnglibconf.h').write_text(pnglibconf_h)
32+
ports.write_file(os.path.join(source_path, 'pnglibconf.h'), pnglibconf_h)
3433
ports.install_headers(source_path)
3534

3635
flags = ['-sUSE_ZLIB=1']

tools/ports/mpg123.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import os
77
import logging
8-
from pathlib import Path
98

109
TAG = '1.26.2'
1110
HASH = 'aa63fcb08b243a1e09f7701b3d84a19d7412a87253d54d49f014fdb9e75bbc81d152a41ed750fccde901453929b2a001585a7645351b41845ad205c17a73dcc9'
@@ -27,8 +26,8 @@ def create(final):
2726
libmpg123_path = os.path.join(src_path, 'libmpg123')
2827
compat_path = os.path.join(src_path, 'compat')
2928

30-
Path(src_path, 'config.h').write_text(config_h)
31-
Path(libmpg123_path, 'mpg123.h').write_text(mpg123_h)
29+
ports.write_file(os.path.join(src_path, 'config.h'), config_h)
30+
ports.write_file(os.path.join(libmpg123_path, 'mpg123.h'), mpg123_h)
3231

3332
# copy header to a location so it can be used as 'MPG123/'
3433
ports.install_headers(libmpg123_path, pattern="*123.h", target='')

tools/ports/ogg.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import logging
77
import os
8-
from pathlib import Path
98

109
TAG = 'version_1'
1110
HASH = '929e8d6003c06ae09593021b83323c8f1f54532b67b8ba189f4aedce52c25dc182bac474de5392c46ad5b0dea5a24928e4ede1492d52f4dd5cd58eea9be4dba7'
@@ -22,7 +21,7 @@ def create(final):
2221
logging.info('building port: ogg')
2322

2423
source_path = os.path.join(ports.get_dir(), 'ogg', 'Ogg-' + TAG)
25-
Path(source_path, 'include', 'ogg', 'config_types.h').write_text(config_types_h)
24+
ports.write_file(os.path.join(source_path, 'include', 'ogg', 'config_types.h'), config_types_h)
2625
ports.install_header_dir(os.path.join(source_path, 'include', 'ogg'), 'ogg')
2726
ports.build_port(os.path.join(source_path, 'src'), final, 'ogg')
2827

tools/ports/zlib.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# found in the LICENSE file.
55

66
import os
7-
from pathlib import Path
87

98
VERSION = '1.2.12'
109
HASH = 'cc2366fa45d5dfee1f983c8c51515e0cff959b61471e2e8d24350dea22d3f6fcc50723615a911b046ffc95f51ba337d39ae402131a55e6d1541d3b095d6c0a14'
@@ -19,7 +18,7 @@ def get(ports, settings, shared):
1918

2019
def create(final):
2120
source_path = os.path.join(ports.get_dir(), 'zlib', 'zlib-' + VERSION)
22-
Path(source_path, 'zconf.h').write_text(zconf_h)
21+
ports.write_file(os.path.join(source_path, 'zconf.h'), zconf_h)
2322
ports.install_headers(source_path)
2423

2524
# build

0 commit comments

Comments
 (0)