Handle keystore error issue
[scm/meta/abs.git] / abs
diff --git a/abs b/abs
index 772a628..8076924 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.*']}
@@ -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):
@@ -248,8 +248,11 @@ class Sdk(object):
         """Run a tizen command"""
 
         cmd = [self.tizen, command] + args
+        if command == 'package':
+            cmd = ['dbus-run-session -- bash; echo build | gnome-keyring-daemon --unlock; '] + 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"""
@@ -344,7 +347,7 @@ class Sdk(object):
         myZipFile.close()
         return rsrc_zip
 
-    def build_native(self, source, rootstrap=None, arch=None, conf='Debug', jobs=None):
+    def build_tizen(self, source, rootstrap=None, arch=None, conf='Debug', jobs=None):
         """SDK CLI build command"""
 
         _rootstrap = self.check_rootstrap(rootstrap)
@@ -369,10 +372,18 @@ class Sdk(object):
             elif arch == 'arm': rootstrap = rootstrap.replace('emulator', 'device')
 
         for x in source.project_list:
-            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)
+            b_args = []
+            if x['web_app'] == True:
+                print '\n\n BUILD WEB\n'
+                b_args.extend(['--', x['path']])
+                out = self._run('build-web ', b_args, checker=True)
+            else:
+                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])
+                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):
@@ -386,6 +397,17 @@ 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:
+            raise LocalError('keystore password was incorrect 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
@@ -398,6 +420,7 @@ class Sdk(object):
 
         final_app = ''
         main_args = ['-t', pkg_type, '-s', cert]
+        main_args_web = ['-t', 'wgt', '-s', cert]
         out = '' #logfile
 
         # remove tpk or zip file on project path
@@ -405,6 +428,7 @@ class Sdk(object):
         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'))
+            package_list.extend(list_files(x['path'], ext='wgt'))
 
         for k in package_list :
             print ' package list ' + k;
@@ -412,12 +436,15 @@ 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')
 
             for i, x in enumerate(source.project_list):
                 dir = os.path.join(x['path'], conf)
+                if not os.path.isdir(dir):
+                    continue
                 files = [os.path.join(dir,f) for f in os.listdir(dir) if os.path.isfile(os.path.join(dir,f))]
 
                 # dir must be "project/Debug directory"
@@ -452,52 +479,76 @@ class Sdk(object):
 
                 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':
+            if x['web_app'] == False:
+                if x['type'] == 'app':
+                    print '\n\n PACKAGE NATIVE\n'
+                    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:
+                        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'])
+                    x['out_package'] = list_files(os.path.join(x['path'], conf), ext='zip')[0]
+                else:
+                    raise LocalError('Not supported project type %s' % x['type'])
+            elif x['web_app'] == True:
+                print '\n\n PACKAGE WEB\n'
                 out = '%s\n%s' % (out, \
-                      self._run('package', main_args + ['--',os.path.join(x['path'],conf)]))
+                      self._run('package', main_args_web + ['--', os.path.join(x['path'], '.buildResult')]))
                 try:
-                    final_app = list_files(os.path.join(x['path'], conf), ext='tpk')[0]
+                    final_app = list_files(os.path.join(x['path'], '.buildResult'), ext='wgt')[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'])
-                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']])
+                if x['out_package'] != final_app and x.get('type') == 'app':
+                    extra_args.extend(['-r', '"%s"' % x['out_package']])
+                elif x.get('type') == 'sharedLib':
+                    extra_args.extend(['-r', '"%s"' % x['out_package']])
 
-            extra_args.extend(['--', final_app])
-            out = self._run('package', main_args + extra_args)
+            extra_args.extend(['--', '"%s"' % final_app])
+            if final_app.endswith('.tpk'):
+                out = '%s\n\n%s' % (out, self._run('package', main_args + extra_args))
+            elif final_app.endswith('.wgt'):
+                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.
-        print 'Packaging final step again!'
-        out = self._run('package', main_args + ['--', final_app])
+        if final_app.endswith('.tpk'):
+            print 'Packaging final step again!'
+            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
 
         #Copy tpk to output directory
         if conf == 'Debug' and manual_strip == False :
             basename = os.path.splitext(final_app)[0]
-            newname = basename +'-debug.tpk'
+            if final_app.endswith('.tpk'):
+                newname = basename +'-debug.tpk'
+            elif final_app.endswith('.wgt'):
+                newname = basename +'-debug.wgt'
             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"""
 
@@ -540,9 +591,13 @@ class Source(object):
         mydict = {}
         cp = ConfigParser.SafeConfigParser()
         cp.optionxform = str
-        cp.readfp(FakeSecHead(open(os.path.join(path, 'project_def.prop'))))
-        for x in cp.items('ascection'):
-            mydict[x[0]] = x[1]
+        if self.is_web_app(path):
+            mydict['web_app'] = True
+        else:
+            mydict['web_app'] = False
+            cp.readfp(FakeSecHead(open(os.path.join(path, 'project_def.prop'))))
+            for x in cp.items('ascection'):
+                mydict[x[0]] = x[1]
         mydict['path'] = path
         return mydict
 
@@ -557,6 +612,11 @@ class Source(object):
             os.environ['USER_LINK_OPTS'] = link_opts
             print 'Set USER_LINK_OPTS=[%s]' % os.getenv('USER_LINK_OPTS')
 
+    def is_web_app(self, project_directory):
+        if os.path.isfile(os.path.join(project_directory, 'config.xml')):
+            return True
+        return False
+
     def pre_process(self):
 
         if os.path.isfile(os.path.join(self.workspace, self.multi_conf_file)):
@@ -622,7 +682,7 @@ def build_main(args):
         print '-------------------'
         my_sdk = Sdk(sdkpath=args.sdkpath, rootstrap_search=args.profiletosearch)
         my_sdk.clean(my_source)
-        my_sdk.build_native(my_source, rootstrap=args.rootstrap, arch=args.arch, jobs=args.jobs)
+        my_sdk.build_tizen(my_source, rootstrap=args.rootstrap, arch=args.arch, jobs=args.jobs)
         if args.conf == 'Debug' :
             my_sdk.package(my_source, pkg_type=args.type, cert=args.cert)
             my_sdk.package(my_source, pkg_type=args.type, cert=args.cert, manual_strip=True)
@@ -640,8 +700,6 @@ def build_main(args):
 def main(argv):
     """Script entry point."""
 
-    print 'ABS SCRIPT FROM GIT'
-
     args = argument_parsing(argv)
 
     if args.subcommands == 'build':
@@ -661,4 +719,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)