Skip to content

Commit 5e6aabb

Browse files
authored
Merge pull request #189 from ddalcino/use-auto-desktop
[v4] Install desktop Qt when required to by Qt 6.2+ mobile and WASM
2 parents 6f7dd7e + 6cf14df commit 5e6aabb

File tree

6 files changed

+132
-21
lines changed

6 files changed

+132
-21
lines changed

.github/workflows/test-android.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: CI-android
2+
3+
on: [push, pull_request, workflow_dispatch]
4+
5+
jobs:
6+
test:
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
os:
12+
- ubuntu-22.04
13+
- windows-2022
14+
- macos-12
15+
qt:
16+
- version: "5.15.2"
17+
ndk-version: r21e
18+
modules:
19+
example-archives: qtbase qtsensors
20+
example-modules:
21+
- version: "6.3.2"
22+
ndk-version: r21e
23+
modules: qtsensors
24+
example-archives: qtbase
25+
example-modules: qtsensors
26+
27+
steps:
28+
- uses: actions/checkout@v3
29+
30+
- uses: actions/setup-node@v3
31+
with:
32+
node-version: 16
33+
cache: npm
34+
cache-dependency-path: action/
35+
36+
- run: |
37+
cd action
38+
npm ci || npm install
39+
shell: bash
40+
41+
- run: |
42+
cd action
43+
npm run build
44+
45+
- name: Install Qt
46+
uses: ./
47+
with:
48+
target: android
49+
modules: ${{ matrix.qt.modules }}
50+
version: ${{ matrix.qt.version }}
51+
examples: true
52+
example-archives: ${{ matrix.qt.example-archives }}
53+
example-modules: ${{ matrix.qt.example-modules }}
54+
55+
- name: Install Android NDK
56+
shell: bash
57+
# Links to NDK are at https://github.com/android/ndk/wiki/Unsupported-Downloads
58+
run: |
59+
if [[ "${RUNNER_OS}" == "Linux" ]]; then
60+
export TARGET_ARCH="linux"
61+
elif [[ "${RUNNER_OS}" == "Windows" ]]; then
62+
export TARGET_ARCH="windows"
63+
else
64+
export TARGET_ARCH="darwin"
65+
fi
66+
export NDK_VER_NUM=$(echo ${{ matrix.qt.ndk-version }} | sed -e 's/r(\d+).*/$1/g')
67+
# If it's less than 23, append -x86_64
68+
if (( "${NDK_VER_NUM}" < 23 )); then
69+
export TARGET_ARCH="${TARGET_ARCH}-x86_64"
70+
fi;
71+
curl -O "https://dl.google.com/android/repository/android-ndk-${{ matrix.qt.ndk-version }}-${TARGET_ARCH}.zip"
72+
unzip "android-ndk-${{ matrix.qt.ndk-version }}-${TARGET_ARCH}.zip"
73+
74+
- name: Build test project
75+
env:
76+
QT_VERSION: ${{ matrix.qt.version }}
77+
run: |
78+
export ANDROID_NDK_ROOT=$(pwd)/android-ndk-${{ matrix.qt.ndk-version }}
79+
cd ../Qt/Examples/Qt-${{ matrix.qt.version }}/sensors/accelbubble
80+
qmake || qmake.bat
81+
make
82+
shell: bash

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,12 @@ Default: `false`
221221

222222
Version of [aqtinstall](https://github.com/miurahr/aqtinstall) to use, given in the format used by pip, for example: `==0.7.1`, `>=0.7.1`, `==0.7.*`. This is intended to be used to troubleshoot any bugs that might be caused or fixed by certain versions of aqtinstall.
223223

224-
Default: `==2.1.*`
224+
Default: `==3.1.*`
225225

226226
### `py7zrversion`
227227
Version of py7zr in the same style as the aqtversion and intended to be used for the same purpose.
228228

229-
Default: `==0.19.*`
229+
Default: `==0.20.*`
230230

231231
### `extra`
232232
This input can be used to append arguments to the end of the aqtinstall command for any special purpose.
@@ -253,8 +253,8 @@ Example value: `--external 7z`
253253
tools: 'tools_ifw tools_qtcreator,qt.tools.qtcreator'
254254
set-env: 'true'
255255
tools-only: 'false'
256-
aqtversion: '==2.1.*'
257-
py7zrversion: '==0.19.*'
256+
aqtversion: '==3.1.*'
257+
py7zrversion: '==0.20.*'
258258
extra: '--external 7z'
259259
```
260260

README_upgrade_guide.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Upgrading `install-qt-action`
22

33
## Unreleased
4+
* Updated `aqtinstall` to version 3.1.* by default.
5+
* Use the `--autodesktop` flag to automatically install the desktop version of Qt, parallel to any WASM or mobile
6+
versions of Qt 6.2 and above.
7+
* If your action installed Qt 6.2+ for Android or WASM using `install-qt-action@v3`, then your action would have
8+
needed to install the desktop version of Qt alongside the WASM/mobile version of Qt, otherwise it would not have
9+
worked properly. As long as you are using `aqtinstall v3` or higher, the new version of `install-qt-action` will do
10+
that automatically, so you can remove the second step where you add the parallel desktop version of Qt.
11+
If you don't, your workflow will install desktop Qt twice.
412
* Added the `QT_ROOT_DIR` environment variable that points to the root of the Qt installation.
513
This variable points to the same directory as the old `Qt5_DIR` and `Qt6_DIR` variables.
614
* Changed `Qt5_DIR` environment variable, so that it points to `${QT_ROOT_DIR}/lib/cmake`, as required by CMake.

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ inputs:
5050
default: false
5151
aqtversion:
5252
description: Version of aqtinstall to use in case of issues
53-
default: ==2.1.*
53+
default: ==3.1.*
5454
py7zrversion:
5555
description: Version of py7zr to use in case of issues
56-
default: ==0.19.*
56+
default: ==0.20.*
5757
extra:
5858
description: Any extra arguments to append to the back
5959
source:

action/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ inputs:
4747
default: false
4848
aqtversion:
4949
description: Version of aqtinstall to use in case of issues
50-
default: ==2.1.*
50+
default: ==3.1.*
5151
py7zrversion:
5252
description: Version of py7zr to use in case of issues
53-
default: ==0.19.*
53+
default: ==0.20.*
5454
extra:
5555
description: Any extra arguments to append to the back
5656
source:

action/src/main.ts

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as process from "process";
55

66
import * as cache from "@actions/cache";
77
import * as core from "@actions/core";
8-
import { exec } from "@actions/exec";
8+
import { exec, getExecOutput } from "@actions/exec";
99

1010
import * as glob from "glob";
1111
import { compare, CompareOperator } from "compare-versions";
@@ -25,9 +25,19 @@ const setOrAppendEnvVar = (name: string, value: string): void => {
2525
core.exportVariable(name, newValue);
2626
};
2727

28-
const execPython = async (command: string, args: readonly string[]): Promise<number> => {
28+
const pythonCommand = (command: string, args: readonly string[]): string => {
2929
const python = process.platform === "win32" ? "python" : "python3";
30-
return exec(`${python} -m ${command} ${args.join(" ")}`);
30+
return `${python} -m ${command} ${args.join(" ")}`;
31+
};
32+
const execPython = async (command: string, args: readonly string[]): Promise<number> => {
33+
return exec(pythonCommand(command, args));
34+
};
35+
36+
const getPythonOutput = async (command: string, args: readonly string[]): Promise<string> => {
37+
// Aqtinstall prints to both stderr and stdout, depending on the command.
38+
// This function assumes we don't care which is which, and we want to see it all.
39+
const out = await getExecOutput(pythonCommand(command, args));
40+
return out.stdout + out.stderr;
3141
};
3242

3343
const flaggedList = (flag: string, listArgs: readonly string[]): string[] => {
@@ -58,6 +68,12 @@ const locateQtArchDir = (installDir: string): string => {
5868
}
5969
};
6070

71+
const isAutodesktopSupported = async (): Promise<boolean> => {
72+
const rawOutput = await getPythonOutput("aqt", ["version"]);
73+
const match = rawOutput.match(/aqtinstall\(aqt\)\s+v(\d+\.\d+\.\d+)/);
74+
return match ? compareVersions(match[1], ">=", "3.0.0") : false;
75+
};
76+
6177
class Inputs {
6278
readonly host: "windows" | "mac" | "linux";
6379
readonly target: "desktop" | "android" | "ios";
@@ -130,7 +146,16 @@ class Inputs {
130146
this.arch = core.getInput("arch");
131147
// Set arch automatically if omitted
132148
if (!this.arch) {
133-
if (this.host === "windows") {
149+
if (this.target === "android") {
150+
if (
151+
compareVersions(this.version, ">=", "5.14.0") &&
152+
compareVersions(this.version, "<", "6.0.0")
153+
) {
154+
this.arch = "android";
155+
} else {
156+
this.arch = "android_armv7";
157+
}
158+
} else if (this.host === "windows") {
134159
if (compareVersions(this.version, ">=", "5.15.0")) {
135160
this.arch = "win64_msvc2019_64";
136161
} else if (compareVersions(this.version, "<", "5.6.0")) {
@@ -140,15 +165,6 @@ class Inputs {
140165
} else {
141166
this.arch = "win64_msvc2017_64";
142167
}
143-
} else if (this.target === "android") {
144-
if (
145-
compareVersions(this.version, ">=", "5.14.0") &&
146-
compareVersions(this.version, "<", "6.0.0")
147-
) {
148-
this.arch = "android";
149-
} else {
150-
this.arch = "android_armv7";
151-
}
152168
}
153169
}
154170

@@ -321,13 +337,18 @@ const run = async (): Promise<void> => {
321337
// Install aqtinstall separately: allows aqtinstall to override py7zr if required
322338
await execPython("pip install", [`"aqtinstall${inputs.aqtVersion}"`]);
323339

340+
// This flag will install a parallel desktop version of Qt, only where required.
341+
// aqtinstall will automatically determine if this is necessary.
342+
const autodesktop = (await isAutodesktopSupported()) ? ["--autodesktop"] : [];
343+
324344
// Install Qt
325345
if (inputs.isInstallQtBinaries) {
326346
const qtArgs = [
327347
inputs.host,
328348
inputs.target,
329349
inputs.version,
330350
...(inputs.arch ? [inputs.arch] : []),
351+
...autodesktop,
331352
...["--outputdir", inputs.dir],
332353
...flaggedList("--modules", inputs.modules),
333354
...flaggedList("--archives", inputs.archives),

0 commit comments

Comments
 (0)