Skip to content

Commit

Permalink
Merge pull request #266 from ddalcino/topic/ddalcino/fix-path-composi…
Browse files Browse the repository at this point in the history
…tion

Use path library for path manipulation
  • Loading branch information
jurplel authored Nov 18, 2024
2 parents 09d1e79 + 485d851 commit ab8c8a2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ jobs:
- cached
- uncached
include:
- os: windows-latest
dir: '/'
qt:
version: "6.7.0"
requested: "6.7.0"
modules: qtwebengine qtpositioning qtwebchannel
- os: ubuntu-20.04
src-doc-examples: true
source: true
Expand Down Expand Up @@ -114,6 +120,7 @@ jobs:
if: ${{ !matrix.aqtversion && matrix.qt.version }}
uses: ./
with:
dir: ${{ matrix.dir }}
modules: ${{ matrix.qt.modules }}
version: ${{ matrix.qt.requested }}
tools: tools_ifw tools_qtcreator,qt.tools.qtcreator
Expand All @@ -124,11 +131,20 @@ jobs:
uses: ./
with:
aqtversion: ${{ matrix.aqtversion }}
dir: ${{ matrix.dir }}
modules: ${{ matrix.qt.modules }}
version: ${{ matrix.qt.requested }}
tools: tools_ifw tools_qtcreator,qt.tools.qtcreator
cache: ${{ matrix.cache == 'cached' }}

- name: Test QT_ROOT_DIR
if: ${{ matrix.qt.version }}
shell: bash
run: |
set -x
# Check that QT_ROOT_DIR contains a qmake of some kind
ls "${QT_ROOT_DIR}/bin/" | grep qmake
- name: Switch macOS Xcode version with older Qt versions
if: ${{ matrix.qt.version && (startsWith(matrix.os, 'macos-13') || startsWith(matrix.os, 'macos-14')) }}
shell: pwsh
Expand Down Expand Up @@ -174,6 +190,7 @@ jobs:
if: ${{ matrix.source }}
uses: ./
with:
dir: ${{ matrix.dir }}
version: "5.15.2"
source: true
no-qt-binaries: true
Expand All @@ -183,6 +200,7 @@ jobs:
if: ${{ matrix.documentation }}
uses: ./
with:
dir: ${{ matrix.dir }}
version: "5.15.2"
documentation: true
no-qt-binaries: true
Expand All @@ -193,6 +211,7 @@ jobs:
if: ${{ matrix.examples }}
uses: ./
with:
dir: ${{ matrix.dir }}
version: "5.15.2"
examples: true
no-qt-binaries: true
Expand All @@ -210,6 +229,7 @@ jobs:
if: ${{ matrix.qt.tools-only-build }}
uses: ./
with:
dir: ${{ matrix.dir }}
tools-only: true
tools: tools_ifw tools_qtcreator,qt.tools.qtcreator tools_cmake tools_ninja tools_conan
add-tools-to-path: ${{ matrix.qt.add-tools-to-path }}
Expand Down
37 changes: 19 additions & 18 deletions action/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { exec, getExecOutput } from "@actions/exec";
import * as glob from "glob";
import { compare, CompareOperator } from "compare-versions";

const nativePath = process.platform === "win32" ? path.win32.normalize : path.normalize;

const compareVersions = (v1: string, op: CompareOperator, v2: string): boolean => {
return compare(v1, v2, op);
};
Expand Down Expand Up @@ -40,7 +38,7 @@ const binlessToolDirectories = ["Conan", "Ninja"];

const toolsPaths = (installDir: string): string[] => {
const binlessPaths: string[] = binlessToolDirectories
.map((dir) => `${installDir}/Tools/${dir}`)
.map((dir) => path.join(installDir, "Tools", dir))
.filter((dir) => dirExists(dir));
return [
"Tools/**/bin",
Expand All @@ -50,7 +48,8 @@ const toolsPaths = (installDir: string): string[] => {
"Tools/*/*.app/**/bin",
]
.flatMap((p: string): string[] => glob.sync(`${installDir}/${p}`))
.concat(binlessPaths);
.concat(binlessPaths)
.map((p) => path.resolve(p));
};

const pythonCommand = (command: string, args: readonly string[]): string => {
Expand All @@ -77,14 +76,16 @@ const locateQtArchDir = (installDir: string): string => {
// 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];
Expand Down Expand Up @@ -204,7 +205,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");

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

// 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 = 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"));
core.addPath(path.resolve(qtPath, "bin"));
}
}
};
Expand Down

0 comments on commit ab8c8a2

Please sign in to comment.