Skip to content

Commit

Permalink
docs: collector looks for versioned compiler executables
Browse files Browse the repository at this point in the history
  • Loading branch information
alandefreitas committed Jul 10, 2024
1 parent 2d35d94 commit b1c9bdb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 17 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,6 @@ 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: |
cd doc
Expand Down
64 changes: 58 additions & 6 deletions doc/generate-files.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,65 @@ 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;
}
}
}

// If the exact executable is not found, search for versioned executables
const versionedExecutables = [];
const versionRegex = new RegExp(`${executableName}-(\\d+)$`);

for (const dir of pathDirs) {
try {
const files = fs.readdirSync(dir);
for (const file of files) {
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() {
Expand Down

0 comments on commit b1c9bdb

Please sign in to comment.