From 3145f8434564374d2de1f645dac90bd7f9294bdc Mon Sep 17 00:00:00 2001 From: alandefreitas Date: Wed, 10 Jul 2024 18:09:42 -0300 Subject: [PATCH] docs: collector finds versioned compilers --- .github/workflows/ci.yml | 12 +------ doc/generate-files.mjs | 73 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 68 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a73b4cf3c..05beabbcf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -374,19 +374,9 @@ jobs: compiler: clang version: 18 - - name: Set environment variables - run: | - set -x - clangpp_path="$(which clang++-18)" - clang_path="$(which clang-18)" - echo "CXX_COMPILER=$clangpp_path" >> $GITHUB_ENV - echo "CXX=$clang_path" >> $GITHUB_ENV - echo "C_COMPILER=$clang_path" >> $GITHUB_ENV - echo "CC=$clang_path" >> $GITHUB_ENV - git config --global --add safe.directory "$(pwd)" - - name: Build Antora Docs run: | + git config --global --add safe.directory "$(pwd)" cd doc bash ./build_antora.sh diff --git a/doc/generate-files.mjs b/doc/generate-files.mjs index a6665a989..d3d65887f 100644 --- a/doc/generate-files.mjs +++ b/doc/generate-files.mjs @@ -36,13 +36,74 @@ function findExecutable(executableName) { } return undefined } - try { - const whichCommand = (process.platform === 'win32') ? 'where' : 'which'; - const cmd = `${whichCommand} ${executableName}` - return execSync(cmd, {encoding: 'utf-8'}).trim() - } catch (error) { - return undefined + + const isWin = process.platform === 'win32'; + const pathDirs = process.env.PATH.split(isWin ? ';' : ':'); + const extensions = isWin ? ['.exe', '.bat', '.cmd'] : ['']; + + function isExecutable(filePath) { + try { + if (!isWin) { + fs.accessSync(filePath, fs.constants.X_OK); + } + return true; + } catch (error) { + return false; + } + } + + // Try to find the exact executable first + for (const dir of pathDirs) { + for (const ext of extensions) { + const fullPath = path.join(dir, executableName + ext); + if (fs.existsSync(fullPath) && isExecutable(fullPath)) { + return fullPath; + } + } } + + function escapeRegExp(string) { + // Escape special characters for use in regex + return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + } + + // If the exact executable is not found, search for versioned executables + const versionedExecutables = []; + const escapedExecutableName = escapeRegExp(executableName); + const versionRegex = new RegExp(`${escapedExecutableName}-(\\d+)$`); + + for (const dir of pathDirs) { + try { + const files = fs.readdirSync(dir); + for (const file of files) { + if (!extensions.some(ext => file.endsWith(ext))) { + continue + } + const fullPath = path.join(dir, file); + if (!isExecutable(fullPath)) { + continue + } + const ext = path.extname(file); + const basename = path.basename(file, ext); + const match = basename.match(versionRegex); + if (match) { + versionedExecutables.push({ + path: fullPath, + version: parseInt(match[1], 10) + }); + } + } + } catch (error) { + // Ignore errors from reading directories + } + } + + if (versionedExecutables.length > 0) { + versionedExecutables.sort((a, b) => b.version - a.version); + return versionedExecutables[0].path; + } + + return undefined; } function mkTmpDir() {