blob: 3099d27d6cd6fe3d661f97d8f13a9bb15339a825 [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
jljusten267865e2011-02-23 22:21:00 +000057def git_svn_info():
58 dir = os.getcwd()
59 os.chdir('OvmfPkg')
60 stdout = run_and_capture_output(args=('git', 'svn', 'info'))
61 os.chdir(dir)
62 return stdout
63
64def svn_info():
65 dir = os.getcwd()
66 os.chdir('OvmfPkg')
67 stdout = run_and_capture_output(args=('svn', 'info'))
68 os.chdir(dir)
69 return stdout
70
71def get_svn_info_output():
72 if os.path.exists(os.path.join('OvmfPkg', '.svn')):
73 return svn_info()
74 else:
75 return git_svn_info()
76
77def get_revision():
78 buf = get_svn_info_output()
79 revision_re = re.compile('^Revision\:\s*(\d+)$', re.MULTILINE)
80 mo = revision_re.search(buf)
81 if mo is not None:
82 return int(mo.group(1))
83
84revision = get_revision()
85
86newline_re = re.compile(r'(\n|\r\n|\r(?!\n))', re.MULTILINE)
87def to_dos_text(str):
88 return newline_re.sub('\r\n', str)
89
90def gen_build_info():
91 distro = run_and_capture_output(args=('lsb_release', '-sd')).strip()
92
93 machine = run_and_capture_output(args=('uname', '-m')).strip()
94
Jordan Justen6d3d4a72014-01-03 19:19:32 +000095 gcc_version_str = '.'.join(map(lambda v: str(v), gcc_version))
jljusten267865e2011-02-23 22:21:00 +000096
97 ld_version = run_and_capture_output(args=('ld', '--version'))
98 ld_version = ld_version.split('\n')[0].split()[-1]
99
100 iasl_version = run_and_capture_output(args=('iasl'), checkExitCode=False)
101 iasl_version = filter(lambda s: s.find(' version ') >= 0, iasl_version.split('\n'))[0]
102 iasl_version = iasl_version.split(' version ')[1].strip()
103
104 sb = StringIO.StringIO()
105 print >> sb, 'edk2: ', 'r%d' % revision
Jordan Justen6d3d4a72014-01-03 19:19:32 +0000106 print >> sb, 'compiler: GCC', gcc_version_str, '(' + TOOLCHAIN + ')'
jljusten267865e2011-02-23 22:21:00 +0000107 print >> sb, 'binutils:', ld_version
108 print >> sb, 'iasl: ', iasl_version
109 print >> sb, 'system: ', distro, machine.replace('_', '-')
110 return to_dos_text(sb.getvalue())
111
112LICENSE = to_dos_text(
113'''This OVMF binary release is built from source code licensed under
114the BSD open source license. The BSD license is documented at
115http://opensource.org/licenses/bsd-license.php, and a copy is
116shown below.
117
118One sub-component of the OVMF project is a FAT filesystem driver. The FAT
119filesystem driver code is also BSD licensed, but the code license contains
120one additional term. This license can be found at
121http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=Edk2-fat-driver,
122and a copy is shown below (following the normal BSD license).
123
124=== BSD license: START ===
125
126Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
127
128Redistribution and use in source and binary forms, with or without
129modification, are permitted provided that the following conditions
130are met:
131
132* Redistributions of source code must retain the above copyright
133 notice, this list of conditions and the following disclaimer.
134* Redistributions in binary form must reproduce the above copyright
135 notice, this list of conditions and the following disclaimer in
136 the documentation and/or other materials provided with the
137 distribution.
138* Neither the name of the Intel Corporation nor the names of its
139 contributors may be used to endorse or promote products derived
140 from this software without specific prior written permission.
141
142THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
143"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
144LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
145FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
146COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
147INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
148BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
149LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
150CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
151LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
152ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
153POSSIBILITY OF SUCH DAMAGE.
154
155=== BSD license: END ===
156
157=== FAT filesystem driver license: START ===
158
159Copyright (c) 2004, Intel Corporation. All rights reserved.
160
161Redistribution and use in source and binary forms, with or without
162modification, are permitted provided that the following conditions
163are met:
164
165* Redistributions of source code must retain the above copyright
166 notice, this list of conditions and the following disclaimer.
167* Redistributions in binary form must reproduce the above copyright
168 notice, this list of conditions and the following disclaimer in
169 the documentation and/or other materials provided with the
170 distribution.
171* Neither the name of Intel nor the names of its
172 contributors may be used to endorse or promote products derived
173 from this software without specific prior written permission.
174
175THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
177LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
178FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
179COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
180INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
181BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
182LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
183CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
184LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
185ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
186POSSIBILITY OF SUCH DAMAGE.
187
188Additional terms:
189In addition to the forgoing, redistribution and use of the code is
190conditioned upon the FAT 32 File System Driver and all derivative
191works thereof being used for and designed only to read and/or write
192to a file system that is directly managed by an Extensible Firmware
193Interface (EFI) implementation or by an emulator of an EFI
194implementation.
195
196=== FAT filesystem driver license: END ===
197''')
198
199def build(arch):
200 args = (
201 'OvmfPkg/build.sh',
202 '-t', TOOLCHAIN,
203 '-a', arch,
204 '-b', 'RELEASE'
205 )
206 logname = 'build-%s.log' % arch
207 build_log = open(logname, 'w')
208 print 'Building OVMF for', arch, '(%s)' % logname, '...',
209 sys.stdout.flush()
210 p = subprocess.Popen(args=args, stdout=build_log, stderr=build_log)
211 ret_code = p.wait()
212 if ret_code == 0:
213 print '[done]'
214 else:
215 print '[error 0x%x]' % ret_code
216 return ret_code
217
218def create_zip(arch):
219 global build_info
Jordan Justen4272d1a2014-01-03 19:19:26 +0000220 filename = 'OVMF-%s-r%d.zip' % (arch, revision)
jljusten267865e2011-02-23 22:21:00 +0000221 print 'Creating', filename, '...',
222 sys.stdout.flush()
223 if os.path.exists(filename):
224 os.remove(filename)
225 zipf = zipfile.ZipFile(filename, 'w', zipfile.ZIP_DEFLATED)
226
227 zipf.writestr('BUILD_INFO', build_info)
228 zipf.writestr('LICENSE', LICENSE)
229 zipf.write(os.path.join('OvmfPkg', 'README'), 'README')
230 FV_DIR = os.path.join(
231 'Build',
232 'Ovmf' + arch.title(),
233 'RELEASE_' + TOOLCHAIN,
234 'FV'
235 )
236 zipf.write(os.path.join(FV_DIR, 'OVMF.fd'), 'OVMF.fd')
jljusten267865e2011-02-23 22:21:00 +0000237 zipf.close()
238 print '[done]'
239
240build_info = gen_build_info()
241build('IA32')
242build('X64')
243create_zip('IA32')
244create_zip('X64')
245
246