From 2980adfd79d8f6dc48407c1238306742fc0bc498 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 1 Apr 2015 19:03:50 +0800 Subject: [PATCH] Fix calling js2c --- tools/coffee2c.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tools/coffee2c.py b/tools/coffee2c.py index 6c1241eb18b7..1ca9a19334c6 100755 --- a/tools/coffee2c.py +++ b/tools/coffee2c.py @@ -1,15 +1,16 @@ #!/usr/bin/env python +import contextlib import os import subprocess import sys -SOURCE_ROOT = os.path.dirname(os.path.dirname(__file__)) +SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) def main(): - natives = sys.argv[1] + natives = os.path.abspath(sys.argv[1]) coffee_source_files = sys.argv[2:] output_dir = os.path.dirname(natives) @@ -35,7 +36,21 @@ def call_compile_coffee(source_file, output_filename): def call_js2c(natives, js_source_files): js2c = os.path.join(SOURCE_ROOT, 'vendor', 'node', 'tools', 'js2c.py') - subprocess.check_call([sys.executable, js2c, natives] + js_source_files) + src_dir = os.path.dirname(js_source_files[0]) + with scoped_cwd(src_dir): + subprocess.check_call( + [sys.executable, js2c, natives] + + [os.path.basename(source) for source in js_source_files]) + + +@contextlib.contextmanager +def scoped_cwd(path): + cwd = os.getcwd() + os.chdir(path) + try: + yield + finally: + os.chdir(cwd) if __name__ == '__main__':