Skip to content

Commit

Permalink
target script
Browse files Browse the repository at this point in the history
  • Loading branch information
fraxy-v committed Sep 1, 2024
1 parent 2836f93 commit 42ff5b5
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 31 deletions.
60 changes: 29 additions & 31 deletions scripts/diff.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
const { execSync } = require('child_process');
const { parse } = require('path');
const output = execSync(`git diff origin/master`).toString().split('\n')

let count = 0;
let start = 0;
let current = 0;
let sources = [];
for (let i = 0; i < output.length; i++) {
if (output[i].startsWith('diff --git')) {
// skip 'diff --git a/' prefix
const file = output[i].split(' ')[2].substring(2);
sources.push({'file': file, 'lines': []});
// go to header line, e.g. '@@ -1,2 +1,3 @@'
do {
++i;
module.exports = () => {
const output = execSync(`git diff origin/master`).toString().split('\n')
let count = 0;
let start = 0;
let current = 0;
let sources = [];
for (let i = 0; i < output.length; i++) {
if (output[i].startsWith('diff --git')) {
// skip 'diff --git a/' prefix
const file = output[i].split(' ')[2].substring(2);
sources.push({'file': file, 'lines': []});
// go to header line, e.g. '@@ -1,2 +1,3 @@'
do {
++i;
}
while (!output[i].startsWith('@@'));
output[i].split(' ').forEach((c) => {
if (c.startsWith('+')) {
[start, count] = c.split(',');
start = parseInt(start);
count = parseInt(count);
current = 0;
}
});
}
while (!output[i].startsWith('@@'));
output[i].split(' ').forEach((c) => {
if (c.startsWith('+')) {
[start, count] = c.split(',');
start = parseInt(start);
count = parseInt(count);
current = 0;
}
});
}
else if (current < count && !output[i].startsWith('-')) {
if (output[i].startsWith('+')) {
sources[sources.length - 1].lines.push(start + current);
else if (current < count && !output[i].startsWith('-')) {
if (output[i].startsWith('+')) {
sources[sources.length - 1].lines.push(start + current);
}
++current;
}
++current;
}
}

module.exports = () => {
return sources;
};
45 changes: 45 additions & 0 deletions scripts/targets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const fs = require('fs');
const { execSync } = require('child_process');

module.exports = (sources) => {
let outputs = [];
let commands = JSON.parse(fs.readFileSync('build/compile_commands.json', 'utf8'));
for (let {'file': 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');

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(' ');
}

0 comments on commit 42ff5b5

Please sign in to comment.