Skip to content

Commit

Permalink
Update c-cpp.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
fraxy-v authored Sep 1, 2024
1 parent c75b218 commit 60a3b47
Showing 1 changed file with 3 additions and 45 deletions.
48 changes: 3 additions & 45 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,59 +31,17 @@ jobs:
with:
script: |
const diff = require('./scripts/diff.js');
console.log(diff())
return diff();
- name: Get affected targets
id: find-targets
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const fs = require('fs');
const { execSync } = require('child_process');
let sources = execSync(`git diff --name-only origin/master`).toString().split('\n')
let outputs = [];
let commands = JSON.parse(fs.readFileSync('build/compile_commands.json', 'utf8'));
for (let src of sources) {
if (src.endsWith('.cpp') || src.endsWith('.h') || src.endsWith('.c')
|| src.endsWith('.hpp')) {
const idx = commands.findIndex(entry => entry.file.endsWith(src));
if (idx >= 0) {
let entry = commands[idx];
if (entry.output !== 'undefined') {
entry.output = entry.command.split(' ').find(token => token.endsWith('.o'));
}
outputs.push(entry.output);
commands.splice(idx, 1);
}
}
}
targets = new Set();
while (outputs.length > 0) {
level_targets = new Set();
for (const output of outputs) {
let lines = execSync(`ninja -C build -t query ${output}`).toString().split('\n');
const targets = require('./scripts/targets.js');
return targets('${{steps.get-modified-source.outputs.result}} ');
let insert = false;
for (const line of lines) {
if (line.endsWith('outputs:')) {
insert = true;
continue;
}
const value = line.trim();
if (insert && value.length > 0) {
level_targets.add(value);
}
}
}
outputs = [...level_targets];
targets = new Set([...targets, ...level_targets]);
}
return [...targets].join(' ');
- name: Build affected targets
if: ${{steps.find-targets.outputs.result != ''}}
run: ninja -C build ${{steps.find-targets.outputs.result}}
Expand Down

0 comments on commit 60a3b47

Please sign in to comment.