From f9be1585a51b579bc83f3c6f3ce827f1ae142e4e Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Fri, 10 Feb 2023 11:07:48 -0600 Subject: [PATCH] Fixup embed script Signed-off-by: Michael Carroll --- sdf/embedSdf.py | 26 +++++++++++++++++++------- src/SDF_TEST.cc | 1 - 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/sdf/embedSdf.py b/sdf/embedSdf.py index b89607fa6..0837e234d 100644 --- a/sdf/embedSdf.py +++ b/sdf/embedSdf.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import inspect +import sys from pathlib import Path, PurePosixPath """"Script for generating a C++ file that contains the content from all SDF files""" @@ -130,15 +131,26 @@ def get_file_header_epilog() -> str: if __name__ == "__main__": copyright = get_copyright_notice() prolog = get_file_header_prolog() - map_str = "" - for sdf_version in SUPPORTED_SDF_VERSIONS: - pathlist = Path(sdf_version).glob('*.sdf') - map_str += get_map_content(pathlist) - for sdf_conversion in SUPPORTED_SDF_CONVERSIONS: - pathlist = Path(sdf_conversion).glob('*.convert') - map_str += get_map_content(pathlist) + if len(sys.argv) > 1: + # Sources are passed in as arguments (Bazel) + for filename in sorted(sys.argv[1:]): + _, relative_path = filename.split('/sdf/') + + with open(filename, 'r', encoding='utf-8') as data: + content = data.read() + map_str += embed_sdf_content(relative_path, content) + + else: + # Assume we are in current working directory + for sdf_version in SUPPORTED_SDF_VERSIONS: + pathlist = Path(sdf_version).glob('*.sdf') + map_str += get_map_content(pathlist) + + for sdf_conversion in SUPPORTED_SDF_CONVERSIONS: + pathlist = Path(sdf_conversion).glob('*.convert') + map_str += get_map_content(pathlist) # remove the last comma map_str = map_str[:-2] diff --git a/src/SDF_TEST.cc b/src/SDF_TEST.cc index 315343e12..9a9cf446c 100644 --- a/src/SDF_TEST.cc +++ b/src/SDF_TEST.cc @@ -21,7 +21,6 @@ #include #include -#include "test_config.hh" #include "test_utils.hh" #include "sdf/sdf.hh"