empty column to display as '--'
instead of modify the csv file, which I am parsing in some other scripts (and loading on Google spreadsheets), lets change them only when piping to `column` which has the bug https://man7.org/linux/man-pages/man1/column.1.html#BUGS
Bug: 283139160
Test: `./incremental_build.sh -c "no change" -b soong prod -- nothing`
Change-Id: I4c7a3c3670082e6cc11adf3d123c0ad824a4cb58
diff --git a/scripts/incremental_build/incremental_build.py b/scripts/incremental_build/incremental_build.py
index 2f33599..e050be9 100644
--- a/scripts/incremental_build/incremental_build.py
+++ b/scripts/incremental_build/incremental_build.py
@@ -70,7 +70,7 @@
def _build_file_sha(target_product: str) -> str:
build_file = util.get_out_dir().joinpath(f'soong/build.{target_product}.ninja')
if not build_file.exists():
- return '--'
+ return ''
with open(build_file, mode="rb") as f:
h = hashlib.sha256()
for block in iter(lambda: f.read(4096), b''):
@@ -105,14 +105,14 @@
def recompact_ninja_log():
subprocess.run([
- util.get_top_dir().joinpath(
- 'prebuilts/build-tools/linux-x86/bin/ninja'),
- '-f',
- util.get_out_dir().joinpath(
+ util.get_top_dir().joinpath(
+ 'prebuilts/build-tools/linux-x86/bin/ninja'),
+ '-f',
+ util.get_out_dir().joinpath(
f'combined-{target_product}.ninja'),
- '-t', 'recompact'],
- check=False, cwd=util.get_top_dir(), shell=False,
- stdout=f, stderr=f)
+ '-t', 'recompact'],
+ check=False, cwd=util.get_top_dir(), shell=False,
+ stdout=f, stderr=f)
with open(logfile, mode='w') as f:
action_count_before = get_action_count()
diff --git a/scripts/incremental_build/perf_metrics.py b/scripts/incremental_build/perf_metrics.py
index 5c20dfe..099d5ee 100644
--- a/scripts/incremental_build/perf_metrics.py
+++ b/scripts/incremental_build/perf_metrics.py
@@ -227,8 +227,7 @@
headers: list[str] = _get_column_headers(rows, allow_cycles=True)
def row2line(r):
- #if a column value is missing, use '-' as a placeholder
- return ','.join([str(r.get(col, '-')) for col in headers])
+ return ','.join([str(r.get(col, '')) for col in headers])
lines = [','.join(headers)]
lines.extend(row2line(r) for r in rows)
diff --git a/scripts/incremental_build/util.py b/scripts/incremental_build/util.py
index 57cf296..038a1a7 100644
--- a/scripts/incremental_build/util.py
+++ b/scripts/incremental_build/util.py
@@ -81,7 +81,21 @@
columns.append(1)
f = ','.join(str(i + 1) for i in columns)
- return f'grep -v "WARMUP\\|rebuild-\\|FAILED "{csv_file}" | ' \
+ # the sed invocations are to account for
+ # https://man7.org/linux/man-pages/man1/column.1.html#BUGS
+ # example: if a row were `,,,hi,,,,`
+ # the successive sed conversions would be
+ # `,,,hi,,,,` =>
+ # `,--,,hi,--,,--,` =>
+ # `,--,--,hi,--,--,--,` =>
+ # `--,--,--,hi,--,--,--,` =>
+ # `--,--,--,hi,--,--,--,--`
+ # Note sed doesn't support lookahead or lookbehinds
+ return f'grep -v "WARMUP\\|rebuild-\\|FAILED" "{csv_file}" | ' \
+ f'sed "s/,,/,--,/g" | ' \
+ f'sed "s/,,/,--,/g" | ' \
+ f'sed "s/^,/--,/" | ' \
+ f'sed "s/,$/,--/" | ' \
f'cut -d, -f{f} | column -t -s,'