From 6f98db61f16fc944a2fe361979aeef518295aeb8 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Tue, 11 Jun 2019 15:50:04 -0700 Subject: [PATCH] generated/cfb_font_dice.h: don't leak absolute paths in comment The start of generated/cfb_font_dice.h looked like this: /* * This file was automatically generated using the following command: * /home/john/zephyrproject/zephyr/scripts/gen_cfb_font_header.py * --input fonts/dice.png --output * /home/john/tmp/build/zephyr/include/generated//cfb_font_dice.h * --width 32 --height 32 --first 49 --last 54 */ For build reproduction and "privacy" reasons, change it to this: /* * This file was automatically generated using the following command: * ${ZEPHYR_BASE}/scripts/gen_cfb_font_header.py * --input fonts/dice.png --output * zephyr/include/generated//cfb_font_dice.h * --width 32 --height 32 --first 49 --last 54 */ Test with: sanitycheck -p reel_board \ -T $ZEPHYR_BASE/samples/display/cfb_custom_font/ Signed-off-by: Marc Herbert --- cmake/cfb.cmake | 1 + scripts/gen_cfb_font_header.py | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cmake/cfb.cmake b/cmake/cfb.cmake index e0263adae26..b7995823b66 100644 --- a/cmake/cfb.cmake +++ b/cmake/cfb.cmake @@ -15,6 +15,7 @@ function(generate_cfb_font ${ZEPHYR_BASE}/scripts/gen_cfb_font_header.py --input ${input_file} --output ${output_file} + --bindir ${CMAKE_BINARY_DIR} --width ${width} --height ${height} ${ARGN} # Extra arguments are passed to gen_cfb_font_header.py diff --git a/scripts/gen_cfb_font_header.py b/scripts/gen_cfb_font_header.py index d887d4e5c42..c19e7e0f9eb 100755 --- a/scripts/gen_cfb_font_header.py +++ b/scripts/gen_cfb_font_header.py @@ -5,6 +5,7 @@ # SPDX-License-Identifier: Apache-2.0 import argparse +import os import sys from PIL import ImageFont @@ -67,6 +68,21 @@ def generate_header(): guard = "__CFB_FONT_{:s}_{:d}{:d}_H__".format(args.name.upper(), args.width, args.height) + zephyr_base = os.environ.get('ZEPHYR_BASE', "") + + clean_cmd = [ ] + for arg in sys.argv: + if arg.startswith("--bindir"): + # Drop. Assumes --bindir= was passed with '=' sign. + continue + if arg.startswith(args.bindir): + # +1 to also strip '/' or '\' separator + striplen = min(len(args.bindir)+1, len(arg)) + clean_cmd.append(arg[striplen:]) + continue + + clean_cmd.append(arg.replace(zephyr_base, '"${ZEPHYR_BASE}"')) + args.output.write("""/* * This file was automatically generated using the following command: * {cmd} @@ -80,7 +96,7 @@ def generate_header(): #include const u8_t cfb_font_{name:s}_{width:d}{height:d}[{elem:d}][{b:.0f}] = {{\n""" - .format(cmd=" ".join(sys.argv), + .format(cmd=" ".join(clean_cmd), guard=guard, name=args.name, width=args.width, @@ -141,6 +157,9 @@ def parse_args(): group.add_argument( "-o", "--output", type=argparse.FileType('w'), default="-", metavar="FILE", help="CFB font header file (default: stdout)") + group.add_argument( + "--bindir", type=str, default="", + help="CMAKE_BINARY_DIR for pure logging purposes. No trailing slash.") group.add_argument( "-x", "--width", required=True, type=int, help="width of the CFB font elements in pixels")