-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuilder.ts
386 lines (351 loc) · 15.6 KB
/
builder.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/*******************************************************************************
* Copyright (c) 2020, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/
import * as exec from '@actions/exec'
import * as core from '@actions/core'
import * as tc from '@actions/tool-cache'
import * as io from '@actions/io'
import * as path from 'path'
import * as fs from 'fs'
import * as childProcess from 'child_process'
import {ExecOptions} from '@actions/exec/lib/interfaces'
const workDir = process.env['GITHUB_WORKSPACE']
const IS_WINDOWS = process.platform === "win32"
const targetOs = IS_WINDOWS ? 'windows' : process.platform === 'darwin' ? 'mac' : 'linux'
let tempDirectory = process.env['RUNNER_TEMP'] || ''
if (!tempDirectory) {
let baseLocation;
if (IS_WINDOWS) {
// On windows use the USERPROFILE env variable
baseLocation = process.env['USERPROFILE'] || 'C:\\';
} else if (process.platform === 'darwin') {
baseLocation = '/Users'
} else {
baseLocation = '/home'
}
tempDirectory = path.join(baseLocation, 'actions', 'temp')
}
export async function buildJDK(
version: string,
usePersonalRepo: boolean
): Promise<void> {
const openj9Version = `openj9-openjdk-jdk${version}`
await installDependencies(version)
process.chdir(`${workDir}`)
await getBootJdk(version)
process.chdir(`${workDir}`)
await getSource(openj9Version, usePersonalRepo)
await setConfigure(version, openj9Version)
await exec.exec(`make all`)
await printJavaVersion(version, openj9Version)
}
async function installDependencies(version: string): Promise<void> {
if (`${targetOs}` === 'mac') {
await installMacDepends()
} else if (`${targetOs}` === 'linux') {
await installLinuxDepends(version)
} else {
await installWindowsDepends(version)
}
await installCommons()
}
async function installCommons(): Promise<void> {
if (!IS_WINDOWS) {
process.chdir(`${workDir}`)
const freeMarker = await tc.downloadTool(`https://sourceforge.net/projects/freemarker/files/freemarker/2.3.8/freemarker-2.3.8.tar.gz/download`)
await exec.exec(`sudo tar -xzf ${freeMarker} freemarker-2.3.8/lib/freemarker.jar --strip=2`)
await io.rmRF(`${freeMarker}`)
}
}
async function installMacDepends(): Promise<void> {
await exec.exec('brew install autoconf ccache coreutils bash nasm gnu-tar')
core.addPath('/usr/local/opt/gnu-tar/libexec/gnubin')
core.info(`path is ${process.env['PATH']}`)
}
async function installLinuxDepends(version: string): Promise<void> {
const ubuntuVersion = await getOsVersion()
if (`${ubuntuVersion}` === '16.04') {
await exec.exec('sudo apt-get update')
await exec.exec(
'sudo apt-get install -qq -y --no-install-recommends \
python-software-properties \
realpath'
)
}
await exec.exec(`sudo apt-get update`)
await exec.exec(
'sudo apt-get install -qq -y --no-install-recommends \
software-properties-common \
autoconf \
cpio \
libasound2-dev \
libcups2-dev \
libdwarf-dev \
libelf-dev \
libfontconfig1-dev \
libfreetype6-dev \
libx11-dev \
libxext-dev \
libxrender-dev \
libxt-dev \
libxtst-dev \
make \
libnuma-dev \
nasm \
pkg-config \
ssh \
gcc-multilib'
)
if (version === '8') {
await exec.exec('sudo add-apt-repository ppa:openjdk-r/ppa')
await exec.exec(`sudo apt-get update`)
await exec.exec(
'sudo apt-get install -qq -y --no-install-recommends openjdk-8-jdk'
)
} else {
await exec.exec(`sudo apt-get update`)
await exec.exec(
'sudo apt-get install -qq -y --no-install-recommends libxrandr-dev'
)
}
await io.rmRF(`/var/lib/apt/lists/*`)
//install cuda9
const cuda9 = await tc.downloadTool('https://developer.nvidia.com/compute/cuda/9.0/Prod/local_installers/cuda_9.0.176_384.81_linux-run')
await exec.exec(`sudo sh ${cuda9} --silent --toolkit --override`)
await io.rmRF(`${cuda9}`)
process.chdir('/usr/local')
//install gcc binary
const gccBinary = await tc.downloadTool(`https://ci.adoptopenjdk.net/userContent/gcc/gcc730+ccache.x86_64.tar.xz`)
await exec.exec(`ls -l ${gccBinary}`)
await exec.exec(`sudo tar -xJ --strip-components=1 -C /usr/local -f ${gccBinary}`)
await io.rmRF(`${gccBinary}`)
await exec.exec(`sudo ln -s /usr/lib/x86_64-linux-gnu /usr/lib64`)
await exec.exec(`sudo ln -s /usr/include/x86_64-linux-gnu/* /usr/local/include`)
await exec.exec(`sudo ln -sf /usr/local/bin/g++-7.3 /usr/bin/g++`)
await exec.exec(`sudo ln -sf /usr/local/bin/gcc-7.3 /usr/bin/gcc`)
process.env.LIBRARY_PATH=`/usr/lib/x86_64-linux-gnu:${process.env.LIBRARY_PATH}`
}
async function installWindowsDepends(version: string): Promise<void> {
//install cgywin
await io.mkdirP('C:\\cygwin64')
await io.mkdirP('C:\\cygwin_packages')
await tc.downloadTool('https://cygwin.com/setup-x86_64.exe', 'C:\\temp\\cygwin.exe')
await exec.exec(`C:\\temp\\cygwin.exe --packages wget,bsdtar,rsync,gnupg,git,autoconf,make,gcc-core,mingw64-x86_64-gcc-core,unzip,zip,cpio,curl,grep,perl --quiet-mode --download --local-install
--delete-orphans --site https://mirrors.kernel.org/sourceware/cygwin/
--local-package-dir "C:\\cygwin_packages"
--root "C:\\cygwin64"`)
await exec.exec(`C:/cygwin64/bin/git config --system core.autocrlf false`)
core.addPath(`C:\\cygwin64\\bin`)
//freeMarker
await tc.downloadTool(`https://repo.maven.apache.org/maven2/freemarker/freemarker/2.3.8/freemarker-2.3.8.jar`, `${workDir}\\freemarker.jar`)
//nasm
await io.mkdirP('C:\\nasm')
await tc.downloadTool(`https://www.nasm.us/pub/nasm/releasebuilds/2.13.03/win64/nasm-2.13.03-win64.zip`, 'C:\\temp\\nasm.zip')
await tc.extractZip('C:\\temp\\nasm.zip', 'C:\\nasm')
const nasmdir = path.join('C:\\nasm', fs.readdirSync('C:\\nasm')[0])
core.addPath(nasmdir)
await io.rmRF('C:\\temp\\nasm.zip')
//llvm
await tc.downloadTool('https://ci.adoptopenjdk.net/userContent/winansible/llvm-7.0.0-win64.zip', 'C:\\temp\\llvm.zip')
await tc.extractZip('C:\\temp\\llvm.zip', 'C:\\')
await io.rmRF('C:\\temp\\llvm.zip')
core.addPath('C:\\Program Files\\LLVM\\bin')
//cuda
await tc.downloadTool('https://developer.nvidia.com/compute/cuda/9.0/Prod/network_installers/cuda_9.0.176_win10_network-exe', 'C:\\temp\\cuda_9.0.176_win10_network-exe.exe')
await exec.exec(`C:\\temp\\cuda_9.0.176_win10_network-exe.exe -s compiler_9.0 nvml_dev_9.0`)
await io.rmRF(`C:\\temp\\cuda_9.0.176_win10_network-exe.exe`)
//register necessary libraries, looks like those are registered by default in newly 2017 installation
//await exec.exec(`regsvr32 "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\DIA SDK\\bin\\msdia140.dll"`)
//await exec.exec(`regsvr32 "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\DIA SDK\\bin\\amd64\\msdia140.dl"`)
//openssl
await tc.downloadTool('https://www.openssl.org/source/openssl-1.1.1g.tar.gz', 'C:\\temp\\OpenSSL-1.1.1g.tar.gz')
await tc.extractTar('C:\\temp\\OpenSSL-1.1.1g.tar.gz', 'C:\\temp')
process.chdir('C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\VC\\Auxiliary\\Build')
core.addPath('C:\\Strawberry\\perl\\bin')
childProcess.execSync(`.\\vcvarsall.bat AMD64 && cd C:\\temp\\OpenSSL-1.1.1g && perl C:\\temp\\OpenSSL-1.1.1g\\Configure VC-WIN64A --prefix=C:\\OpenSSL-1.1.1g-x86_64-VS2017 && nmake.exe install > C:\\temp\\openssl64-VS2017.log && nmake.exe -f makefile clean`)
await io.rmRF('C:\\temp\\OpenSSL-1.1.1g.tar.gz')
await io.rmRF(`C:\\temp\\OpenSSL-1.1.1g`)
if (version === '8') {
core.setFailed('JDK8 for Windows is not available for now!')
// TODO: install version 8 specific dependencies
// https://github.com/eclipse/openj9/blob/master/doc/build-instructions/Build_Instructions_V8.md#windows
}
}
//TODO: could be only call when default environment javahome doesn't work.
async function getBootJdk(version: string): Promise<void> {
const bootJDKVersion = (parseInt(version) - 1).toString()
if (parseInt(bootJDKVersion) > 8) {
let bootjdkJar
// TODO: issue open openj9,mac, 10 ga : https://api.adoptopenjdk.net/v3/binary/latest/10/ga/mac/x64/jdk/openj9/normal/adoptopenjdk doesn't work
if (`${bootJDKVersion}` === '10') {
//JDK 11 require a latest jdk11 as boot JVMhttps://github.com/eclipse-openj9/build-openj9/issues/25#issuecomment-848354452
bootjdkJar = await tc.downloadTool(`https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk11u-2021-05-07-07-34/OpenJDK11U-jdk_x64_linux_openj9_2021-05-07-07-34.tar.gz`)
if (`${targetOs}` === 'mac') {
bootjdkJar = await tc.downloadTool(`https://github.com/AdoptOpenJDK/openjdk10-binaries/releases/download/jdk-10.0.2%2B13.1/OpenJDK10U-jdk_x64_mac_hotspot_10.0.2_13.tar.gz`)
}
} else {
bootjdkJar = await tc.downloadTool(`https://api.adoptopenjdk.net/v3/binary/latest/${bootJDKVersion}/ga/${targetOs}/x64/jdk/openj9/normal/adoptopenjdk`)
}
await io.mkdirP('bootjdk')
if (`${targetOs}` === 'mac') {
await exec.exec(`sudo tar -xzf ${bootjdkJar} -C ./bootjdk --strip=3`)
} else if (`${targetOs}` === 'linux') {
if (`${bootJDKVersion}` === '10' && `${targetOs}` === 'mac' ) {
await exec.exec(`sudo tar -xzf ${bootjdkJar} -C ./bootjdk --strip=2`) // TODO : issue open as this is packaged differently
} else {
await exec.exec(`sudo tar -xzf ${bootjdkJar} -C ./bootjdk --strip=1`)
}
} else {
// windows jdk is zip file
const tempDir = path.join(tempDirectory, 'temp_' + Math.floor(Math.random() * 2000000000))
await tc.extractZip(bootjdkJar, `${tempDir}`)
const tempJDKDir = path.join(tempDir, fs.readdirSync(tempDir)[0])
await exec.exec(`mv ${tempJDKDir}/* ${workDir}/bootjdk`)
}
await io.rmRF(`${bootjdkJar}`)
}
}
async function getSource(
openj9Version: string,
usePersonalRepo: boolean
): Promise<void> {
let openjdkOpenj9Repo = `ibmruntimes/${openj9Version}`
let openjdkOpenj9Branch = 'openj9'
let omrRepo = ''
let omrBranch = ''
let openj9Repo = ''
let openj9Branch = ''
if (usePersonalRepo) {
const repo = process.env.GITHUB_REPOSITORY as string
let branch = ''
if (process.env.GITHUB_HEAD_REF === '') {
const ref = process.env.GITHUB_REF as string
branch = ref.substr(ref.lastIndexOf('/') + 1)
} else {
branch = process.env.GITHUB_HEAD_REF as string
}
if (repo.includes(`/${openj9Version}`)) {
openjdkOpenj9Repo = repo
openjdkOpenj9Branch = branch
} else if (repo.includes('/openj9-omr')) {
omrRepo = repo
omrBranch = branch
} else if (repo.includes('/openj9')) {
openj9Repo = repo
openj9Branch = branch
} else {
core.error(`${repo} is not one of openj9-openjdk-jdk8|11|12..., openj9, omr`)
}
}
await exec.exec(`git clone -b ${openjdkOpenj9Branch} https://github.com/${openjdkOpenj9Repo}.git`)
process.chdir(`${openj9Version}`)
let omrParameters = ''
let openj9Parameters = ''
if (omrRepo.length !== 0) {
omrParameters = `-omr-repo=https://github.com/${omrRepo}.git -omr-branch=${omrBranch}`
}
if (openj9Repo.length !== 0) {
openj9Parameters = `-openj9-repo=https://github.com/${openj9Repo}.git -openj9-branch=${openj9Branch}`
}
let opensslversion = ''
if (!IS_WINDOWS) {
opensslversion = '--openssl-version=1.1.1g'
}
await exec.exec(`bash ./get_source.sh ${omrParameters} ${openj9Parameters} ${opensslversion}`)
//Using default javahome for jdk8. TODO: only use specified bootjdk when necessary
/* let bootjdkConfigure = ''
if (parseInt(version) > 8) bootjdkConfigure = `--with-boot-jdk=${workDir}/bootjdk`
await exec.exec(`bash configure --with-freemarker-jar=${workDir}/freemarker.jar ${bootjdkConfigure}`) */
}
async function setConfigure(version: string, openj9Version: string): Promise<void> {
let bootjdkConfigure = ''
if (parseInt(version) > 8) bootjdkConfigure = `--with-boot-jdk=${workDir}/bootjdk`
let configureArgs
if (`${targetOs}` === 'linux') {
configureArgs = '--enable-jitserver --with-openssl=fetched --enable-cuda --with-cuda=/usr/local/cuda-9.0'
if (`${version}` === '8') {
configureArgs += ' --disable-zip-debug-info'
}
}
if (`${targetOs}` === 'mac') {
configureArgs = '--with-openssl=fetched --enable-openssl-bundling'
if (`${version}` === '8') {
core.setFailed('JDK8 for Mac needs to build on a older OS version 10.11, macos-10.15 can not work for jdk8. please double check the jdkversion and os!')
// TODO: JDK8 for Mac needs to build on a older OS version 10.11, if older version is available the following ... should be replaced with a full path.
// Also note MACOSX_DEPLOYMENT_TARGET and SDKPATH are environment variables, not configure options.
// configureArgs += ' --with-xcode-path=.../Xcode4/Xcode.app --with-openj9-cc=.../clang --with-openj9-cxx=.../clang++ --with-openj9-developer-dir=.../Developer MACOSX_DEPLOYMENT_TARGET=10.9.0 SDKPATH=.../MacOSX10.8.sdk'
}
}
if (IS_WINDOWS) {
configureArgs = '--with-openssl="c:/OpenSSL-1.1.1g-x86_64-VS2017" --enable-openssl-bundling --enable-cuda -with-cuda="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0"'
if (`${version}` === '8') {
//TODO
configureArgs += '--disable-zip-debug-info --with-freetype-include=.../freetype-2.5.3/include --with-freetype-lib=.../freetype-2.5.3/lib64'
}
}
await exec.exec(`bash configure --with-freemarker-jar=${workDir}/freemarker.jar ${bootjdkConfigure} ${configureArgs}`)
}
async function printJavaVersion(version: string, openj9Version: string): Promise<void> {
let platform
if (`${targetOs}` === 'linux') {
platform = 'linux'
} else if (`${targetOs}` === 'mac') {
platform = 'macosx'
} else {
platform = 'windows'
}
let platformRelease = `${platform}-x86_64-normal-server-release`
if (parseInt(version) >= 13) platformRelease = `${platform}-x86_64-server-release`
let jdkImages
if (version === '8') {
jdkImages = `build/${platformRelease}/images/j2sdk-image`
process.chdir(`${jdkImages}/jre/bin`)
} else {
jdkImages = `build/${platformRelease}/images/jdk`
process.chdir(`${jdkImages}/bin`)
}
await exec.exec(`./java -version`)
//set outputs
core.setOutput('BuildJDKDir', `${workDir}/${openj9Version}/${jdkImages}`)
}
async function getOsVersion(): Promise<string> {
let osVersion = ''
const options: ExecOptions = {}
let myOutput = ''
options.listeners = {
stdout: (data: Buffer) => {
myOutput += data.toString()
}
}
if (IS_WINDOWS) {
//TODO
} else if (`${targetOs}` === 'mac') {
//TODO
} else {
exec.exec(`lsb_release`, ['-r', '-s'], options)
if (myOutput.includes('16.04')) {
osVersion = '16.04'
} else {
osVersion = '18.04'
}
}
return osVersion
}