Use cpp(c pre-processor) to merge .js files instead of merge.js 54/53154/1 accepted/tizen/mobile/20151202.091718 accepted/tizen/tv/20151202.091740 accepted/tizen/wearable/20151202.091750 submit/tizen/20151202.075444
authorWonYoung Choi <wy80.choi@samsung.com>
Wed, 2 Dec 2015 07:36:51 +0000 (16:36 +0900)
committerWonYoung Choi <wy80.choi@samsung.com>
Wed, 2 Dec 2015 07:36:51 +0000 (16:36 +0900)
If want to use multiple js files in module implementation,
'//#include' directive can be used in main js file (xxx_api.js)

Change-Id: I30a459d4c5828db8107e1be8b6507ee4a148dd6e

packaging/xwalk-extensions-common.spec
tools/build/generate_api.py
tools/build/mergejs.py [deleted file]

index 306688b..0e019d5 100644 (file)
@@ -18,6 +18,8 @@ Summary:  Development package of xwalk-extensions-common
 Group:    Development/Libraries
 Requires: %{name} = %{version}-%{release}
 Requires: python
+Requires: sed
+Requires: cpp
 Provides: gyp_xwext
 
 %description devel
index d9dfc02..ec4f0d1 100644 (file)
@@ -12,7 +12,7 @@ const char %s[] = { %s, 0 };
 """
 
 js_code = sys.argv[1]
-cmd = "python " + os.path.dirname(__file__) + "/mergejs.py -f" + js_code
+cmd = "sed -e 's#//\##\##g' " + js_code + " | cpp -E -P "
 lines = subprocess.check_output(cmd, shell=True)
 c_code = ', '.join(str(ord(c)) for c in lines)
 
diff --git a/tools/build/mergejs.py b/tools/build/mergejs.py
deleted file mode 100644 (file)
index 794a46b..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-#!/usr/bin/env python
-
-# Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import fileinput
-import sys
-import getopt
-import glob
-import os
-
-class Utils:
-    reqfiles = []
-    searchfile = '*_api.js'
-    startwith = "//= require('"
-    endwith = "')"
-    code = ""
-
-    @classmethod
-    def get_require(self, s):
-        try:
-            start = s.index(self.startwith) + len(self.startwith)
-            end = s.index(self.endwith, start)
-            filename = s[start:end]
-            self.reqfiles.append(filename)
-        except ValueError:
-           return ""
-
-    @classmethod
-    def find_require(self):
-        p = os.path.join('./', self.searchfile)
-        filenames = glob.glob(self.searchfile)
-        for fname in filenames:
-            with open(fname, 'r') as myfile:
-                for line in myfile:
-                    self.get_require(line)
-
-    @classmethod
-    def print_lines(self, filename):
-        with open(filename, 'r') as file:
-            for line in file:
-                self.code += line
-
-    @classmethod
-    def merge_js_files(self, path):
-        self.find_require()
-        if len(self.reqfiles) == 0:
-            s = os.path.join('./', self.searchfile)
-            sfiles = glob.glob(s)
-            for fname in sfiles:
-                self.print_lines(fname)
-        else:
-            js = '*.js'
-            p = os.path.join(path, js)
-            filenames = glob.glob(p)
-            for fname in self.reqfiles:
-                fname = path + '/' + fname
-                if fname in filenames:
-                    self.print_lines(fname)
-
-    @classmethod
-    def main(self, argv):
-        path = 'js'
-        try:
-            opts, args = getopt.getopt(argv,"hf:p:",["file=", "path="])
-        except getopt.GetoptError:
-            print __file__ + ' -h'
-            sys.exit()
-        if len(argv) > 0:
-          for opt, arg in opts:
-              if opt in ("-h"):
-                  print 'Help:'
-                  print ''
-                  print __file__ + '-f <file> -p <path>'
-                  print ''
-                  print '<opt> \t <opt> \t\t <description>'
-                  print '-f \t --file \t Name of the file where script searching for require files:'
-                  print '\t \t \t ' + self.startwith + 'file_name.js' + self.endwith
-                  print '-p \t --path \t Path to "' + path + '" directory'
-                  print ''
-                  sys.exit()
-              elif opt in ("-f", "--file"):
-                  self.searchfile = arg
-              elif opt in ("-p", "--path"):
-                  path = arg
-        self.merge_js_files(path)
-        print self.code
-
-if Utils.__module__ == "__main__":
-    Utils.main(sys.argv[1:])