8 from optparse import OptionParser
11 def vagrant(params, cwd=None, printout=False):
14 :param: list of parameters to pass to vagrant
15 :cwd: directory to run in, or None for current directory
16 :printout: True to print output in realtime, False to just
18 :returns: (ret, out) where ret is the return code, and out
19 is the stdout (and stderr) from vagrant
21 p = subprocess.Popen(['vagrant'] + params, cwd=cwd,
22 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
26 line = p.stdout.readline()
33 out = p.communicate()[0]
34 return (p.returncode, out)
36 boxfile = 'buildserver.box'
37 serverdir = 'buildserver'
39 parser = OptionParser()
40 parser.add_option("-v", "--verbose", action="store_true", default=False,
41 help="Spew out even more information than normal")
42 parser.add_option("-c", "--clean", action="store_true", default=False,
43 help="Build from scratch, rather than attempting to update the existing server")
44 options, args = parser.parse_args()
47 execfile('makebs.config.py', config)
49 if not os.path.exists('makebuildserver') or not os.path.exists(serverdir):
50 print 'This must be run from the correct directory!'
53 if os.path.exists(boxfile):
57 vagrant(['destroy', '-f'], cwd=serverdir, printout=options.verbose)
59 # Update cached files.
60 cachedir = os.path.join('buildserver', 'cache')
61 if not os.path.exists(cachedir):
65 ('android-sdk_r24.3.4-linux.tgz',
66 'https://dl.google.com/android/android-sdk_r24.3.4-linux.tgz',
67 '886412375d8fe6e49a1583e57a8a36a47943666da681701ba9ad1ab7236e83ea'),
68 ('gradle-1.4-bin.zip',
69 'https://services.gradle.org/distributions/gradle-1.4-bin.zip',
70 'cd99e85fbcd0ae8b99e81c9992a2f10cceb7b5f009c3720ef3a0078f4f92e94e'),
71 ('gradle-1.6-bin.zip',
72 'https://services.gradle.org/distributions/gradle-1.6-bin.zip',
73 'de3e89d2113923dcc2e0def62d69be0947ceac910abd38b75ec333230183fac4'),
74 ('gradle-1.7-bin.zip',
75 'https://services.gradle.org/distributions/gradle-1.7-bin.zip',
76 '360c97d51621b5a1ecf66748c718594e5f790ae4fbc1499543e0c006033c9d30'),
77 ('gradle-1.8-bin.zip',
78 'https://services.gradle.org/distributions/gradle-1.8-bin.zip',
79 'a342bbfa15fd18e2482287da4959588f45a41b60910970a16e6d97959aea5703'),
80 ('gradle-1.9-bin.zip',
81 'https://services.gradle.org/distributions/gradle-1.9-bin.zip',
82 '097ddc2bcbc9da2bb08cbf6bf8079585e35ad088bafd42e8716bc96405db98e9'),
83 ('gradle-1.10-bin.zip',
84 'https://services.gradle.org/distributions/gradle-1.10-bin.zip',
85 '6e6db4fc595f27ceda059d23693b6f6848583950606112b37dfd0e97a0a0a4fe'),
86 ('gradle-1.11-bin.zip',
87 'https://services.gradle.org/distributions/gradle-1.11-bin.zip',
88 '07e235df824964f0e19e73ea2327ce345c44bcd06d44a0123d29ab287fc34091'),
89 ('gradle-1.12-bin.zip',
90 'https://services.gradle.org/distributions/gradle-1.12-bin.zip',
91 '8734b13a401f4311ee418173ed6ca8662d2b0a535be8ff2a43ecb1c13cd406ea'),
92 ('gradle-2.1-bin.zip',
93 'https://services.gradle.org/distributions/gradle-2.1-bin.zip',
94 '3eee4f9ea2ab0221b89f8e4747a96d4554d00ae46d8d633f11cfda60988bf878'),
95 ('gradle-2.2.1-bin.zip',
96 'https://services.gradle.org/distributions/gradle-2.2.1-bin.zip',
97 '420aa50738299327b611c10b8304b749e8d3a579407ee9e755b15921d95ff418'),
98 ('gradle-2.3-bin.zip',
99 'https://services.gradle.org/distributions/gradle-2.3-bin.zip',
100 '010dd9f31849abc3d5644e282943b1c1c355f8e2635c5789833979ce590a3774'),
101 ('gradle-2.4-bin.zip',
102 'https://services.gradle.org/distributions/gradle-2.4-bin.zip',
103 'c4eaecc621a81f567ded1aede4a5ddb281cc02a03a6a87c4f5502add8fc2f16f'),
104 ('gradle-2.5-bin.zip',
105 'https://services.gradle.org/distributions/gradle-2.5-bin.zip',
106 '3f953e0cb14bb3f9ebbe11946e84071547bf5dfd575d90cfe9cc4e788da38555'),
107 ('gradle-2.6-bin.zip',
108 'https://services.gradle.org/distributions/gradle-2.6-bin.zip',
109 '18a98c560af231dfa0d3f8e0802c20103ae986f12428bb0a6f5396e8f14e9c83'),
110 ('Kivy-1.7.2.tar.gz',
111 'https://pypi.python.org/packages/source/K/Kivy/Kivy-1.7.2.tar.gz',
112 '0485e2ef97b5086df886eb01f8303cb542183d2d71a159466f99ad6c8a1d03f1'),
117 ('android-ndk-r10e-linux-x86_64.bin',
118 'https://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.bin',
119 '102d6723f67ff1384330d12c45854315d6452d6510286f4e5891e00a5a8f1d5a'),
120 ('android-ndk-r9b-linux-x86_64.tar.bz2',
121 'https://dl.google.com/android/ndk/android-ndk-r9b-linux-x86_64.tar.bz2',
122 '8956e9efeea95f49425ded8bb697013b66e162b064b0f66b5c75628f76e0f532'),
123 ('android-ndk-r9b-linux-x86_64-legacy-toolchains.tar.bz2',
124 'https://dl.google.com/android/ndk/android-ndk-r9b-linux-x86_64-legacy-toolchains.tar.bz2',
125 'de93a394f7c8f3436db44568648f87738a8d09801a52f459dcad3fc047e045a1')])
128 ('android-ndk-r10e-linux-x86.bin',
129 'https://dl.google.com/android/ndk/android-ndk-r10e-linux-x86.bin',
130 '92b07d25aaad9b341a7f2b2a62402d508e948bf2dea3ee7b65a6aeb18bca7df5'),
131 ('android-ndk-r9b-linux-x86.tar.bz2',
132 'https://dl.google.com/android/ndk/android-ndk-r9b-linux-x86.tar.bz2',
133 '748104b829dd12afb2fdb3044634963abb24cdb0aad3b26030abe2e9e65bfc81'),
134 ('android-ndk-r9b-linux-x86-legacy-toolchains.tar.bz2',
135 'https://dl.google.com/android/ndk/android-ndk-r9b-linux-x86-legacy-toolchains.tar.bz2',
136 '606aadf815ae28cc7b0154996247c70d609f111b14e44bcbcd6cad4c87fefb6f')])
140 def sha256_for_file(path):
141 with open(path, 'r') as f:
150 for f, src, shasum in cachefiles:
151 relpath = os.path.join(cachedir, f)
152 if not os.path.exists(relpath):
153 print "Downloading " + f + " to cache"
154 if subprocess.call(['wget', src], cwd=cachedir) != 0:
155 print "...download of " + f + " failed."
158 v = sha256_for_file(relpath)
160 print "Invalid shasum of '" + v + "' detected for " + f
163 print "...shasum verified for " + f
168 # Generate an appropriate Vagrantfile for the buildserver, based on our
171 Vagrant.configure("2") do |config|
173 config.vm.box = "{0}"
174 config.vm.box_url = "{1}"
176 config.vm.provider "virtualbox" do |v|
177 v.customize ["modifyvm", :id, "--memory", "{2}"]
178 v.customize ["modifyvm", :id, "--cpus", "{3}"]
181 config.vm.provision :shell, :path => "fixpaths.sh"
182 """.format(config['basebox'],
183 config['baseboxurl'],
185 config.get('cpus', 1))
186 if 'aptproxy' in config and config['aptproxy']:
188 config.vm.provision :shell, :inline => 'sudo echo "Acquire::http {{ Proxy \\"{0}\\"; }};" > /etc/apt/apt.conf.d/02proxy && sudo apt-get update'
189 """.format(config['aptproxy'])
191 config.vm.provision :chef_solo do |chef|
192 chef.cookbooks_path = "cookbooks"
193 chef.log_level = :debug
196 :sdk_loc => "/home/vagrant/android-sdk",
197 :ndk_loc => "/home/vagrant/android-ndk",
201 chef.add_recipe "fdroidbuild-general"
202 chef.add_recipe "android-sdk"
203 chef.add_recipe "android-ndk"
204 chef.add_recipe "gradle"
205 chef.add_recipe "kivy"
210 # Check against the existing Vagrantfile, and if they differ, we need to
212 vf = os.path.join(serverdir, 'Vagrantfile')
214 if os.path.exists(vf):
215 vagrant(['halt'], serverdir)
216 with open(vf, 'r') as f:
218 if oldvf != vagrantfile:
219 print "Server configuration has changed, rebuild from scratch is required"
220 vagrant(['destroy', '-f'], serverdir)
222 print "Re-provisioning existing server"
225 print "No existing server - building from scratch"
227 with open(vf, 'w') as f:
231 print "Configuring build server VM"
232 returncode, out = vagrant(['up'], serverdir, printout=True)
233 with open(os.path.join(serverdir, 'up.log'), 'w') as log:
236 print "Failed to configure server"
239 print "Writing buildserver ID"
240 p = subprocess.Popen(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE)
241 buildserverid = p.communicate()[0].strip()
242 print "...ID is " + buildserverid
244 ['vagrant', 'ssh', '-c', 'sh -c "echo {0} >/home/vagrant/buildserverid"'
245 .format(buildserverid)],
248 print "Stopping build server VM"
249 vagrant(['halt'], serverdir)
251 print "Waiting for build server VM to be finished"
255 returncode, out = vagrant(['status'], serverdir)
257 print "Error while checking status"
259 for line in out.splitlines():
260 if line.startswith("default"):
261 if line.find("poweroff") != -1:
264 print "Status: " + line
267 vagrant(['package', '--output', os.path.join('..', boxfile)], serverdir,
268 printout=options.verbose)
270 vagrant(['box', 'add', 'buildserver', boxfile, '-f'],
271 printout=options.verbose)