Skip to content

Commit 710e055

Browse files
authored
Add option to force using 32 bit cmake (#33)
1 parent 8a432c4 commit 710e055

File tree

11 files changed

+683
-338
lines changed

11 files changed

+683
-338
lines changed

.github/workflows/windows-32bit.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
on:
2+
push:
3+
branches: [master]
4+
pull_request:
5+
branches: [master]
6+
7+
8+
jobs:
9+
check-win32:
10+
runs-on: ${{ matrix.os }}
11+
name: Check action on 32bit windows
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
os: [windows-latest]
16+
cmake_ver: ['', '3.19.3', '3.15.1', '2.8']
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v2
21+
22+
- name: Setup cmake
23+
uses: ./
24+
id: setup
25+
with:
26+
cmake-version: ${{ matrix.cmake_ver }}
27+
use-32bit: 'true'
28+
29+
- name: Run cmake --version
30+
shell: bash
31+
run: |
32+
VERSION=`cmake --version`
33+
echo $VERSION
34+
[[ "$VERSION" =~ "${{ matrix.cmake_ver }}" ]]

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- name: Setup cmake
19-
uses: jwlawson/actions-setup-cmake@v1.8
19+
uses: jwlawson/actions-setup-cmake@v1.9
2020
with:
2121
cmake-version: '3.16.x'
2222
- name: Use cmake
@@ -25,7 +25,7 @@ jobs:
2525
2626
### Options
2727
28-
There are two options for the action:
28+
There are three options for the action:
2929
3030
* `cmake-version` controls the version of CMake that is added to the path. This
3131
can be a fully specified verison `3.3.0`, partly specified `3.2`, a wildcard
@@ -44,6 +44,12 @@ There are two options for the action:
4444
- [GitHub API rate limiting]
4545
- [GITHUB_TOKEN]
4646

47+
* `use-32bit' forces the use of a 32 bit binary, instead of first looking for a
48+
64 bit binary. Note that more recent releases of cmake only have 32 bit
49+
packages for windows and not for linux or macos, so this option may cause
50+
failures in those cases.
51+
52+
Possible values are 'true' or 'false'. The default is 'false'.
4753

4854
### How it works
4955

__tests__/setup-cmake.test.ts

Lines changed: 102 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe('When adding tool to cache', () => {
7979
.get('/cmake-win32-x86_64.zip')
8080
.replyWithFile(200, path.join(dataPath, 'empty.zip'));
8181

82-
await setup.addCMakeToToolCache(required_version);
82+
await setup.addCMakeToToolCache(required_version, ['x86_64']);
8383
expect(darwin_nock.isDone()).toBe(darwin);
8484
expect(linux_nock.isDone()).toBe(linux);
8585
expect(windows_nock.isDone()).toBe(windows);
@@ -147,7 +147,7 @@ describe('When using version 3.19.2 on macos', () => {
147147
const archive_nock = nock('https://fakeaddress.com')
148148
.get('/cmake-3.19.2-macos-universal.tar.gz')
149149
.replyWithFile(200, path.join(dataPath, 'empty.tar.gz'));
150-
await setup.addCMakeToToolCache(macos_version);
150+
await setup.addCMakeToToolCache(macos_version, ['x86_64']);
151151
expect(package_nock.isDone()).toBe(false);
152152
expect(archive_nock.isDone()).toBe(true);
153153
Object.defineProperty(process, 'platform', {
@@ -213,7 +213,7 @@ describe('When using version 2.8', () => {
213213
const darwin64_nock = nock('https://fakeaddress.com')
214214
.get('/cmake-2.8.12.2-Darwin64-universal.tar.gz')
215215
.replyWithFile(200, path.join(dataPath, 'empty.tar.gz'));
216-
await setup.addCMakeToToolCache(version);
216+
await setup.addCMakeToToolCache(version, ['x86_64', 'x86']);
217217
expect(darwin_nock.isDone()).toBe(false);
218218
expect(darwin64_nock.isDone()).toBe(true);
219219
Object.defineProperty(process, 'platform', {
@@ -231,7 +231,7 @@ describe('When using version 2.8', () => {
231231
.get('/cmake-2.8.12.2-Linux-i386.tar.gz')
232232
.replyWithFile(200, path.join(dataPath, 'empty.tar.gz'));
233233

234-
await setup.addCMakeToToolCache(version);
234+
await setup.addCMakeToToolCache(version, ['x86_64', 'x86']);
235235
expect(linux_nock.isDone()).toBe(true);
236236
Object.defineProperty(process, 'platform', {
237237
value: orig_platform,
@@ -300,7 +300,7 @@ describe('Using version 3.19.3', () => {
300300
const aarch64_nock = nock('https://fakeaddress.com')
301301
.get('/cmake-3.19.3-Linux-aarch64.tar.gz')
302302
.replyWithFile(200, path.join(dataPath, 'empty.tar.gz'));
303-
await setup.addCMakeToToolCache(version);
303+
await setup.addCMakeToToolCache(version, ['x86_64']);
304304
expect(x86_nock.isDone()).toBe(true);
305305
expect(aarch64_nock.isDone()).toBe(false);
306306
Object.defineProperty(process, 'platform', {
@@ -320,11 +320,107 @@ describe('Using version 3.19.3', () => {
320320
const second_nock = nock('https://fakeaddress.com')
321321
.get('/cmake-3.19.3-macos10.10-universal.tar.gz')
322322
.replyWithFile(200, path.join(dataPath, 'empty.tar.gz'));
323-
await setup.addCMakeToToolCache(version);
323+
await setup.addCMakeToToolCache(version, ['x86_64']);
324324
expect(first_nock.isDone()).toBe(true);
325325
expect(second_nock.isDone()).toBe(false);
326326
Object.defineProperty(process, 'platform', {
327327
value: orig_platform,
328328
});
329329
});
330330
});
331+
332+
describe('Using a version with both x86_64 and x86 binaries', () => {
333+
const version: vi.VersionInfo = {
334+
name: '3.20.2',
335+
assets: [
336+
{
337+
name: 'cmake-3.20.2-windows-i386.msi',
338+
platform: 'win32',
339+
arch: 'x86',
340+
filetype: 'package',
341+
url: 'https://url.test/cmake-3.20.2-windows-i386.msi',
342+
},
343+
{
344+
name: 'cmake-3.20.2-windows-i386.zip',
345+
platform: 'win32',
346+
arch: 'x86',
347+
filetype: 'archive',
348+
url: 'https://url.test/cmake-3.20.2-windows-i386.zip',
349+
},
350+
{
351+
name: 'cmake-3.20.2-windows-x86_64.msi',
352+
platform: 'win32',
353+
arch: 'x86_64',
354+
filetype: 'package',
355+
url: 'https://url.test/cmake-3.20.2-windows-x86_64.msi',
356+
},
357+
{
358+
name: 'cmake-3.20.2-windows-x86_64.zip',
359+
platform: 'win32',
360+
arch: 'x86_64',
361+
filetype: 'archive',
362+
url: 'https://url.test/cmake-3.20.2-windows-x86_64.zip',
363+
},
364+
],
365+
url: '',
366+
draft: false,
367+
prerelease: false,
368+
};
369+
370+
beforeEach(() => {
371+
nock.disableNetConnect();
372+
});
373+
374+
afterEach(() => {
375+
nock.cleanAll();
376+
nock.enableNetConnect();
377+
});
378+
379+
it('downloads the 32 bit package when requested', async () => {
380+
const orig_platform: string = process.platform;
381+
Object.defineProperty(process, 'platform', {
382+
value: 'win32',
383+
});
384+
expect(process.platform).toBe('win32');
385+
const x86_nock = nock('https://url.test')
386+
.get('/cmake-3.20.2-windows-i386.zip')
387+
.replyWithFile(200, path.join(dataPath, 'empty.zip'));
388+
await setup.addCMakeToToolCache(version, ['x86']);
389+
expect(x86_nock.isDone()).toBe(true);
390+
Object.defineProperty(process, 'platform', {
391+
value: orig_platform,
392+
});
393+
});
394+
395+
it('downloads the 64 bit package when requested', async () => {
396+
const orig_platform: string = process.platform;
397+
Object.defineProperty(process, 'platform', {
398+
value: 'win32',
399+
});
400+
expect(process.platform).toBe('win32');
401+
const x86_nock = nock('https://url.test')
402+
.get('/cmake-3.20.2-windows-x86_64.zip')
403+
.replyWithFile(200, path.join(dataPath, 'empty.zip'));
404+
await setup.addCMakeToToolCache(version, ['x86_64']);
405+
expect(x86_nock.isDone()).toBe(true);
406+
Object.defineProperty(process, 'platform', {
407+
value: orig_platform,
408+
});
409+
});
410+
411+
it('falls back to 64 bit package when both requested', async () => {
412+
const orig_platform: string = process.platform;
413+
Object.defineProperty(process, 'platform', {
414+
value: 'win32',
415+
});
416+
expect(process.platform).toBe('win32');
417+
const x86_nock = nock('https://url.test')
418+
.get('/cmake-3.20.2-windows-x86_64.zip')
419+
.replyWithFile(200, path.join(dataPath, 'empty.zip'));
420+
await setup.addCMakeToToolCache(version, ['x86_64', 'x86']);
421+
expect(x86_nock.isDone()).toBe(true);
422+
Object.defineProperty(process, 'platform', {
423+
value: orig_platform,
424+
});
425+
});
426+
});

__tests__/version.test.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,75 @@ describe('When using the 3.20 release', () => {
383383
});
384384
});
385385
});
386+
387+
describe('When using the 3.19 windows release with both 32 and 64 bit archives', () => {
388+
// The windows releases before 3.20 had different platform naming for 32 and 64 bit archives
389+
// cmake-3.19.8-win32-x86.zip and cmake-3.19.8-win64-x64.zip
390+
const releases = [
391+
{
392+
tag_name: 'v3.19.0',
393+
assets: [
394+
{
395+
name: 'cmake-3.19.0-win32-x86.zip',
396+
browser_download_url: 'https://url.test/cmake-3.19.0-win32-x86.zip',
397+
},
398+
{
399+
name: 'cmake-3.19.0-win64-x64.zip',
400+
browser_download_url: 'https://url.test/cmake-3.19.0-win64-x64.zip',
401+
},
402+
],
403+
},
404+
];
405+
406+
beforeEach(() => {
407+
nock.disableNetConnect();
408+
nock('https://api.github.com')
409+
.get('/repos/Kitware/CMake/releases')
410+
.reply(200, releases);
411+
nock('https://api.github.com')
412+
.get('/repos/Kitware/CMake/releases')
413+
.query({ page: 2 })
414+
.reply(200, []);
415+
});
416+
417+
afterEach(() => {
418+
nock.cleanAll();
419+
nock.enableNetConnect();
420+
});
421+
422+
it('correctly parses the 32 bit archive', async () => {
423+
const version_info = await version.getAllVersionInfo();
424+
const selected = version.getLatestMatching('3.x', version_info);
425+
const assets = selected.assets.filter(
426+
(a) =>
427+
a.platform === 'win32' && a.filetype === 'archive' && a.arch === 'x86'
428+
);
429+
expect(assets.length).toBe(1);
430+
expect(assets[0]).toEqual({
431+
name: 'cmake-3.19.0-win32-x86.zip',
432+
platform: 'win32',
433+
arch: 'x86',
434+
filetype: 'archive',
435+
url: 'https://url.test/cmake-3.19.0-win32-x86.zip',
436+
});
437+
});
438+
439+
it('correctly parses the 64 bit archive', async () => {
440+
const version_info = await version.getAllVersionInfo();
441+
const selected = version.getLatestMatching('3.x', version_info);
442+
const assets = selected.assets.filter(
443+
(a) =>
444+
a.platform === 'win32' &&
445+
a.filetype === 'archive' &&
446+
a.arch === 'x86_64'
447+
);
448+
expect(assets.length).toBe(1);
449+
expect(assets[0]).toEqual({
450+
name: 'cmake-3.19.0-win64-x64.zip',
451+
platform: 'win32',
452+
arch: 'x86_64',
453+
filetype: 'archive',
454+
url: 'https://url.test/cmake-3.19.0-win64-x64.zip',
455+
});
456+
});
457+
});

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ inputs:
77
github-api-token:
88
description: 'GitHub token to use when retrieving version info'
99
default: '${{ github.token }}'
10+
use-32bit:
11+
description: 'Force using 32 bit version of cmake, instead of looking for 64 bit version'
12+
default: 'false'
1013
runs:
1114
using: 'node12'
1215
main: 'dist/index.js'

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)