Update build.xml to match the new repo structure
authorZhuoX Li <zhuox.li@intel.com>
Fri, 9 May 2014 06:48:25 +0000 (14:48 +0800)
committerLin Yang <lin.a.yang@intel.com>
Tue, 13 May 2014 02:27:36 +0000 (10:27 +0800)
One example shows as below:

<build version="1.0">
  <id>tizen_20140509.20</id>
  <buildtargets>
    <buildtarget name="ia32-wayland">
      <archs>
        <arch>ia32</arch>
      </archs>
      <repo type="debug">repos/ia32-wayland/debug</repo>
      <repo type="source">repos/ia32-wayland/source</repo>
      <repo type="binary">repos/ia32-wayland/packages</repo>
    </buildtarget>
    <buildtarget name="x86_64-wayland">
      <archs>
        <arch>x86_64</arch>
      </archs>
      <repo type="source">repos/x86_64-wayland/source</repo>
      <repo type="binary">repos/x86_64-wayland/packages</repo>
      <repo type="debug">repos/x86_64-wayland/debug</repo>
    </buildtarget>
  </buildtargets>
</build>

Fixes: #1863

Change-Id: Ie7545a0df1c3011510f50d351639565995edb712

common/builddata.py
tests/test_builddata.py

index 9f1b28a..c9a0947 100644 (file)
@@ -55,12 +55,23 @@ class BuildData(object):
         dom = minidom.parseString(xml)
         btargets = get_elem(dom, "buildtargets")
 
-        for btarget in btargets.getElementsByTagName("buildtarget"):
+        # load archs list
+        archs = {}
+        for arch_index, arch_value in \
+                enumerate(btargets.getElementsByTagName('archs')):
+            arch_list = []
+            for arch in arch_value.getElementsByTagName('arch'):
+                if arch.firstChild.data:
+                    arch_list.append(arch.firstChild.data)
+            archs[arch_index] = arch_list
+        # load buildtarget
+        for btarget_index, btarget in \
+                enumerate(btargets.getElementsByTagName("buildtarget")):
             target = {
-                "name":  btarget.getAttribute("name"),
-                "archs": [],
-                "repos": [],
-                }
+                    'name': btarget.getAttribute("name"),
+                    'repos': [],
+                    'archs': archs.get(btarget_index)
+                    }
 
             try:
                 bconf = get_elem(btarget, "buildconf")
@@ -79,8 +90,6 @@ class BuildData(object):
             # Get archs
             for repo in btarget.getElementsByTagName("repo"):
                 barch = repo.getAttribute("arch")
-                if barch and barch not in target["archs"]:
-                    target["archs"].append(barch)
                 target["repos"].append((repo.getAttribute("type"), barch,
                                         repo.firstChild.data))
 
@@ -90,19 +99,6 @@ class BuildData(object):
         """Format build data as xml."""
         content = '<?xml version="1.0"?><build version="1.0">'\
                   '<id>%s</id>' % self.build_id
-        # list of repos
-        content += '<repos>'
-        archs = []
-        for name, target in self.targets.iteritems():
-            content += '<repo>%s</repo>' % name
-            archs.extend(target['archs'])
-        content += '</repos>'
-
-        # list of architectures
-        content += '<archs>'
-        for arch in set(archs):
-            content += '<arch>%s</arch>' % arch
-        content += '</archs>'
 
         # build targets
         content += '<buildtargets>'
@@ -120,14 +116,20 @@ class BuildData(object):
                      buildconf['checksum']['value'])
                 content += '</buildconf>'
 
+            # list of architectures
+            content += '<archs>'
+            for arch in set(target['archs']):
+                content += '<arch>%s</arch>' % arch
+            content += '</archs>'
+
             # repos
             for rtype, rarch, rpath in target["repos"]:
-                if rarch:
-                    content += '<repo type="%s" arch="%s">%s</repo>' % (rtype,
-                                                                        rarch,
-                                                                        rpath)
-                else:
-                    content += '<repo type="%s">%s</repo>' % (rtype, rpath)
+                if rtype == 'noarch':
+                    rtype = 'binary'
+                target_repo_line = '<repo type="%s">%s</repo>' % (rtype, rpath)
+                if target_repo_line in content:
+                    continue
+                content += target_repo_line
 
             content += '</buildtarget>'
         content += '</buildtargets></build>'
index 483c048..f165ea1 100644 (file)
@@ -28,25 +28,18 @@ from common.builddata import BuildData, BuildDataError
 TEST_XML = """<?xml version="1.0" ?>
 <build version="1.0">
   <id>test.id</id>
-  <repos>
-    <repo>atom</repo>
-    <repo>exynos</repo>
-  </repos>
-  <archs>
-    <arch>x86_64</arch>
-    <arch>armv7l</arch>
-    <arch>i586</arch>
-  </archs>
   <buildtargets>
     <buildtarget name="atom">
       <buildconf>
         <location href="3bd64bd5fa862d99dbc363ccb1557d137b5685bc3bfe9a86bcbf50767da5e2e8-build.conf"/>
         <checksum type="sh256">3bd64bd5fa862d99dbc363ccb1557d137b5685bc3bfe9a86bcbf50767da5e2e8</checksum>
       </buildconf>
-      <repo arch="i586" type="binary">repos/atom/i586/packages</repo>
-      <repo arch="i586" type="binary">repos/atom/i586/debug</repo>
-      <repo arch="x86_64" type="binary">repos/atom/x86_64/packages</repo>
-      <repo arch="x86_64" type="binary">repos/atom/x86_64/debug</repo>
+      <archs>
+        <arch>x86_64</arch>
+        <arch>i586</arch>
+      </archs>
+      <repo type="binary">repos/atom/packages</repo>
+      <repo type="debug">repos/atom/debug</repo>
       <repo type="source">repos/atom/sources</repo>
     </buildtarget>
     <buildtarget name="exynos">
@@ -54,8 +47,11 @@ TEST_XML = """<?xml version="1.0" ?>
         <location href="3bd64bd5fa862d99dbc363ccb1557d137b5685bc3bfe9a86bcbf50767da5e2e8-build.conf"/>
         <checksum type="sh256">3bd64bd5fa862d99dbc363ccb1557d137b5685bc3bfe9a86bcbf50767da5e2e8</checksum>
       </buildconf>
-      <repo arch="armv7l" type="binary">repos/exynos/armv7l/packages</repo>
-      <repo arch="armv7l" type="binary">repos/exynos/armv7l/debug</repo>
+      <archs>
+        <arch>armv7l</arch>
+      </archs>
+      <repo type="binary">repos/exynos/packages</repo>
+      <repo type="debug">repos/exynos/debug</repo>
       <repo type="source">repos/exynos/sources</repo>
     </buildtarget>
   </buildtargets>
@@ -72,20 +68,18 @@ class BuildDataTest(unittest.TestCase):
         self.assertEqual(bdata.targets, OrderedDict(
             [(u'atom',
               {"repos":
-               [(u'binary', u'i586', u'repos/atom/i586/packages'),
-                (u'binary', u'i586', u'repos/atom/i586/debug'),
-                (u'binary', u'x86_64', u'repos/atom/x86_64/packages'),
-                (u'binary', u'x86_64', u'repos/atom/x86_64/debug'),
+               [(u'binary', '', u'repos/atom/packages'),
+                (u'debug', '', u'repos/atom/debug'),
                 (u'source', '', u'repos/atom/sources')],
                'buildconf':
                  {'checksum': {'type': u'sh256',
                   'value': u'3bd64bd5fa862d99dbc363ccb1557d137b5685bc3bfe9a86bcbf50767da5e2e8'},
                   'location':  u'3bd64bd5fa862d99dbc363ccb1557d137b5685bc3bfe9a86bcbf50767da5e2e8-build.conf'},
-               'name': u'atom', 'archs': [u'i586', u'x86_64']}),
+               'name': u'atom', 'archs': [u'x86_64', u'i586']}),
              (u'exynos',
               {"repos":
-               [(u'binary', u'armv7l', u'repos/exynos/armv7l/packages'),
-                (u'binary', u'armv7l', u'repos/exynos/armv7l/debug'),
+               [(u'binary', '', u'repos/exynos/packages'),
+                (u'debug', '', u'repos/exynos/debug'),
                 (u'source', '', u'repos/exynos/sources')],
                'buildconf':
                {'checksum': {'type': u'sh256',
@@ -113,8 +107,8 @@ class BuildDataTest(unittest.TestCase):
                       "location": 'build.conf'
                    },
                   "repos": [
-                      ("binary", "arm7vl", "repos/exynos/armv71/packages"),
-                      ("binary", "arm7vl", "repos/exynos/armv71/debug"),
+                      ("binary", "arm7vl", "repos/exynos/packages"),
+                      ("debug", None, "repos/exynos/debug"),
                       ("source", None, "repos/exynos/sources")]
                  }
 
@@ -127,7 +121,7 @@ class BuildDataTest(unittest.TestCase):
         bdata = BuildData(build_id='test.id')
         bdata.load(TEST_XML)
         self.assertEqual(bdata.to_xml(), TEST_XML)
-        self.assertEqual(len(bdata.to_xml(hreadable=False)), 1207)
+        self.assertEqual(len(bdata.to_xml(hreadable=False)), 962)
 
 
     def test_save(self):