blob: fa00cb75c0fcbc3e386a3b3bb35b1aaaf78d00a9 [file] [log] [blame]
jljusten267865e2011-02-23 22:21:00 +00001#!/usr/bin/python
2#
Jordan Justen4272d1a2014-01-03 19:19:26 +00003# Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
jljusten267865e2011-02-23 22:21:00 +00004#
5# This program and the accompanying materials
6# are licensed and made available under the terms and conditions of the BSD License
7# which accompanies this distribution. The full text of the license may be found at
8# http://opensource.org/licenses/bsd-license.php
9#
10# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12#
13
jljusten267865e2011-02-23 22:21:00 +000014import os
15import re
16import StringIO
17import subprocess
18import sys
19import zipfile
20
21is_unix = not sys.platform.startswith('win')
22
23if not is_unix:
24 print "This script currently only supports unix-like systems"
25 sys.exit(-1)
26
27if os.path.exists('OvmfPkgX64.dsc'):
28 os.chdir('..')
29
30if not os.path.exists(os.path.join('OvmfPkg', 'OvmfPkgX64.dsc')):
31 print "OvmfPkg/OvmfPkgX64.dsc doesn't exist"
32 sys.exit(-1)
33
jljusten267865e2011-02-23 22:21:00 +000034def run_and_capture_output(args, checkExitCode = True):
35 p = subprocess.Popen(args=args, stdout=subprocess.PIPE)
36 stdout = p.stdout.read()
37 ret_code = p.wait()
38 if checkExitCode:
39 assert ret_code == 0
40 return stdout
41
Jordan Justen6d3d4a72014-01-03 19:19:32 +000042gcc_version = run_and_capture_output(args=('gcc', '--version'))
43gcc_re = re.compile(r'\s*\S+\s+\([^\)]+?\)\s+(\d+(?:\.\d+)*)(?:\s+.*)?')
44mo = gcc_re.match(gcc_version)
45if not mo:
46 print "Unable to find GCC version"
47 sys.exit(-1)
48gcc_version = map(lambda n: int(n), mo.group(1).split('.'))
49
50if 'TOOLCHAIN' in os.environ:
51 TOOLCHAIN = os.environ['TOOLCHAIN']
52else:
53 assert(gcc_version[0] == 4)
54 minor = max(4, min(7, gcc_version[1]))
55 TOOLCHAIN = 'GCC4' + str(minor)
56
Jordan Justen57dcb832014-01-03 19:19:38 +000057def git_based_version():
jljusten267865e2011-02-23 22:21:00 +000058 dir = os.getcwd()
Jordan Justen57dcb832014-01-03 19:19:38 +000059 if not os.path.exists('.git'):
60 os.chdir('OvmfPkg')
61 stdout = run_and_capture_output(args=('git', 'log',
62 '-n', '1',
63 '--abbrev-commit'))
64 regex = re.compile(r'^\s*git-svn-id:\s+\S+@(\d+)\s+[0-9a-f\-]+$',
65 re.MULTILINE)
66 mo = regex.search(stdout)
67 if mo:
68 version = 'r' + mo.group(1)
69 else:
70 version = stdout.split(None, 3)[1]
jljusten267865e2011-02-23 22:21:00 +000071 os.chdir(dir)
Jordan Justen57dcb832014-01-03 19:19:38 +000072 return version
jljusten267865e2011-02-23 22:21:00 +000073
74def svn_info():
75 dir = os.getcwd()
76 os.chdir('OvmfPkg')
77 stdout = run_and_capture_output(args=('svn', 'info'))
78 os.chdir(dir)
79 return stdout
80
Jordan Justen57dcb832014-01-03 19:19:38 +000081def svn_based_version():
82 buf = svn_info()
83 revision_re = re.compile('^Revision\:\s*([\da-f]+)$', re.MULTILINE)
84 mo = revision_re.search(buf)
85 assert(mo is not None)
86 return 'r' + mo.group(1)
jljusten267865e2011-02-23 22:21:00 +000087
88def get_revision():
Jordan Justen57dcb832014-01-03 19:19:38 +000089 if os.path.exists(os.path.join('OvmfPkg', '.svn')):
90 return svn_based_version()
91 else:
92 return git_based_version()
jljusten267865e2011-02-23 22:21:00 +000093
94revision = get_revision()
95
96newline_re = re.compile(r'(\n|\r\n|\r(?!\n))', re.MULTILINE)
97def to_dos_text(str):
98 return newline_re.sub('\r\n', str)
99
100def gen_build_info():
101 distro = run_and_capture_output(args=('lsb_release', '-sd')).strip()
102
103 machine = run_and_capture_output(args=('uname', '-m')).strip()
104
Jordan Justen6d3d4a72014-01-03 19:19:32 +0000105 gcc_version_str = '.'.join(map(lambda v: str(v), gcc_version))
jljusten267865e2011-02-23 22:21:00 +0000106
107 ld_version = run_and_capture_output(args=('ld', '--version'))
108 ld_version = ld_version.split('\n')[0].split()[-1]
109
110 iasl_version = run_and_capture_output(args=('iasl'), checkExitCode=False)
111 iasl_version = filter(lambda s: s.find(' version ') >= 0, iasl_version.split('\n'))[0]
112 iasl_version = iasl_version.split(' version ')[1].strip()
113
114 sb = StringIO.StringIO()
Jordan Justen57dcb832014-01-03 19:19:38 +0000115 print >> sb, 'edk2: ', revision
Jordan Justen6d3d4a72014-01-03 19:19:32 +0000116 print >> sb, 'compiler: GCC', gcc_version_str, '(' + TOOLCHAIN + ')'
jljusten267865e2011-02-23 22:21:00 +0000117 print >> sb, 'binutils:', ld_version
118 print >> sb, 'iasl: ', iasl_version
119 print >> sb, 'system: ', distro, machine.replace('_', '-')
120 return to_dos_text(sb.getvalue())
121
122LICENSE = to_dos_text(
123'''This OVMF binary release is built from source code licensed under
124the BSD open source license. The BSD license is documented at
125http://opensource.org/licenses/bsd-license.php, and a copy is
126shown below.
127
128One sub-component of the OVMF project is a FAT filesystem driver. The FAT
129filesystem driver code is also BSD licensed, but the code license contains
130one additional term. This license can be found at
131http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=Edk2-fat-driver,
132and a copy is shown below (following the normal BSD license).
133
134=== BSD license: START ===
135
136Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
137
138Redistribution and use in source and binary forms, with or without
139modification, are permitted provided that the following conditions
140are met:
141
142* Redistributions of source code must retain the above copyright
143 notice, this list of conditions and the following disclaimer.
144* Redistributions in binary form must reproduce the above copyright
145 notice, this list of conditions and the following disclaimer in
146 the documentation and/or other materials provided with the
147 distribution.
148* Neither the name of the Intel Corporation nor the names of its
149 contributors may be used to endorse or promote products derived
150 from this software without specific prior written permission.
151
152THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
153"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
154LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
155FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
156COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
157INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
158BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
159LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
160CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
161LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
162ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
163POSSIBILITY OF SUCH DAMAGE.
164
165=== BSD license: END ===
166
167=== FAT filesystem driver license: START ===
168
169Copyright (c) 2004, Intel Corporation. All rights reserved.
170
171Redistribution and use in source and binary forms, with or without
172modification, are permitted provided that the following conditions
173are met:
174
175* Redistributions of source code must retain the above copyright
176 notice, this list of conditions and the following disclaimer.
177* Redistributions in binary form must reproduce the above copyright
178 notice, this list of conditions and the following disclaimer in
179 the documentation and/or other materials provided with the
180 distribution.
181* Neither the name of Intel nor the names of its
182 contributors may be used to endorse or promote products derived
183 from this software without specific prior written permission.
184
185THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
187LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
188FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
189COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
190INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
191BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
192LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
193CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
194LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
195ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
196POSSIBILITY OF SUCH DAMAGE.
197
198Additional terms:
199In addition to the forgoing, redistribution and use of the code is
200conditioned upon the FAT 32 File System Driver and all derivative
201works thereof being used for and designed only to read and/or write
202to a file system that is directly managed by an Extensible Firmware
203Interface (EFI) implementation or by an emulator of an EFI
204implementation.
205
206=== FAT filesystem driver license: END ===
207''')
208
209def build(arch):
210 args = (
211 'OvmfPkg/build.sh',
212 '-t', TOOLCHAIN,
213 '-a', arch,
214 '-b', 'RELEASE'
215 )
216 logname = 'build-%s.log' % arch
217 build_log = open(logname, 'w')
218 print 'Building OVMF for', arch, '(%s)' % logname, '...',
219 sys.stdout.flush()
220 p = subprocess.Popen(args=args, stdout=build_log, stderr=build_log)
221 ret_code = p.wait()
222 if ret_code == 0:
223 print '[done]'
224 else:
225 print '[error 0x%x]' % ret_code
226 return ret_code
227
228def create_zip(arch):
229 global build_info
Jordan Justen57dcb832014-01-03 19:19:38 +0000230 filename = 'OVMF-%s-%s.zip' % (arch, revision)
jljusten267865e2011-02-23 22:21:00 +0000231 print 'Creating', filename, '...',
232 sys.stdout.flush()
233 if os.path.exists(filename):
234 os.remove(filename)
235 zipf = zipfile.ZipFile(filename, 'w', zipfile.ZIP_DEFLATED)
236
237 zipf.writestr('BUILD_INFO', build_info)
238 zipf.writestr('LICENSE', LICENSE)
239 zipf.write(os.path.join('OvmfPkg', 'README'), 'README')
240 FV_DIR = os.path.join(
241 'Build',
242 'Ovmf' + arch.title(),
243 'RELEASE_' + TOOLCHAIN,
244 'FV'
245 )
246 zipf.write(os.path.join(FV_DIR, 'OVMF.fd'), 'OVMF.fd')
jljusten267865e2011-02-23 22:21:00 +0000247 zipf.close()
248 print '[done]'
249
250build_info = gen_build_info()
251build('IA32')
252build('X64')
253create_zip('IA32')
254create_zip('X64')
255
256