diff --git a/src/setup-build-tools/index.js b/src/setup-build-tools/index.js index a41e53d..7da6f48 100644 --- a/src/setup-build-tools/index.js +++ b/src/setup-build-tools/index.js @@ -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) { @@ -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) { @@ -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}`); @@ -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 @@ -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 }; diff --git a/test/setup-build-tools/index.test.js b/test/setup-build-tools/index.test.js new file mode 100644 index 0000000..8d090be --- /dev/null +++ b/test/setup-build-tools/index.test.js @@ -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); + }); +}); diff --git a/test/setup-build-tools/vcpkg-version.test.js b/test/setup-build-tools/vcpkg-version.test.js new file mode 100644 index 0000000..031680c --- /dev/null +++ b/test/setup-build-tools/vcpkg-version.test.js @@ -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'); + }); +});