TPE-172 ABS: Use profile from tizen-manifest.xml
authorhyokeun <hyokeun.jeon@samsung.com>
Fri, 18 Aug 2017 07:15:46 +0000 (16:15 +0900)
committerhyokeun <hyokeun.jeon@samsung.com>
Fri, 18 Aug 2017 07:15:46 +0000 (16:15 +0900)
Change-Id: I8f5e9241618f511dd3d489110b85a7d1946c12cc

abs/job_abs_build.py
common/tizen_studio.py

index a1d1f44..1986d2b 100644 (file)
@@ -165,14 +165,15 @@ def set_gerrit_event(fields):
              'branch': fields.get('branch'), \
              'revision': fields.get('revision'), \
              'buildcheck': fields.get('full_build', None)}
-    _data['profile'] = _data.get('obs_project').split(':')[-1].lower()
 
-    # Set new branch and tag
-    if _data.get('branch').endswith('_' + _data.get('profile')):
-        _data['new_branch'] = _data.get('branch') + '_tpk'
-    else:
-        _data['new_branch'] = _data.get('branch') + '_' + _data.get('profile') + '_tpk'
-    _data['new_tag'] = _data.get('tag').replace(_data.get('branch'), _data.get('new_branch'))
+    #TODO: Profile will be fetched from tizen-manifest.xml
+    #_data['profile'] = _data.get('obs_project').split(':')[-1].lower()
+    ## Set new branch and tag
+    #if _data.get('branch').endswith('_' + _data.get('profile')):
+    #    _data['new_branch'] = _data.get('branch') + '_tpk'
+    #else:
+    #    _data['new_branch'] = _data.get('branch') + '_' + _data.get('profile') + '_tpk'
+    #_data['new_tag'] = _data.get('tag').replace(_data.get('branch'), _data.get('new_branch'))
 
     print 'TOUCHED_DATA:'
     for f in _data:
@@ -233,8 +234,15 @@ def retrieve_project_property(src_git, tag):
 
     def retrieve_properties_from_project_def(src_root):
 
+        sdk_package = ''
+        sdk_version = ''
+        sdk_profile = ''
+        ret_error = ''
+
+        # As guided, the last is the main app from multi project listup.
+        def_file_list = []
         # Single project
-        def_file = os.path.join(src_root, 'tizen-manifest.xml')
+        def_file_list.append(os.path.join(src_root, 'tizen-manifest.xml'))
         # Multi project
         multiproject_list_f = os.path.join(src_root, 'WORKSPACE')
         if os.path.isfile(multiproject_list_f):
@@ -242,17 +250,28 @@ def retrieve_project_property(src_git, tag):
                 for x in r_file.readlines():
                     if os.path.isdir(os.path.join(src_root, x.rstrip())) and \
                         os.path.isfile(os.path.join(src_root, x.rstrip(), 'tizen-manifest.xml')):
-                        def_file = os.path.join(src_root, x.rstrip(), 'tizen-manifest.xml')
-
-        print 'Property file: %s' % def_file
-        if os.path.isfile(def_file):
-            root = ElementTree.ElementTree(file=def_file).getroot()
-            sdk_package = root.attrib['package']
-            sdk_version = root.attrib['version']
-        else:
-            raise LocalError('Property file [%s] not found!' % def_file)
+                        def_file_list.append(os.path.join(src_root, x.rstrip(), 'tizen-manifest.xml'))
+
+        for def_file in def_file_list:
+            print 'Property file: %s' % def_file
+            if os.path.isfile(def_file):
+                try:
+                    with open(def_file, 'r') as df:
+                        manifest_dump = df.read()
+                    xmlstring = re.sub('\\sxmlns="[^"]+"', '', manifest_dump, count=1)
+                    _root = ElementTree.fromstring(xmlstring)
+                    for child in _root:
+                        if child.tag == 'profile':
+                            sdk_profile = child.attrib.get('name', sdk_profile)
+                            print 'Set SDK_PROFILE:[%s]' % sdk_profile
+                    sdk_package = _root.attrib.get('package', sdk_package)
+                    sdk_version = _root.attrib.get('version', sdk_version)
+                except Exception as err:
+                    continue
+        if not sdk_profile:
+            ret_error += 'ERROR: No "profile" tag in property file(tizen-manifest.xml)'
         print 'TIZEN-MANIFEST.XML (%s) (%s)' % (sdk_package, sdk_version)
-        return {'sdk_package': sdk_package, 'sdk_version': sdk_version}
+        return {'sdk_package': sdk_package, 'sdk_version': sdk_version, 'sdk_profile': sdk_profile, 'ret_error': ret_error}
 
     def retrieve_commit_id(src_git):
         commit_id = src_git.rev_parse('HEAD')
@@ -645,6 +664,16 @@ def start_build(fields):
 
     project_properties = retrieve_project_property(src_git, int_tag)
 
+    #TODO: 
+    print project_properties.get('sdk_profile')
+    data['profile'] = project_properties.get('sdk_profile')
+    # Set new branch and tag
+    if data.get('branch').endswith('_' + data.get('profile')):
+        data['new_branch'] = data.get('branch') + '_tpk'
+    else:
+        data['new_branch'] = data.get('branch') + '_' + data.get('profile') + '_tpk'
+    data['new_tag'] = data.get('tag').replace(data.get('branch'), data.get('new_branch'))
+
     mailer.add_title(data.get('obs_package'))
     mailer.add_title('(' + data.get('branch') + ')')
     if data.get('buildcheck', None):
@@ -653,6 +682,15 @@ def start_build(fields):
     mailer.add_message('Target OBS project: %s' % data.get('obs_project'))
     mailer.add_message('SR subject: %s' % project_properties.get('sr_message'), top=True)
 
+    #TODO:
+    if project_properties.get('ret_error') != '':
+        print 'You got property error:\n%s' % project_properties.get('ret_error')
+        if data.get('buildcheck', None) == None:
+            mailer.add_title('Property file parsing error')
+            mailer.add_message('Result: FAIL')
+            mailer.add_message('\n\n%s' % project_properties.get('ret_error'))
+        return 1
+
     # Make tarball to share source codes easily with vm machine
     zipping_workspace(src_root)
 
@@ -664,6 +702,9 @@ def start_build(fields):
     sys.stdout.flush()
     vm_image = ast.literal_eval(os.getenv('ABS_PROJECT_VM_MAP')).get(data.get('obs_project')).split(',')[0]
     my_tizen_studio = TizenStudio(vm_image)
+    for x in data:
+        print '[%s] %s' % (x, data[x])
+    sys.stdout.flush()
     ret = my_tizen_studio.build_app_source(package=data.get('package'), \
                                            profile=data.get('profile'), \
                                            gitpath=data.get('project'), \
index 7472613..bd6e5f3 100644 (file)
@@ -203,17 +203,6 @@ class TizenStudio(object):
     def build_app_source(self, package, profile=None, gitpath=None, build_mode='Release', parallel_jobs=''):
 
         PROFILE = profile
-        if gitpath:
-            print 'Force set profile from %s' % gitpath
-            if 'profile/mobile/apps/native/' in gitpath:
-                PROFILE = 'mobile'
-            elif 'profile/wearable/apps/native/' in gitpath:
-                PROFILE = 'wearable'
-            #TODO:
-            elif 'scm/test' in gitpath:
-                PROFILE = 'mobile'
-            else:
-                raise LocalError('Not supported profile %s' % gitpath)
 
         build_cmd = self.get_template('build')
         build_cmd = build_cmd.replace( \