]> khamidou — GitHub mirrors - electron.git/commitdiff
Compile asar.coffee to .c
authorCheng Zhao <zcbenz@gmail.com>
Wed, 4 Feb 2015 00:46:52 +0000 (16:46 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 4 Feb 2015 00:46:52 +0000 (16:46 -0800)
atom.gyp
tools/coffee2c.py [new file with mode: 0755]

index 0a3928cac172e6f42d542aeea98f76d159e4ae86..b235439a06f87cfebf30ef7ab3a2354b23113696 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
@@ -41,7 +41,6 @@
       'atom/common/api/lib/original-fs.coffee',
       'atom/common/api/lib/shell.coffee',
       'atom/common/lib/init.coffee',
-      'atom/common/lib/asar.coffee',
       'atom/renderer/lib/chrome-api.coffee',
       'atom/renderer/lib/init.coffee',
       'atom/renderer/lib/inspector.coffee',
@@ -55,6 +54,9 @@
       'atom/renderer/api/lib/screen.coffee',
       'atom/renderer/api/lib/web-frame.coffee',
     ],
+    'coffee2c_sources': [
+      'atom/common/lib/asar.coffee',
+    ],
     'lib_sources': [
       'atom/app/atom_content_client.cc',
       'atom/app/atom_content_client.h',
       'chromium_src/library_loaders/libspeechd_loader.cc',
       'chromium_src/library_loaders/libspeechd.h',
       '<@(native_mate_files)',
+      '<(SHARED_INTERMEDIATE_DIR)/atom_natives.h',
     ],
     'lib_sources_win': [
       'chromium_src/chrome/browser/ui/views/color_chooser_dialog.cc',
       'target_name': '<(project_name)_lib',
       'type': 'static_library',
       'dependencies': [
+        'atom_coffee2c',
         'vendor/brightray/brightray.gyp:brightray',
         'vendor/node/node.gyp:node_lib',
       ],
         'chromium_src',
         'vendor/brightray',
         'vendor/native_mate',
+        # Include atom_natives.h.
+        '<(SHARED_INTERMEDIATE_DIR)',
         # Include directories for uv and node.
         'vendor/node/src',
         'vendor/node/deps/http_parser',
         },
       ],
     },  # target compile_coffee
+    {
+      'target_name': 'atom_coffee2c',
+      'type': 'none',
+      'actions': [
+        {
+          'action_name': 'atom_coffee2c',
+          'inputs': [
+            '<@(coffee2c_sources)',
+          ],
+          'outputs': [
+            '<(SHARED_INTERMEDIATE_DIR)/atom_natives.h',
+          ],
+          'action': [
+            'python',
+            'tools/coffee2c.py',
+            '<@(_outputs)',
+            '<@(_inputs)',
+          ],
+        }
+      ],
+    },  # target atom_coffee2c
     {
       'target_name': '<(project_name)_dump_symbols',
       'type': 'none',
diff --git a/tools/coffee2c.py b/tools/coffee2c.py
new file mode 100755 (executable)
index 0000000..6c1241e
--- /dev/null
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+
+import os
+import subprocess
+import sys
+
+
+SOURCE_ROOT = os.path.dirname(os.path.dirname(__file__))
+
+
+def main():
+  natives = sys.argv[1]
+  coffee_source_files = sys.argv[2:]
+
+  output_dir = os.path.dirname(natives)
+  js_source_files = compile_coffee(coffee_source_files, output_dir)
+  call_js2c(natives, js_source_files)
+
+
+def compile_coffee(coffee_source_files, output_dir):
+  js_source_files = []
+  for source_file in coffee_source_files:
+    output_filename = os.path.splitext(source_file)[0] + '.js'
+    output_path = os.path.join(output_dir, output_filename)
+    js_source_files.append(output_path)
+    call_compile_coffee(source_file, output_path)
+  return js_source_files
+
+
+def call_compile_coffee(source_file, output_filename):
+  compile_coffee = os.path.join(SOURCE_ROOT, 'tools', 'compile-coffee.py')
+  subprocess.check_call([sys.executable, 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)
+
+
+if __name__ == '__main__':
+  sys.exit(main())