Skip to content

Commit f3f2c7e

Browse files
committed
Fix various errors
1. Use an absolute path for CACHE in embuilder_config 2. Fix various issues with error handling (fail, return_code, etc)
1 parent 2818b5a commit f3f2c7e

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

bazel/emscripten_cache.bzl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,19 @@ def _emscripten_cache_impl(repository_ctx):
5050

5151
if repository_ctx.attr.libraries or repository_ctx.attr.flags:
5252
binaryen_root = get_binaryen_root(repository_ctx)
53-
embuilder_path = binaryen_root.get_child('emscripten/embuilder')
5453
llvm_root = binaryen_root.get_child("bin")
55-
nodejs = repository_ctx.path(Label("@nodejs//:node_files")).dirname.get_child('bin/node')
54+
emscripten_root = binaryen_root.get_child("emscripten")
55+
embuilder_path = emscripten_root.get_child("embuilder")
56+
cache_path = repository_ctx.path('cache')
57+
nodejs = repository_ctx.path(Label("@nodejs//:node_files")).dirname.get_child("bin/node")
5658
# Create configuration file
57-
embuilder_config_content = "LLVM_ROOT = '{}'\n".format(llvm_root)
58-
embuilder_config_content += "NODE_JS = '{}'\n".format(nodejs)
59+
embuilder_config_content = "NODE_JS = '{}'\n".format(nodejs)
60+
embuilder_config_content += "LLVM_ROOT = '{}'\n".format(llvm_root)
5961
embuilder_config_content += "BINARYEN_ROOT = '{}'\n".format(binaryen_root)
60-
embuilder_config_content += "CACHE = 'cache'\n"
61-
repository_ctx.file('embuilder_config', embuilder_config_content)
62-
embuilder_config_path = repository_ctx.path('embuilder_config')
62+
embuilder_config_content += "EMSCRIPTEN_ROOT = '{}'\n".format(emscripten_root)
63+
embuilder_config_content += "CACHE = '{}'\n".format(cache_path)
64+
repository_ctx.file("embuilder_config", embuilder_config_content)
65+
embuilder_config_path = repository_ctx.path("embuilder_config")
6366
# Prepare the command line
6467
if repository_ctx.attr.libraries:
6568
libraries = repository_ctx.attr.libraries
@@ -70,11 +73,11 @@ def _emscripten_cache_impl(repository_ctx):
7073
embuilder_args = [embuilder_path] + flags + ["build"] + libraries
7174
# Run embuilder
7275
repository_ctx.report_progress("Building secondary cache")
73-
result = repository_ctx.execute(embuilder_args, quiet=False)
74-
if result != 0:
76+
result = repository_ctx.execute(embuilder_args, quiet=True)
77+
if result.return_code != 0:
7578
fail("Embuilder exited with a non-zero return code")
7679
# Override Emscripten's cache with the secondary cache
77-
default_config += "CACHE = '{}'\n".format(repository_ctx.path('cache'))
80+
default_config += "CACHE = '{}'\n".format(cache_path)
7881

7982
# Create the configuration file for the toolchain and export
8083
repository_ctx.file('emscripten_config', default_config)

0 commit comments

Comments
 (0)