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