Skip to content

Commit f199880

Browse files
committed
set up parameter passing for jcache
1 parent b074f42 commit f199880

4 files changed

Lines changed: 31 additions & 6 deletions

File tree

emcc

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,16 @@ Options that are modified or new in %s include:
327327
llvm-link's behavior is not as permissive
328328
as ld is.
329329
330+
--jcache Use a JavaScript cache. This is disabled by
331+
default. When enabled, emcc will store the
332+
results of compilation in a cache and check
333+
the cache when compiling later, something
334+
like what ccache does. This allows incremental
335+
builds - where you are compiling a large
336+
program but only modified a small part of it -
337+
to be much faster (at the cost of more disk
338+
IO for cache accesses).
339+
330340
--clear-cache Manually clears the cache of compiled
331341
emscripten system libraries (libc++,
332342
libc++abi, dlmalloc). This is normally
@@ -336,7 +346,10 @@ Options that are modified or new in %s include:
336346
mechanism can get confused. Clearing the
337347
cache can fix weird problems related to
338348
cache incompatibilities, like clang failing
339-
to link with library files.
349+
to link with library files. This also clears
350+
other cached data like the jcache and
351+
the bootstrapped relooper. After the cache
352+
is cleared, this process will exit.
340353
341354
The target file, if specified (-o <target>), defines what will
342355
be generated:
@@ -571,6 +584,7 @@ try:
571584
remove_duplicates = False
572585
keep_debug = False
573586
bind = False
587+
jcache = False
574588

575589
def check_bad_eq(arg):
576590
assert '=' not in arg, 'Invalid parameter (do not use "=" with "--" options)'
@@ -678,10 +692,14 @@ try:
678692
elif newargs[i] == '--remove-duplicates':
679693
remove_duplicates = True
680694
newargs[i] = ''
695+
elif newargs[i] == '--jcache':
696+
jcache = True
697+
newargs[i] = ''
681698
elif newargs[i] == '--clear-cache':
682699
newargs[i] = ''
683700
print >> sys.stderr, 'emcc: clearing cache'
684701
shared.Cache.erase()
702+
sys.exit(0)
685703
elif newargs[i].startswith(('-I/', '-L/')):
686704
if not absolute_warning_shown:
687705
print >> sys.stderr, 'emcc: warning: -I or -L of an absolute path encountered. If this is to a local system header/library, it may cause problems (local system files make sense for compiling natively on your system, but not necessarily to JavaScript)' # Of course an absolute path to a non-system-specific library or header is fine, and you can ignore this warning. The danger are system headers that are e.g. x86 specific and nonportable. The emscripten bundled headers are modified to be portable, local system ones are generally not
@@ -1044,6 +1062,7 @@ try:
10441062
# Emscripten
10451063
if DEBUG: print >> sys.stderr, 'emcc: LLVM => JS'
10461064
extra_args = [] if not js_libraries else ['--libraries', ','.join(map(os.path.abspath, js_libraries))]
1065+
if jcache: extra_args.append('--jcache')
10471066
final = shared.Building.emscripten(final, append_ext=False, extra_args=extra_args)
10481067
if DEBUG: save_intermediate('original')
10491068

@@ -1100,12 +1119,12 @@ try:
11001119
if len(js_optimizer_queue) > 0:
11011120
if DEBUG < 2:
11021121
if DEBUG: print >> sys.stderr, 'emcc: applying js optimization passes:', js_optimizer_queue
1103-
final = shared.Building.js_optimizer(final, js_optimizer_queue)
1122+
final = shared.Building.js_optimizer(final, js_optimizer_queue, jcache)
11041123
if DEBUG: save_intermediate('js_opts')
11051124
else:
11061125
for name in js_optimizer_queue:
11071126
print >> sys.stderr, 'emcc: applying js optimization pass:', name
1108-
final = shared.Building.js_optimizer(final, [name])
1127+
final = shared.Building.js_optimizer(final, [name], jcache)
11091128
save_intermediate(name)
11101129
js_optimizer_queue = []
11111130

emscripten.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def path_from_root(*pathelems):
3232
temp_files = shared.TempFiles()
3333

3434
compiler_engine = None
35+
jcache = False
3536

3637
def scan(ll, settings):
3738
# blockaddress(@main, %23)
@@ -335,6 +336,10 @@ def lookup(value):
335336
metavar='FOO=BAR',
336337
help=('Overrides for settings defined in settings.js. '
337338
'May occur multiple times.'))
339+
parser.add_option('-j', '--jcache',
340+
action='store_true',
341+
default=False,
342+
help=('Enable jcache (ccache-like caching of compilation results, for faster incremental builds).'))
338343

339344
# Convert to the same format that argparse would have produced.
340345
keywords, positional = parser.parse_args()
@@ -344,6 +349,7 @@ def lookup(value):
344349
if isinstance(keywords.outfile, basestring):
345350
keywords.outfile = open(keywords.outfile, 'w')
346351
compiler_engine = keywords.compiler
352+
jcache = keywords.jcache
347353

348354
temp_files.run_and_clean(lambda: main(keywords))
349355

tools/js_optimizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def run_on_chunk(command):
2323
f.close()
2424
return filename
2525

26-
def run(filename, passes, js_engine):
26+
def run(filename, passes, js_engine, jcache):
2727
if type(passes) == str:
2828
passes = [passes]
2929

tools/shared.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,8 +1006,8 @@ def pick_llvm_opts(optimization_level):
10061006
return opts
10071007

10081008
@staticmethod
1009-
def js_optimizer(filename, passes):
1010-
return js_optimizer.run(filename, passes, NODE_JS)
1009+
def js_optimizer(filename, passes, jcache):
1010+
return js_optimizer.run(filename, passes, NODE_JS, jcache)
10111011

10121012
@staticmethod
10131013
def closure_compiler(filename):

0 commit comments

Comments
 (0)