This repository has been archived by the owner on Jan 16, 2024. It is now read-only.
forked from nodegui/qode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
executable file
·106 lines (95 loc) · 2.88 KB
/
build.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
#!/usr/bin/env node
const path = require("path");
//==================================
// HELPER UTILITIES
//==================================
// Wrapper of execSync that prints output.
const execSync = (command, options = {}) => {
if (options.stdio === undefined) options.stdio = "inherit";
if (options.env) options.env = Object.assign(options.env, options.env);
else options.env = Object.assign({}, process.env);
return require("child_process").execSync(command, options);
};
const checkEnvExists = (envVarName, defaultValue) => {
const value = process.env[envVarName];
if (!value) {
console.warn(
`Env variable: ${envVarName} not specified, using default: ${defaultValue}`
);
process.env[envVarName] = defaultValue;
return defaultValue;
}
console.log(`Env variable: ${envVarName}, value: ${value}`);
return value;
};
const runPreBuild = qtPath => {
let command = "";
switch (process.platform) {
case "win32":
command = `"${__dirname}\\deploy\\win32\\prebuild.bat"`;
break;
case "linux":
command = `${__dirname}/deploy/linux/prebuild.sh`;
break;
case "darwin":
command = `${__dirname}/deploy/darwin/prebuild.sh`;
break;
}
const env = Object.assign({}, process.env, { QT_INSTALL_DIR: qtPath });
execSync(command, { env });
};
const runPostBuild = qtPath => {
let command = "";
switch (process.platform) {
case "win32":
command = `${__dirname}\\deploy\\win32\\postbuild.bat`;
break;
case "linux":
command = `${__dirname}/deploy/linux/postbuild.sh`;
break;
case "darwin":
command = `${__dirname}/deploy/darwin/postbuild.sh`;
break;
}
const env = Object.assign({}, process.env, { QT_INSTALL_DIR: qtPath });
execSync(command, { env });
};
//==================================
// BUILD PROCESS
//==================================
// Specify target_arch.
const target_arch = checkEnvExists("TARGET_ARCH", "x64");
const host_arch = checkEnvExists("HOST_ARCH", "x64");
const qt_install_dir = checkEnvExists(
"QT_INSTALL_DIR",
"/usr/local/Cellar/qt/5.12.3"
);
runPreBuild(qt_install_dir);
if (process.env.SYNC_GIT_SUBMODULE) {
// Sync submodule.
execSync("git submodule sync --recursive", { stdio: null });
execSync("git submodule update --init --recursive", { stdio: null });
}
// Generate some dynamic gyp files.
execSync(
`python configure --dest-cpu=${target_arch}`,
{
cwd: "node"
}
);
// Update the build configuration.
execSync(
`python tools/gyp/gyp_main.py ../qode.gyp -f ninja -Dhost_arch=${host_arch} -Dtarget_arch=${target_arch} -Dqt_home_dir=${qt_install_dir} -I../config/node_overrides.gypi --depth .`,
{
cwd: "node"
}
);
// Build.
const epath = `${path.join("..", "bin", "ninja")}${path.delimiter}${
process.env.PATH
}`;
execSync(`ninja -j8 -C out/Release qode`, {
cwd: "node",
env: { PATH: epath }
});
runPostBuild(qt_install_dir);