Support user compile/link options
[scm/meta/abs.git] / abs
diff --git a/abs b/abs
old mode 100644 (file)
new mode 100755 (executable)
index a0d43be..668453a
--- a/abs
+++ b/abs
@@ -154,7 +154,7 @@ class _Rootstrap(object):
         cmdline = self.tizen + ' list rootstrap'
         ret = Executor().run(cmdline, show=False)
         for x in ret.splitlines():
-            if re.search('(mobile|wearable)-(2.4|3.0)-(device|emulator).core.*', x):
+            if re.search('(mobile|wearable)-(2.4|3.0|4.0)-(device|emulator|device64|emulator64).core.*', x):
                 if self.rootstrap_list == None:
                     self.rootstrap_list = []
                 self.rootstrap_list.append(x.split(' ')[0])
@@ -180,7 +180,8 @@ class Sdk(object):
 
     rs = None #_Rootstrap class instance
     rootstrap_list = None
-    sdk_to_search = ['tizen-sdk/tools/ide/bin/tizen', \
+    sdk_to_search = ['tizen-studio/tools/ide/bin/tizen', \
+                     'tizen-sdk/tools/ide/bin/tizen', \
                      'tizen-sdk-ux/tools/ide/bin/tizen', \
                      'tizen-sdk-cli/tools/ide/bin/tizen']
 
@@ -337,7 +338,7 @@ class Sdk(object):
         myZipFile.close()
         return rsrc_zip
 
-    def build_native(self, source, rootstrap=None, arch=None, conf='Release'):
+    def build_native(self, source, rootstrap=None, arch=None, conf='Debug', jobs=None):
         """SDK CLI build command"""
 
         _rootstrap = self.check_rootstrap(rootstrap)
@@ -346,18 +347,26 @@ class Sdk(object):
 
         if rootstrap is None and arch is None:
             rootstrap = _rootstrap
-            arch = 'x86'
+            self.arch = 'x86'
         elif arch is None:
-            if 'emulator' in rootstrap: arch = 'x86'
-            elif 'device' in rootstrap: arch = 'arm'
+            if 'emulator64' in rootstrap: self.arch = 'x86_64'
+            elif 'device64' in rootstrap: self.arch = 'aarch64'
+            elif 'emulator' in rootstrap: self.arch = 'x86'
+            elif 'device' in rootstrap: self.arch = 'arm'
         elif rootstrap is None:
-            if arch not in ['x86', 'arm']:
+            if arch not in ['x86', 'arm', 'aarch64', 'x86_64']:
                 raise LocalError('Architecture and rootstrap mismatch')
+
             rootstrap = _rootstrap
-            if arch == 'arm': rootstrap = rootstrap.replace('emulator', 'device')
+            if arch == 'x86_64': rootstrap = rootstrap.replace('emulator', 'emulator64')
+            elif arch == 'aarch64': rootstrap = rootstrap.replace('emulator', 'device64')
+            elif arch == 'arm': rootstrap = rootstrap.replace('emulator', 'device')
 
         for x in source.project_list:
-            out = self._run('build-native', ['-r', rootstrap, '-a', arch, '-C', conf, '--' , x['path']], checker=True)
+            b_args = ['-r', rootstrap, '-a', self.arch, '-C', conf, '-c', 'gcc']
+            if jobs is not None: b_args.extend(['-j', jobs])
+            b_args.extend(['--', x['path']])
+            out = self._run('build-native', b_args, checker=True)
             logpath = os.path.join(source.output_dir, \
                                   'build_%s_%s' % (rootstrap, os.path.basename(x['path'])))
             if not os.path.isdir(source.output_dir):
@@ -418,6 +427,97 @@ class Sdk(object):
         #Copy tpk to output directory
         shutil.copy(final_app, source.output_dir)
 
+    def package_new(self, source, cert=None, pkg_type=None, conf=None, manual_strip=False):
+        """SDK CLI package command
+            IF Debug + Manual Strip off then generate package-name-debug.tpk
+            IF Debug + Manual Strip on then generate package-name.tpk with custom strip
+            IF Release then generate package-name.tpk with strip option
+        """
+
+        if cert is None: cert = 'ABS'
+        if pkg_type is None: pkg_type = 'tpk'
+        if conf is None: conf = 'Debug'
+
+        final_app = ''
+        main_args = ['-t', pkg_type, '-s', cert]
+        out = '' #logfile
+
+        # remove tpk or zip file on project path
+        package_list = []
+        for i, x in enumerate(source.project_list):
+            package_list.extend(list_files(os.path.join(x['path'], conf), ext='tpk'))
+            package_list.extend(list_files(os.path.join(x['path'], conf), ext='zip'))
+
+        for k in package_list :
+            print ' package list ' + k;
+            os.remove(k)
+
+        # Manual strip
+        if manual_strip == True :
+            strip_cmd='';
+            if self.arch == None:
+                raise LocalError('Architecture is Noen')
+            elif self.arch == 'x86' :
+                strip_cmd = os.path.join(os.path.dirname(self.tizen), '../../i386-linux-gnueabi-gcc-4.9/bin/i386-linux-gnueabi-strip')
+            elif self.arch == 'arm' :
+                strip_cmd = os.path.join(os.path.dirname(self.tizen), '../../arm-linux-gnueabi-gcc-4.9/bin/arm-linux-gnueabi-strip')
+            elif self.arch == 'x86_64' :
+                strip_cmd = os.path.join(os.path.dirname(self.tizen), '../../x86_64-linux-gnu-gcc-4.9/bin/x86_64-linux-gnu-strip')
+            elif self.arch == 'aarch64' :
+                strip_cmd = os.path.join(os.path.dirname(self.tizen), '../../aarch64-linux-gnu-gcc-4.9/bin/aarch64-linux-gnu-strip')
+
+            print strip_cmd
+
+            for i, x in enumerate(source.project_list):
+                dir = os.path.join(x['path'], conf)
+                files = [os.path.join(dir,f) for f in os.listdir(dir) if os.path.isfile(os.path.join(dir,f))]
+                for k in files:
+                    cmdline = strip_cmd + ' ' + k;
+                    #print 'my command line ' + cmdline;
+                    Executor().run(cmdline, show=False)
+        elif conf == 'Release':
+            main_args.extend(['--strip', 'on'])
+
+        for i, x in enumerate(source.project_list):
+            if x['type'] == 'app':
+                out = '%s\n%s' % (out, \
+                      self._run('package', main_args + ['--',os.path.join(x['path'],conf)]))
+                try:
+                    final_app = list_files(os.path.join(x['path'], conf), ext='tpk')[0]
+                except:
+                    raise LocalError('TPK file not generated for %s.' % x['APPNAME'])
+                x['out_package'] = final_app
+            elif x['type'] == 'sharedLib':
+                self._package_sharedlib(x['path'], conf, x['APPNAME'])
+                x['out_package'] = list_files(os.path.join(x['path'], conf), ext='zip')[0]
+            else:
+                raise LocalError('Not supported project type %s' % x['type'])
+
+        if source.b_multi == True:
+            extra_args=[]
+            print 'THIS IS MULTI PROJECT'
+            for i, x in enumerate(source.project_list):
+                if x['out_package'] != final_app and x['type'] == 'app':
+                    extra_args.extend(['-r', x['out_package']])
+                elif x['type'] == 'sharedLib':
+                    extra_args.extend(['-r', x['out_package']])
+
+            extra_args.extend(['--', final_app])
+            out = self._run('package', main_args + extra_args)
+
+        #TODO: signature validation check failed : Invalid file reference. An unsigned file was found.
+        print 'Packaging final step again!'
+        out = self._run('package', main_args + ['--', final_app])
+
+        #Copy tpk to output directory
+        if conf == 'Debug' and manual_strip == False :
+            basename = os.path.splitext(final_app)[0]
+            newname = basename +'-debug.tpk'
+            os.rename(final_app, newname)
+            shutil.copy(newname, source.output_dir)
+        else :
+            shutil.copy(final_app, source.output_dir)
+
     def clean(self, source):
         """SDK CLI clean command"""
 
@@ -466,6 +566,17 @@ class Source(object):
         mydict['path'] = path
         return mydict
 
+    def set_user_options(self, c_opts=None, cpp_opts=None, link_opts=None):
+        if c_opts is not None:
+            os.environ['USER_C_OPTS'] = c_opts
+            print 'Set USER_C_OPTS=[%s]' % os.getenv('USER_C_OPTS')
+        if cpp_opts is not None:
+            os.environ['USER_CPP_OPTS'] = cpp_opts
+            print 'Set USER_CPP_OPTS=[%s]' % os.getenv('USER_CPP_OPTS')
+        if link_opts is not None:
+            os.environ['USER_LINK_OPTS'] = link_opts
+            print 'Set USER_LINK_OPTS=[%s]' % os.getenv('USER_LINK_OPTS')
+
     def pre_process(self):
 
         if os.path.isfile(os.path.join(self.workspace, self.multi_conf_file)):
@@ -493,16 +604,24 @@ def argument_parsing(argv):
     build.add_argument('-r', '--rootstrap', action='store', dest='rootstrap', \
                         help='(ex, mobile-3.0-device.core) rootstrap name')
     build.add_argument('-a', '--arch', action='store', dest='arch', \
-                        help='(x86|arm) Architecture to build')
+                        help='(x86|arm|x86_64|aarch64) Architecture to build')
     build.add_argument('-t', '--type', action='store', dest='type', \
                         help='(tpk|wgt) Packaging type')
     build.add_argument('-s', '--cert', action='store', dest='cert', \
                         help='(ex, ABS) Certificate profile name')
     build.add_argument('-c', '--conf', action='store',default='Release', dest='conf', \
-                        help='(Debug|Release) Build configuration')
+                        help='(ex, Debug|Release) Build Configuration')
+    build.add_argument('-j', '--jobs', action='store', dest='jobs', \
+                        help='(number of jobs) The number of parallel builds')
     build.add_argument('--sdkpath', action='store', dest='sdkpath', \
                         help='Specify Tizen SDK installation root (one time init).' \
                              ' ex) /home/yours/tizen-sdk/')
+    build.add_argument('--c-opts', action='store', dest='c_opts', \
+                        help='Extra compile options USER_C_OPTS')
+    build.add_argument('--cpp-opts', action='store', dest='cpp_opts', \
+                        help='Extra compile options USER_CPP_OPTS')
+    build.add_argument('--link-opts', action='store', dest='link_opts', \
+                        help='Extra linking options USER_LINK_OPTS')
 
     return parser.parse_args(argv[1:])
 
@@ -510,14 +629,21 @@ def build_main(args):
     """Command [build] entry point."""
 
     my_source = Source(src=args.workspace)
+    my_source.set_user_options(c_opts=args.c_opts, cpp_opts=args.cpp_opts, link_opts=args.link_opts)
     my_sdk = Sdk(sdkpath=args.sdkpath)
     my_sdk.clean(my_source)
-    my_sdk.build_native(my_source, rootstrap=args.rootstrap, arch=args.arch, conf=args.conf)
-    my_sdk.package(my_source, pkg_type=args.type, cert=args.cert, conf=args.conf)
+    my_sdk.build_native(my_source, rootstrap=args.rootstrap, arch=args.arch, conf=args.conf, jobs=args.jobs)
+    if args.conf == 'Debug' :
+        my_sdk.package_new(my_source, pkg_type=args.type, cert=args.cert, conf=args.conf)
+        my_sdk.package_new(my_source, pkg_type=args.type, cert=args.cert, conf=args.conf, manual_strip=True)
+    else :
+        my_sdk.package_new(my_source, pkg_type=args.type, cert=args.cert, conf=args.conf)
 
 def main(argv):
     """Script entry point."""
 
+    print 'ABS SCRIPT FROM GIT'
+
     args = argument_parsing(argv)
 
     if args.subcommands == 'build':
@@ -533,4 +659,3 @@ if __name__ == '__main__':
     except Exception, e:
         print 'Exception %s' % str(e)
         sys.exit(1)
-