Skip to content

Commit ab8c8a2

Browse files
authored
Merge pull request #266 from ddalcino/topic/ddalcino/fix-path-composition
Use path library for path manipulation
2 parents 09d1e79 + 485d851 commit ab8c8a2

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

.github/workflows/test.yml

+20
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ jobs:
6060
- cached
6161
- uncached
6262
include:
63+
- os: windows-latest
64+
dir: '/'
65+
qt:
66+
version: "6.7.0"
67+
requested: "6.7.0"
68+
modules: qtwebengine qtpositioning qtwebchannel
6369
- os: ubuntu-20.04
6470
src-doc-examples: true
6571
source: true
@@ -114,6 +120,7 @@ jobs:
114120
if: ${{ !matrix.aqtversion && matrix.qt.version }}
115121
uses: ./
116122
with:
123+
dir: ${{ matrix.dir }}
117124
modules: ${{ matrix.qt.modules }}
118125
version: ${{ matrix.qt.requested }}
119126
tools: tools_ifw tools_qtcreator,qt.tools.qtcreator
@@ -124,11 +131,20 @@ jobs:
124131
uses: ./
125132
with:
126133
aqtversion: ${{ matrix.aqtversion }}
134+
dir: ${{ matrix.dir }}
127135
modules: ${{ matrix.qt.modules }}
128136
version: ${{ matrix.qt.requested }}
129137
tools: tools_ifw tools_qtcreator,qt.tools.qtcreator
130138
cache: ${{ matrix.cache == 'cached' }}
131139

140+
- name: Test QT_ROOT_DIR
141+
if: ${{ matrix.qt.version }}
142+
shell: bash
143+
run: |
144+
set -x
145+
# Check that QT_ROOT_DIR contains a qmake of some kind
146+
ls "${QT_ROOT_DIR}/bin/" | grep qmake
147+
132148
- name: Switch macOS Xcode version with older Qt versions
133149
if: ${{ matrix.qt.version && (startsWith(matrix.os, 'macos-13') || startsWith(matrix.os, 'macos-14')) }}
134150
shell: pwsh
@@ -174,6 +190,7 @@ jobs:
174190
if: ${{ matrix.source }}
175191
uses: ./
176192
with:
193+
dir: ${{ matrix.dir }}
177194
version: "5.15.2"
178195
source: true
179196
no-qt-binaries: true
@@ -183,6 +200,7 @@ jobs:
183200
if: ${{ matrix.documentation }}
184201
uses: ./
185202
with:
203+
dir: ${{ matrix.dir }}
186204
version: "5.15.2"
187205
documentation: true
188206
no-qt-binaries: true
@@ -193,6 +211,7 @@ jobs:
193211
if: ${{ matrix.examples }}
194212
uses: ./
195213
with:
214+
dir: ${{ matrix.dir }}
196215
version: "5.15.2"
197216
examples: true
198217
no-qt-binaries: true
@@ -210,6 +229,7 @@ jobs:
210229
if: ${{ matrix.qt.tools-only-build }}
211230
uses: ./
212231
with:
232+
dir: ${{ matrix.dir }}
213233
tools-only: true
214234
tools: tools_ifw tools_qtcreator,qt.tools.qtcreator tools_cmake tools_ninja tools_conan
215235
add-tools-to-path: ${{ matrix.qt.add-tools-to-path }}

action/src/main.ts

+19-18
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import { exec, getExecOutput } from "@actions/exec";
1111
import * as glob from "glob";
1212
import { compare, CompareOperator } from "compare-versions";
1313

14-
const nativePath = process.platform === "win32" ? path.win32.normalize : path.normalize;
15-
1614
const compareVersions = (v1: string, op: CompareOperator, v2: string): boolean => {
1715
return compare(v1, v2, op);
1816
};
@@ -40,7 +38,7 @@ const binlessToolDirectories = ["Conan", "Ninja"];
4038

4139
const toolsPaths = (installDir: string): string[] => {
4240
const binlessPaths: string[] = binlessToolDirectories
43-
.map((dir) => `${installDir}/Tools/${dir}`)
41+
.map((dir) => path.join(installDir, "Tools", dir))
4442
.filter((dir) => dirExists(dir));
4543
return [
4644
"Tools/**/bin",
@@ -50,7 +48,8 @@ const toolsPaths = (installDir: string): string[] => {
5048
"Tools/*/*.app/**/bin",
5149
]
5250
.flatMap((p: string): string[] => glob.sync(`${installDir}/${p}`))
53-
.concat(binlessPaths);
51+
.concat(binlessPaths)
52+
.map((p) => path.resolve(p));
5453
};
5554

5655
const pythonCommand = (command: string, args: readonly string[]): string => {
@@ -77,14 +76,16 @@ const locateQtArchDir = (installDir: string): string => {
7776
// This makes a list of all the viable arch directories that contain a qmake file.
7877
const qtArchDirs = glob
7978
.sync(`${installDir}/[0-9]*/*/bin/qmake*`)
80-
.map((s) => s.replace(/\/bin\/qmake[^/]*$/, ""));
79+
.map((s) => path.resolve(s, "..", ".."));
8180

8281
// For Qt6 mobile and wasm installations, and Qt6 Windows on ARM installations,
8382
// a standard desktop Qt installation must exist alongside the requested architecture.
8483
// In these cases, we must select the first item that ends with 'android*', 'ios', 'wasm*' or 'msvc*_arm64'.
85-
const requiresParallelDesktop = qtArchDirs.filter((p) =>
86-
p.match(/6\.\d+\.\d+\/(android[^/]*|ios|wasm[^/]*|msvc[^/]*_arm64)$/)
87-
);
84+
const requiresParallelDesktop = qtArchDirs.filter((archPath) => {
85+
const archDir = path.basename(archPath);
86+
const versionDir = path.basename(path.join(archPath, ".."));
87+
return versionDir.match(/^6\.\d+\.\d+$/) && archDir.match(/^(android*|ios|wasm*|msvc*_arm64)$/);
88+
});
8889
if (requiresParallelDesktop.length) {
8990
// NOTE: if multiple mobile/wasm installations coexist, this may not select the desired directory
9091
return requiresParallelDesktop[0];
@@ -204,7 +205,7 @@ class Inputs {
204205
if (!dir) {
205206
throw TypeError(`"dir" input may not be empty`);
206207
}
207-
this.dir = `${dir}/Qt`;
208+
this.dir = path.resolve(dir, "Qt");
208209

209210
this.modules = Inputs.getStringArrayInput("modules");
210211

@@ -445,35 +446,35 @@ const run = async (): Promise<void> => {
445446

446447
// Add tools to path
447448
if (inputs.addToolsToPath && inputs.tools.length) {
448-
toolsPaths(inputs.dir).map(nativePath).forEach(core.addPath);
449+
toolsPaths(inputs.dir).forEach(core.addPath);
449450
}
450451

451452
// Set environment variables/outputs for tools
452453
if (inputs.tools.length && inputs.setEnv) {
453-
core.exportVariable("IQTA_TOOLS", nativePath(`${inputs.dir}/Tools`));
454+
core.exportVariable("IQTA_TOOLS", path.resolve(inputs.dir, "Tools"));
454455
}
455456
// Set environment variables/outputs for binaries
456457
if (inputs.isInstallQtBinaries) {
457-
const qtPath = nativePath(locateQtArchDir(inputs.dir));
458+
const qtPath = locateQtArchDir(inputs.dir);
458459
// Set outputs
459460
core.setOutput("qtPath", qtPath);
460461

461462
// Set env variables
462463
if (inputs.setEnv) {
463464
if (process.platform === "linux") {
464-
setOrAppendEnvVar("LD_LIBRARY_PATH", nativePath(`${qtPath}/lib`));
465+
setOrAppendEnvVar("LD_LIBRARY_PATH", path.resolve(qtPath, "lib"));
465466
}
466467
if (process.platform !== "win32") {
467-
setOrAppendEnvVar("PKG_CONFIG_PATH", nativePath(`${qtPath}/lib/pkgconfig`));
468+
setOrAppendEnvVar("PKG_CONFIG_PATH", path.resolve(qtPath, "lib", "pkgconfig"));
468469
}
469470
// If less than qt6, set Qt5_DIR variable
470471
if (compareVersions(inputs.version, "<", "6.0.0")) {
471-
core.exportVariable("Qt5_DIR", nativePath(`${qtPath}/lib/cmake`));
472+
core.exportVariable("Qt5_DIR", path.resolve(qtPath, "lib", "cmake"));
472473
}
473474
core.exportVariable("QT_ROOT_DIR", qtPath);
474-
core.exportVariable("QT_PLUGIN_PATH", nativePath(`${qtPath}/plugins`));
475-
core.exportVariable("QML2_IMPORT_PATH", nativePath(`${qtPath}/qml`));
476-
core.addPath(nativePath(`${qtPath}/bin`));
475+
core.exportVariable("QT_PLUGIN_PATH", path.resolve(qtPath, "plugins"));
476+
core.exportVariable("QML2_IMPORT_PATH", path.resolve(qtPath, "qml"));
477+
core.addPath(path.resolve(qtPath, "bin"));
477478
}
478479
}
479480
};

0 commit comments

Comments
 (0)