Skip to content

Commit

Permalink
Build
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpurcell committed Dec 14, 2024
1 parent 13aba58 commit 7af3b08
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions action/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const core = __importStar(require("@actions/core"));
const exec_1 = require("@actions/exec");
const glob = __importStar(require("glob"));
const compare_versions_1 = require("compare-versions");
const nativePath = process.platform === "win32" ? path.win32.normalize : path.normalize;
const compareVersions = (v1, op, v2) => {
return (0, compare_versions_1.compare)(v1, v2, op);
};
Expand All @@ -67,7 +66,7 @@ const dirExists = (dir) => {
const binlessToolDirectories = ["Conan", "Ninja"];
const toolsPaths = (installDir) => {
const binlessPaths = binlessToolDirectories
.map((dir) => `${installDir}/Tools/${dir}`)
.map((dir) => path.join(installDir, "Tools", dir))
.filter((dir) => dirExists(dir));
return [
"Tools/**/bin",
Expand All @@ -77,7 +76,8 @@ const toolsPaths = (installDir) => {
"Tools/*/*.app/**/bin",
]
.flatMap((p) => glob.sync(`${installDir}/${p}`))
.concat(binlessPaths);
.concat(binlessPaths)
.map((p) => path.resolve(p));
};
const pythonCommand = (command, args) => {
const python = process.platform === "win32" ? "python" : "python3";
Expand All @@ -100,27 +100,31 @@ const locateQtArchDir = (installDir) => {
// This makes a list of all the viable arch directories that contain a qmake file.
const qtArchDirs = glob
.sync(`${installDir}/[0-9]*/*/bin/qmake*`)
.map((s) => s.replace(/\/bin\/qmake[^/]*$/, ""));
.map((s) => path.resolve(s, "..", ".."));
// For Qt6 mobile and wasm installations, and Qt6 Windows on ARM installations,
// a standard desktop Qt installation must exist alongside the requested architecture.
// In these cases, we must select the first item that ends with 'android*', 'ios', 'wasm*' or 'msvc*_arm64'.
const requiresParallelDesktop = qtArchDirs.filter((p) => p.match(/6\.\d+\.\d+\/(android[^/]*|ios|wasm[^/]*|msvc[^/]*_arm64)$/));
const requiresParallelDesktop = qtArchDirs.filter((archPath) => {
const archDir = path.basename(archPath);
const versionDir = path.basename(path.join(archPath, ".."));
return (versionDir.match(/^6\.\d+\.\d+$/) && archDir.match(/^(android.*|ios|wasm.*|msvc.*_arm64)$/));
});
if (requiresParallelDesktop.length) {
// NOTE: if multiple mobile/wasm installations coexist, this may not select the desired directory
return requiresParallelDesktop[0];
return [requiresParallelDesktop[0], true];
}
else if (!qtArchDirs.length) {
throw Error(`Failed to locate a Qt installation directory in ${installDir}`);
}
else {
// NOTE: if multiple Qt installations exist, this may not select the desired directory
return qtArchDirs[0];
return [qtArchDirs[0], false];
}
};
const isAutodesktopSupported = () => __awaiter(void 0, void 0, void 0, function* () {
const rawOutput = yield getPythonOutput("aqt", ["version"]);
const match = rawOutput.match(/aqtinstall\(aqt\)\s+v(\d+\.\d+\.\d+)/);
return match ? compareVersions(match[1], ">=", "3.0.0") : false;
return match ? compareVersions(match[1], ">=", "3.0.0") : true;
});
class Inputs {
constructor() {
Expand Down Expand Up @@ -195,7 +199,7 @@ class Inputs {
if (!dir) {
throw TypeError(`"dir" input may not be empty`);
}
this.dir = `${dir}/Qt`;
this.dir = path.resolve(dir, "Qt");
this.modules = Inputs.getStringArrayInput("modules");
this.archives = Inputs.getStringArrayInput("archives");
this.tools = Inputs.getStringArrayInput("tools").map(
Expand Down Expand Up @@ -345,9 +349,12 @@ const run = () => __awaiter(void 0, void 0, void 0, function* () {
if (inputs.aqtSource.length > 0) {
yield execPython("pip install", [`"${inputs.aqtSource}"`]);
}
else {
else if (inputs.aqtVersion.length > 0) {
yield execPython("pip install", [`"aqtinstall${inputs.aqtVersion}"`]);
}
else {
yield execPython("pip install", ["git+https://github.com/jdpurcell/aqtinstall.git@custom"]);
}
// This flag will install a parallel desktop version of Qt, only where required.
// aqtinstall will automatically determine if this is necessary.
const autodesktop = (yield isAutodesktopSupported()) ? ["--autodesktop"] : [];
Expand Down Expand Up @@ -403,33 +410,42 @@ const run = () => __awaiter(void 0, void 0, void 0, function* () {
}
// Add tools to path
if (inputs.addToolsToPath && inputs.tools.length) {
toolsPaths(inputs.dir).map(nativePath).forEach(core.addPath);
toolsPaths(inputs.dir).forEach(core.addPath);
}
// Set environment variables/outputs for tools
if (inputs.tools.length && inputs.setEnv) {
core.exportVariable("IQTA_TOOLS", nativePath(`${inputs.dir}/Tools`));
core.exportVariable("IQTA_TOOLS", path.resolve(inputs.dir, "Tools"));
}
// Set environment variables/outputs for binaries
if (inputs.isInstallQtBinaries) {
const qtPath = nativePath(locateQtArchDir(inputs.dir));
const [qtPath, requiresParallelDesktop] = locateQtArchDir(inputs.dir);
// Set outputs
core.setOutput("qtPath", qtPath);
// Set env variables
if (inputs.setEnv) {
if (process.platform === "linux") {
setOrAppendEnvVar("LD_LIBRARY_PATH", nativePath(`${qtPath}/lib`));
setOrAppendEnvVar("LD_LIBRARY_PATH", path.resolve(qtPath, "lib"));
}
if (process.platform !== "win32") {
setOrAppendEnvVar("PKG_CONFIG_PATH", nativePath(`${qtPath}/lib/pkgconfig`));
setOrAppendEnvVar("PKG_CONFIG_PATH", path.resolve(qtPath, "lib", "pkgconfig"));
}
// If less than qt6, set Qt5_DIR variable
if (compareVersions(inputs.version, "<", "6.0.0")) {
core.exportVariable("Qt5_DIR", nativePath(`${qtPath}/lib/cmake`));
core.exportVariable("Qt5_DIR", path.resolve(qtPath, "lib", "cmake"));
}
core.exportVariable("QT_ROOT_DIR", qtPath);
core.exportVariable("QT_PLUGIN_PATH", nativePath(`${qtPath}/plugins`));
core.exportVariable("QML2_IMPORT_PATH", nativePath(`${qtPath}/qml`));
core.addPath(nativePath(`${qtPath}/bin`));
core.exportVariable("QT_PLUGIN_PATH", path.resolve(qtPath, "plugins"));
core.exportVariable("QML2_IMPORT_PATH", path.resolve(qtPath, "qml"));
if (requiresParallelDesktop) {
const hostPrefix = yield fs.promises
.readFile(path.join(qtPath, "bin", "target_qt.conf"), "utf8")
.then((data) => { var _a, _b; return (_b = (_a = data.match(/^HostPrefix=(.*)$/m)) === null || _a === void 0 ? void 0 : _a[1].trim()) !== null && _b !== void 0 ? _b : ""; })
.catch(() => "");
if (hostPrefix) {
core.exportVariable("QT_HOST_PATH", path.resolve(qtPath, "bin", hostPrefix));
}
}
core.addPath(path.resolve(qtPath, "bin"));
}
}
});
Expand Down

0 comments on commit 7af3b08

Please sign in to comment.