Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions src/setup-build-tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ async function getLatestCMakeVersion(githubToken) {
}
}

function getCMakeBinDir(cmakePath, platform) {
if (platform === 'darwin') {
const macOsBinPath = path.join(cmakePath, 'CMake.app', 'Contents', 'bin');
if (fs.existsSync(macOsBinPath)) {
return macOsBinPath;
}
}
return path.join(cmakePath, 'bin');
}

function normalizeVcpkgVersion(version) {
const parts = version.split('.');
if (parts.length === 3) {
const year = parts[0];
const month = parseInt(parts[1], 10).toString();
const day = parseInt(parts[2], 10).toString();
return `${year}.${month}.${day}`;
}
return version;
}

// --- vcpkg Specific Helpers ---

async function downloadVcpkgZip(version, hash, terrapinPath, disableTerrapin) {
Expand Down Expand Up @@ -312,7 +333,7 @@ async function run() {
} // End CMake cache miss

// Add CMake to PATH (if requested)
const cmakeBinPath = path.join(cmakeRootPath, 'bin');
const cmakeBinPath = getCMakeBinDir(cmakeRootPath, platform);
if (!fs.existsSync(cmakeBinPath)) throw new Error(`CMake 'bin' directory not found: ${cmakeBinPath}`);

if (addCMakeToPath) {
Expand Down Expand Up @@ -340,10 +361,11 @@ async function run() {
// === vcpkg Setup ===
core.startGroup('Setup vcpkg');
const vcpkgToolName = 'vcpkg';
core.info(`Setting up vcpkg version: ${vcpkgVersion}`);
const normalizedVcpkgVersion = normalizeVcpkgVersion(vcpkgVersion);
core.info(`Setting up vcpkg version: ${vcpkgVersion} (normalized to ${normalizedVcpkgVersion})`);

// vcpkg Cache Check
let finalVcpkgPath = tc.find(vcpkgToolName, vcpkgVersion); // vcpkg cache key seems simpler
let finalVcpkgPath = tc.find(vcpkgToolName, normalizedVcpkgVersion); // vcpkg cache key seems simpler

if (finalVcpkgPath) {
core.info(`Found cached vcpkg at: ${finalVcpkgPath}`);
Expand All @@ -355,7 +377,7 @@ async function run() {
const vcpkgTempExtractPath = await extractVcpkgZip(vcpkgDownloadedZipPath);
const vcpkgExtractedPath = findActualVcpkgDir(vcpkgTempExtractPath, vcpkgVersion);
await bootstrapVcpkg(vcpkgExtractedPath);
finalVcpkgPath = await cacheVcpkgDir(vcpkgExtractedPath, vcpkgToolName, vcpkgVersion);
finalVcpkgPath = await cacheVcpkgDir(vcpkgExtractedPath, vcpkgToolName, normalizedVcpkgVersion);
// Cleanup handled in finally block
} // End vcpkg cache miss

Expand All @@ -381,4 +403,5 @@ if (require.main === module) {
}

// --- Exports ---
module.exports = { run }; // Export only the main run function
// Export the main run function and utility helpers
module.exports = { run, getCMakeBinDir, normalizeVcpkgVersion };
27 changes: 27 additions & 0 deletions test/setup-build-tools/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { getCMakeBinDir } = require('../../src/setup-build-tools/index');
const fs = require('node:fs');
const path = require('node:path');

jest.mock('node:fs');

describe('getCMakeBinDir', () => {
it('should return the correct bin path for linux', () => {
const cmakePath = '/path/to/cmake';
const expectedPath = path.join(cmakePath, 'bin');
expect(getCMakeBinDir(cmakePath, 'linux')).toBe(expectedPath);
});

it('should return the correct bin path for macos when the specific path exists', () => {
const cmakePath = '/path/to/cmake';
const macOsBinPath = path.join(cmakePath, 'CMake.app', 'Contents', 'bin');
fs.existsSync.mockReturnValue(true);
expect(getCMakeBinDir(cmakePath, 'darwin')).toBe(macOsBinPath);
});

it('should return the default bin path for macos when the specific path does not exist', () => {
const cmakePath = '/path/to/cmake';
const expectedPath = path.join(cmakePath, 'bin');
fs.existsSync.mockReturnValue(false);
expect(getCMakeBinDir(cmakePath, 'darwin')).toBe(expectedPath);
});
});
19 changes: 19 additions & 0 deletions test/setup-build-tools/vcpkg-version.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { normalizeVcpkgVersion } = require('../../src/setup-build-tools/index');

describe('normalizeVcpkgVersion', () => {
it('should remove leading zeros from month and day', () => {
expect(normalizeVcpkgVersion('2025.08.27')).toBe('2025.8.27');
});

it('should not change version string if it is already normalized', () => {
expect(normalizeVcpkgVersion('2025.8.27')).toBe('2025.8.27');
});

it('should handle version strings with no leading zeros', () => {
expect(normalizeVcpkgVersion('2025.10.10')).toBe('2025.10.10');
});

it('should return the original string if it is not in the expected format', () => {
expect(normalizeVcpkgVersion('2025.08')).toBe('2025.08');
});
});
Loading