[ABS] Force clean all old rootstrap
[scm/meta/abs.git] / abs
diff --git a/abs b/abs
index e3bf8e2..487f57f 100755 (executable)
--- a/abs
+++ b/abs
@@ -108,7 +108,7 @@ class ErrorParser(object):
                                     '.*make.*: \*\*\* .*', \
                                     '.*make.*: Target (.*) not remade because of errors.', \
                                     '.*[Cc]ommand not found.*', \
-                                    'Error:\s*(.*)'], \
+                                    '^Error:\s*(.*)'], \
                        'TIZEN_NATIVE':['.*ninja: build stopped.*', \
                                        'edje_cc: Error..(.*):(\d).*', \
                                        'edje_cc: Error.*']}
@@ -147,7 +147,7 @@ class _Rootstrap(object):
     def list_rootstrap(self, rootstrap_search=None):
         """List all the rootstraps"""
 
-        rs_prefix = 'mobile|wearable'
+        rs_prefix = 'mobile|wearable|tizeniot'
         if rootstrap_search is not None:
             rs_prefix = rootstrap_search
         print 'Set rs_prefix: %s' % rs_prefix
@@ -158,12 +158,12 @@ class _Rootstrap(object):
         cmdline = self.tizen + ' list rootstrap'
         ret = Executor().run(cmdline, show=False)
         for x in ret.splitlines():
-            if re.search('(%s)-(2.4|3.0|4.0|5.0)-(device|emulator|device64|emulator64).core.*' % rs_prefix, x):
+            if re.search('(%s)-([0-9.]*)-(device.*|emulator.*).core.*' % rs_prefix, x):
                 if self.rootstrap_list == None:
                     self.rootstrap_list = []
                 self.rootstrap_list.append(x.split(' ')[0])
             else:
-                print 'No search result for %s' % '(%s)-(2.4|3.0|4.0|5.0)-(device|emulator|device64|emulator64).core.*' % rs_prefix
+                print 'No search result for %s' % '(%s)-([0-9.]*)-(device.*|emulator.*).core.*' % rs_prefix
         return self.rootstrap_list
 
     def check_rootstrap(self, rootstrap, show=True):
@@ -191,13 +191,13 @@ class Sdk(object):
                      'tizen-sdk-ux/tools/ide/bin/tizen', \
                      'tizen-sdk-cli/tools/ide/bin/tizen']
 
-    def __init__(self, sdkpath=None, rootstrap_search=None):
+    def __init__(self, sdkpath=None, rootstrap_search=None, no_dbus=False):
 
         self.error_parser = ErrorParser()
         self.runtool = Executor(checker=self.error_parser)
 
         self.home = os.getenv('HOME')
-        self.config_file = os.path.join(g_home, '.abs')
+        self.config_file = os.path.join(g_home, '.absconfig')
 
         if sdkpath is None:
             self.tizen = self.get_user_root()
@@ -215,6 +215,10 @@ class Sdk(object):
             raise LocalError('Fail to locate cli tool')
 
         self.rs = _Rootstrap(sdk_path=self.tizen, config=self.config_file, rootstrap_search=rootstrap_search)
+        if no_dbus != False:
+            self.no_dbus = True
+        else:
+            self.no_dbus = False
 
     def get_user_root(self):
 
@@ -248,8 +252,14 @@ class Sdk(object):
         """Run a tizen command"""
 
         cmd = [self.tizen, command] + args
+        if command == 'package':
+            dbus_command = 'dbus-run-session -- bash; echo build | gnome-keyring-daemon --unlock;  '
+            if self.no_dbus == True:
+                dbus_command = ' '
+            cmd = ['{} '.format(dbus_command)] + cmd
         print '\nRunning command:\n    %s' % ' '.join(cmd)
-        return self.runtool.run(' '.join(cmd), show=show, checker=checker)
+        return self.runtool.run('{}'.format(' '.join(cmd)), \
+                show=show, checker=checker)
 
     def copytree2(self, src, dst, symlinks=False, ignore=None):
         """Copy with Ignore & Overwrite"""
@@ -378,7 +388,7 @@ class Sdk(object):
                 print '\n\n BUILD NATIVE\n'
                 if jobs is not None:
                     b_args.extend(['-j', jobs])
-                b_args.extend(['-r', rootstrap, '-a', self.arch, '-C', conf, '-c', 'gcc'])
+                b_args.extend(['-r', rootstrap, '-a', self.arch, '-C', conf])
                 b_args.extend(['--', x['path']])
                 out = self._run('build-native', b_args, checker=True)
             logpath = os.path.join(source.output_dir, \
@@ -394,6 +404,19 @@ class Sdk(object):
             if ret:
                 raise LocalError(ret)
 
+    def raise_package_exception(self, out, output_dir, i, bname, appname):
+        logpath = os.path.join(output_dir, \
+                              'package_%d_%s' % (i, bname))
+        if not os.path.isdir(output_dir):
+            os.makedirs(output_dir)
+        with open(logpath + '.log', 'w') as lf:
+            lf.write(out)
+        if 'keystore password was incorrect' in out \
+            or 'Sequence tag error' in out \
+            or 'Signing... java.io.IOException: ' in out:
+            raise LocalError('signing error for %s.' % appname)
+        raise LocalError('TPK/WGT file not generated for %s.' % appname)
+
     def package(self, source, cert=None, pkg_type=None, conf='Debug', manual_strip=False):
         """SDK CLI package command
             IF Debug + Manual Strip off then generate package-name-debug.tpk
@@ -422,6 +445,7 @@ class Sdk(object):
 
         # Manual strip
         if manual_strip == True :
+            main_args.extend(['--strip', 'on'])
             strip_cmd='';
             if self.arch == None:
                 raise LocalError('Architecture is None')
@@ -478,7 +502,7 @@ class Sdk(object):
                     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'])
+                        self.raise_package_exception(out, source.output_dir, i, os.path.basename(x['path']), x['APPNAME'])
                     x['out_package'] = final_app
                 elif x['type'] == 'sharedLib':
                     self._package_sharedlib(x['path'], conf, x['APPNAME'])
@@ -492,7 +516,7 @@ class Sdk(object):
                 try:
                     final_app = list_files(os.path.join(x['path'], '.buildResult'), ext='wgt')[0]
                 except:
-                    raise LocalError('WGT file not generated for %s.' % x['APPNAME'])
+                    self.raise_package_exception(out, source.output_dir, i, os.path.basename(x['path']), x['APPNAME'])
                 x['out_package'] = final_app
 
         if source.b_multi == True:
@@ -500,26 +524,26 @@ class Sdk(object):
             print 'THIS IS MULTI PROJECT'
             for i, x in enumerate(source.project_list):
                 if x['out_package'] != final_app and x.get('type') == 'app':
-                    extra_args.extend(['-r', x['out_package']])
+                    extra_args.extend(['-r', '"%s"' % x['out_package']])
                 elif x.get('type') == 'sharedLib':
-                    extra_args.extend(['-r', x['out_package']])
+                    extra_args.extend(['-r', '"%s"' % x['out_package']])
 
-            extra_args.extend(['--', final_app])
+            extra_args.extend(['--', '"%s"' % final_app])
             if final_app.endswith('.tpk'):
-                out = self._run('package', main_args + extra_args)
+                out = '%s\n\n%s' % (out, self._run('package', main_args + extra_args))
             elif final_app.endswith('.wgt'):
-                out = self._run('package', main_args_web + extra_args)
+                out = '%s\n\n%s' % (out, self._run('package', main_args_web + extra_args))
 
         #TODO: signature validation check failed : Invalid file reference. An unsigned file was found.
         if final_app.endswith('.tpk'):
             print 'Packaging final step again!'
-            out = self._run('package', main_args + ['--', final_app])
+            out = '%s\n\n%s' % (out, self._run('package', main_args + ['--', '"%s"' % final_app]))
 
         #Append arch to web binary
-        if final_app.endswith('.wgt'):
-            final_app_with_arch = final_app.replace('.wgt', '-%s.wgt' % self.arch)
-            os.rename(final_app, final_app_with_arch)
-            final_app = final_app_with_arch
+        #if final_app.endswith('.wgt'):
+        #    final_app_with_arch = final_app.replace('.wgt', '-%s.wgt' % self.arch)
+        #    os.rename(final_app, final_app_with_arch)
+        #    final_app = final_app_with_arch
 
         #Copy tpk to output directory
         if conf == 'Debug' and manual_strip == False :
@@ -533,6 +557,7 @@ class Sdk(object):
         else :
             shutil.copy(final_app, source.output_dir)
 
+
     def clean(self, source):
         """SDK CLI clean command"""
 
@@ -651,6 +676,8 @@ def argument_parsing(argv):
                         help='Extra compile options USER_CPP_OPTS')
     build.add_argument('--link-opts', action='store', dest='link_opts', \
                         help='Extra linking options USER_LINK_OPTS')
+    build.add_argument('--no-dbus', action='store', dest='no_dbus', default=False, \
+                        help='Do not run dbus session before packaging')
 
     return parser.parse_args(argv[1:])
 
@@ -664,7 +691,7 @@ def build_main(args):
         print '-------------------'
         print '(%s)' % args.profiletosearch
         print '-------------------'
-        my_sdk = Sdk(sdkpath=args.sdkpath, rootstrap_search=args.profiletosearch)
+        my_sdk = Sdk(sdkpath=args.sdkpath, rootstrap_search=args.profiletosearch, no_dbus=args.no_dbus)
         my_sdk.clean(my_source)
         my_sdk.build_tizen(my_source, rootstrap=args.rootstrap, arch=args.arch, jobs=args.jobs)
         if args.conf == 'Debug' :
@@ -703,4 +730,6 @@ if __name__ == '__main__':
             os.makedirs('_abs_out_')
         with open(os.path.join('_abs_out_', 'build_EXCEPTION.log'), 'w') as ef:
             ef.write('Exception %s' % repr(e))
-        sys.exit(1)
+        if 'keystore password was incorrect' in repr(e):
+            sys.exit(99)
+        sys.exit(77)