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