Skip to content

Commit

Permalink
Fix cli bug
Browse files Browse the repository at this point in the history
  • Loading branch information
gen740 committed Feb 5, 2023
1 parent 3497c44 commit 7325cd4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
25 changes: 13 additions & 12 deletions cppygen/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,42 @@ def run():
cwd = pathlib.Path(args.cwd)

sources = []
if configs["sources"] is None:
if (config_sources := configs.get("sources")) is None:
logger.error("Please Specify the sources field in config file")
exit(1)
for i in configs["sources"]:
for i in config_sources:
sources.extend([j for j in cwd.glob(i)])

headers = []
if configs["headers"] is None:
if (config_headers := configs.get("headers")) is None:
logger.error("Please Specify the headers field in config file")
exit(1)
for i in configs["headers"]:
for i in config_headers:
headers.extend([j for j in cwd.glob(i)])

if configs["output_dir"] is None:
if (config_output_dir := configs.get("output_dir")) is None:
logger.error("Please Specify the output_dir field in config file")
exit(1)
output_dir = cwd.joinpath(configs["output_dir"])
output_dir = cwd.joinpath(config_output_dir)

cppygen = Parser(
namespace=configs["search_namespace"], library_file=configs["libclang_path"]
namespace=configs.get("search_namespace"),
library_file=configs.get("libclang_path"),
)

flags = configs["flags"] or []
flags = configs.get("flags") or []

for i in configs["include_directories"] or []:
for i in configs.get("include_directories") or []:
flags.append(f"-I{str(cwd.joinpath(i).absolute())}")
print(f"-I{str(cwd.joinpath(i).absolute())}")

for i in sources:
cppygen.parse_from_file(i, lang="cpp", flags=configs["flags"])
cppygen.parse_from_file(i, lang="cpp", flags=configs.get("flags") or [])

for i in headers:
cppygen.parse_from_file(i, lang="hpp", flags=configs["flags"])
cppygen.parse_from_file(i, lang="hpp", flags=configs.get("flags") or [])

for i in configs["include_headers"] or []:
for i in configs.get("include_headers") or []:
cppygen.add_hpp_includes(i)

with open(str(output_dir) + "/cppygen_generated.hpp", "w") as f:
Expand Down
6 changes: 4 additions & 2 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ find_package(pybind11 CONFIG)
# Auto Generation
set(cppygen_generated_hpp ${CMAKE_CURRENT_BINARY_DIR}/cppygen_generated.hpp)
set(cppygen_generated_cpp ${CMAKE_CURRENT_BINARY_DIR}/cppygen_generated.cpp)
set(cppygen_config_file ${CMAKE_CURRENT_LIST_DIR}/cppygenconfig.toml)

find_program(_CPPYGEN_GENERATOR cppygen)
message(${cppygen_config_file})

add_custom_command(
OUTPUT ${cppygen_generated_hpp} ${cppygen_generated_cpp}
COMMAND
${_CPPYGEN_GENERATOR} ARGS #
--config_file ${CMAKE_CURRENT_LIST_DIR}/cppygenconfig.toml #
--config_file ${cppygen_config_file}#
--cwd ${CMAKE_CURRENT_LIST_DIR}
DEPENDS ${SHELL_SOURCES}
DEPENDS ${SHELL_SOURCES} ${cppygen_config_file}
COMMENT
"Generating CPPyGen Code To ${cppygen_generated_hpp} and ${cppygen_generated_cpp}"
VERBATIM)
Expand Down

0 comments on commit 7325cd4

Please sign in to comment.