-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.js
120 lines (99 loc) · 3.89 KB
/
main.js
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
const core = require('@actions/core');
const exec = require('@actions/exec');
const io = require('@actions/io');
const tc = require('@actions/tool-cache');
const path = require('path');
async function run() {
try {
const isWindows = process.platform == 'win32';
const isLinux = process.platform == 'linux';
let backend = core.getInput('backend');
if (backend === '') { backend = 'mcode' };
core.startGroup('Check OS');
let osVersion = '';
let MINGW_PACKAGE_PREFIX = '';
if ( isLinux ) {
const options = {
listeners: {
stdout: (data) => { osVersion += data.toString().replace(/^\s+|\s+$/g, ''); }
}
};
if ( await exec.exec('sed', ['-n', 's/^VERSION_ID="\\(.*\\)".*/\\1/p', '/etc/os-release'], options) ) {
throw new Error(`Could not read os version ID from '/etc/os-release!`);
};
if ( osVersion !== '20.04' && osVersion !== '22.04' ) {
throw new Error(`Ubuntu version ${ osVersion.replace(/^\s+|\s+$/g, '') } is not supported!`);
}
}
if ( isWindows ) {
await exec.exec('msys2', ['-c', ['echo', '$MINGW_PACKAGE_PREFIX'].join(' ')], {
listeners: { stdout: (data) => { MINGW_PACKAGE_PREFIX = data.toString().trim(); } }
});
}
core.endGroup();
core.startGroup('Setup GHDL');
const url = 'https://github.com/ghdl/ghdl/releases/download/nightly/' + (isWindows ?
`${ MINGW_PACKAGE_PREFIX }-ghdl-${ backend }-ci-1-any.pkg.tar.zst`
:
`ghdl-gha-ubuntu-${ osVersion }-${ backend }.tgz`
);
console.log('Package URL:', url);
const pkg = await tc.downloadTool(url);
console.log('Package:', pkg);
let ghdlPrefix = '';
if (isWindows) {
async function pacman(args, opts) {
await exec.exec('msys2', ['-c', ['pacman', '--noconfirm'].concat(args).join(' ')], opts);
}
await pacman(['-U', pkg.replace(/\\/g, '/')]);
await pacman(['-S', '--needed', 'gcc']);
let MSYS2_PATH = '';
await exec.exec('msys2', ['-c', ['cygpath', '-w', '/'].join(' ')], {
listeners: { stdout: (data) => { MSYS2_PATH = data.toString().trim(); } }
});
core.exportVariable('MSYS2_PATH', MSYS2_PATH);
ghdlPrefix = MSYS2_PATH + process.env['MSYSTEM'];
} else {
const tmp_dir = process.env['RUNNER_TEMP'];
if (!tmp_dir) {
core.setFailed('Undefined environment variable RUNNER_TEMP');
return;
}
ghdlPrefix = path.join(tmp_dir, 'ghdl');
await io.mkdirP(ghdlPrefix);
console.log('Destination:', pkg);
core.addPath(path.join(ghdlPrefix, 'bin'));
await exec.exec('tar', ['-xvf', pkg], {cwd: ghdlPrefix});
// For 18.04
let gnatVersion = '9';
let llvmVersion = '10';
if ( osVersion == '22.04' ) {
gnatVersion = '10';
llvmVersion = '11';
}
// FIXME: without libgnat-* the following error is produced:
// ghdl: error while loading shared libraries: libgnarl-*.so.1: cannot open shared object file: No such file or directory
// See https://github.com/ghdl/docker/issues/9
let pkgs = ['libgnat-' + gnatVersion]
if (backend == 'llvm') {
pkgs = pkgs.concat(['libllvm' + llvmVersion])
}
await exec.exec('sudo', ['apt', 'update', '-qq']);
await exec.exec('sudo', ['apt', 'install', '-y'].concat(pkgs));
}
core.endGroup();
core.startGroup('Set environment variables');
let _ghdl = path.join(ghdlPrefix, 'bin', 'ghdl' + ((isWindows) ? '.exe' : ''));
core.exportVariable('GHDL', _ghdl);
const ghdlLibs = path.join(ghdlPrefix, 'lib', 'ghdl');
// GHDL expects GHDL_PREFIX this variable to point to the libs prefix, not to the system prefix where GHDL is installed
core.exportVariable('GHDL_PREFIX', ghdlLibs );
core.endGroup();
// Print GHDL version
await exec.exec(_ghdl, ['version']);
}
catch (error) {
core.setFailed(error.message);
}
}
run()