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