chiark / gitweb /
An experiment in automated building from source (git only, HEAD only)
authorCiaran Gultnieks <ciaran@ciarang.com>
Thu, 11 Nov 2010 00:03:39 +0000 (00:03 +0000)
committerCiaran Gultnieks <ciaran@ciarang.com>
Thu, 11 Nov 2010 00:03:39 +0000 (00:03 +0000)
.gitignore
build.py [new file with mode: 0644]
metadata/com.eleybourn.bookcatalogue.txt
metadata/org.fdroid.fdroid.txt
update.py

index fa03af79d025a821559ac4f902703096b3cf8e20..cb805bea05658efd5f0bb96b0a666c82df5fe3a3 100644 (file)
@@ -1,3 +1,5 @@
 config.py
 repo/
+unsigned/
+build_*/
 
diff --git a/build.py b/build.py
new file mode 100644 (file)
index 0000000..40a8fc7
--- /dev/null
+++ b/build.py
@@ -0,0 +1,171 @@
+# -*- coding: UTF-8 -*-
+#
+# build.py - part of the FDroid server tools
+# Copyright (C) 2010, Ciaran Gultnieks, ciaran@ciarang.com
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import sys
+import os
+import shutil
+import glob
+import subprocess
+import re
+import zipfile
+import md5
+from xml.dom.minidom import Document
+from optparse import OptionParser
+
+#Read configuration...
+execfile('config.py')
+
+# Parse command line...
+parser = OptionParser()
+parser.add_option("-v", "--verbose", action="store_true", default=False,
+                  help="Spew out even more information than normal")
+(options, args) = parser.parse_args()
+
+# Get all apps...
+apps = []
+
+for metafile in glob.glob(os.path.join('metadata','*.txt')):
+
+    thisinfo = {}
+
+    # Get metadata...
+    thisinfo['id'] = metafile[9:-4]
+    print "Reading metadata for " + thisinfo['id']
+    thisinfo['description'] = ''
+    thisinfo['summary'] = ''
+    thisinfo['license'] = 'Unknown'
+    thisinfo['web'] = ''
+    thisinfo['source'] = ''
+    thisinfo['tracker'] = ''
+    thisinfo['disabled'] = None
+    thisinfo['marketversion'] = ''
+    thisinfo['marketvercode'] = '0'
+    thisinfo['repotype'] = ''
+    thisinfo['repo'] = ''
+    f = open(metafile, 'r')
+    mode = 0
+    for line in f.readlines():
+        line = line.rstrip('\r\n')
+        if len(line) == 0:
+            pass
+        elif mode == 0:
+            index = line.find(':')
+            if index == -1:
+                print "Invalid metadata in " + metafile + " at:" + line
+                sys.exit(1)
+            field = line[:index]
+            value = line[index+1:]
+            if field == 'Description':
+                mode = 1
+            elif field == 'Summary':
+                thisinfo['summary'] = value
+            elif field == 'Source Code':
+                thisinfo['source'] = value
+            elif field == 'License':
+                thisinfo['license'] = value
+            elif field == 'Web Site':
+                thisinfo['web'] = value
+            elif field == 'Issue Tracker':
+                thisinfo['tracker'] = value
+            elif field == 'Disabled':
+                thisinfo['disabled'] = value
+            elif field == 'Market Version':
+                thisinfo['marketversion'] = value
+            elif field == 'Market Version Code':
+                thisinfo['marketvercode'] = value
+            elif field == 'Repo Type':
+                thisinfo['repotype'] = value
+            elif field == 'Repo':
+                thisinfo['repo'] = value
+            else:
+                print "Unrecognised field " + field
+                sys.exit(1)
+        elif mode == 1:
+            if line == '.':
+                mode = 0
+            else:
+                if len(line) == 0:
+                    thisinfo['description'] += '\n\n'
+                else:
+                    if (not thisinfo['description'].endswith('\n') and
+                        len(thisinfo['description']) > 0):
+                        thisinfo['description'] += ' '
+                    thisinfo['description'] += line
+    if len(thisinfo['description']) == 0:
+        thisinfo['description'] = 'No description available'
+
+    apps.append(thisinfo)
+
+unsigned_dir = 'unsigned'
+if os.path.exists(unsigned_dir):
+    shutil.rmtree(unsigned_dir)
+os.mkdir(unsigned_dir)
+
+for app in apps:
+
+    if app['disabled'] is None and app['repo'] != '' and app['repotype'] != '':
+
+        print "About to build " + app['id']
+
+        build_dir = 'build_' + app['id']
+
+        # Remove the build directory if it already exists...
+        if os.path.exists(build_dir):
+            shutil.rmtree(build_dir)
+
+        # Get the source code...
+        if app['repotype'] == 'git':
+            if subprocess.call(['git','clone',app['repo'],build_dir]) != 0:
+                print "Git clone failed"
+                sys.exit(1)
+        else:
+            print "Invalid repo type " + app['repotype'] + " in " + app['id']
+            sys.exit(1)
+
+        # Generate (or update) the ant build file, build.xml...
+        if subprocess.call(['android','update','project','-p','.'],
+                cwd=build_dir) != 0:
+            print "Failed to update project"
+            sys.exit(1)
+
+        # If the app has ant set up to sign the release, we need to switch
+        # that off, because we want the unsigned apk...
+        if os.path.exists(os.path.join(build_dir, 'build.properties')):
+            if subprocess.call(['sed','-i','s/^key.store/#/',
+                'build.properties'], cwd=build_dir) !=0:
+                print "Failed to amend build.properties"
+                sys.exit(1)
+
+        # Build the release...
+        p = subprocess.Popen(['ant','release'], cwd=build_dir, 
+                stdout=subprocess.PIPE)
+        output = p.communicate()[0]
+        print output
+        if p.returncode != 0:
+            print "Build failed"
+            sys.exit(1)
+
+        # Find the apk name in the output...
+        src = re.match(r".*^.*Creating (\S+) for release.*$.*", output,
+                re.S|re.M).group(1)
+        dest = os.path.join(unsigned_dir, app['id'] + '.apk')
+        shutil.copyfile(os.path.join( os.path.join(build_dir, 'bin'),
+            src), dest)
+
+print "Finished."
+
index f8da82f881c60e6a5a974846d421f6a191cb73ed..da1595a74726258ad874a281af31370d4be705f9 100644 (file)
@@ -9,3 +9,5 @@ This is a simple book catalogue application, to store a list of your books. Book
 
 Market Version:3.0.1
 Market Version Code:37
+Repo Type:git
+Repo:git://github.com/eleybourn/Book-Catalogue.git
index 30029d032c44adba5026d10ca11fe0c588384d97..c37980419ab31c9ef89521efdf00413a3ce9dc35 100644 (file)
@@ -7,4 +7,5 @@ Description:
 FDroid is a... wait a minute. You're running it, how can you not know what
 it is?
 .
-
+Repo Type:git
+Repo:git://gitorious.org/f-droid/fdroidclient.git
index a3c2a449f0c6b6aed2e7713ff6e78e273a420f16..af43b9ccec3cc1d7b51b97df7a983daf4fe3b345 100644 (file)
--- a/update.py
+++ b/update.py
@@ -175,9 +175,6 @@ for metafile in glob.glob(os.path.join('metadata','*.txt')):
                 thisinfo['marketversion'] = value
             elif field == 'Market Version Code':
                 thisinfo['marketvercode'] = value
-            else:
-                print "Unrecognised field " + field
-                sys.exit(1)
         elif mode == 1:
             if line == '.':
                 mode = 0