Skip to content

Commit 8c85f41

Browse files
committed
[libc] Revamp hdrgen command line and build integration
This adds a new main command-line entry point for hdrgen, in the new main.py. This new interface is used for generating a header. The old ways of invoking yaml_to_classes.py for other purposes are left there for now, but `--e` is renamed to `--entry-point` for consistency with the new CLI. The YAML schema is expanded with the `header_template` key where the corresponding `.h.def` file's path is given relative to where the YAML file is found. The build integration no longer gives the `.h.def` path on the command line. Instead, the script now emits a depfile that's used by the cmake rules to track that. The output file is always explicit in the script command line rather than sometimes being derived from a directory path.
1 parent 4922350 commit 8c85f41

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+199
-135
lines changed

libc/cmake/modules/LLVMLibCHeaderRules.cmake

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function(add_gen_header target_name)
7575
cmake_parse_arguments(
7676
"ADD_GEN_HDR"
7777
"PUBLIC" # No optional arguments
78-
"YAML_FILE;DEF_FILE;GEN_HDR" # Single value arguments
78+
"YAML_FILE;GEN_HDR" # Single value arguments
7979
"DEPENDS" # Multi value arguments
8080
${ARGN}
8181
)
@@ -84,9 +84,6 @@ function(add_gen_header target_name)
8484
add_library(${fq_target_name} INTERFACE)
8585
return()
8686
endif()
87-
if(NOT ADD_GEN_HDR_DEF_FILE)
88-
message(FATAL_ERROR "`add_gen_hdr` rule requires DEF_FILE to be specified.")
89-
endif()
9087
if(NOT ADD_GEN_HDR_GEN_HDR)
9188
message(FATAL_ERROR "`add_gen_hdr` rule requires GEN_HDR to be specified.")
9289
endif()
@@ -97,8 +94,11 @@ function(add_gen_header target_name)
9794
set(absolute_path ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR_GEN_HDR})
9895
file(RELATIVE_PATH relative_path ${LIBC_INCLUDE_SOURCE_DIR} ${absolute_path})
9996
set(out_file ${LIBC_INCLUDE_DIR}/${relative_path})
97+
set(dep_file "${out_file}.d")
98+
file(RELATIVE_PATH rel_out_file ${CMAKE_BINARY_DIR} ${out_file})
99+
file(RELATIVE_PATH rel_dep_file ${CMAKE_BINARY_DIR} ${dep_file})
100100
set(yaml_file ${CMAKE_SOURCE_DIR}/${ADD_GEN_HDR_YAML_FILE})
101-
set(def_file ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR_DEF_FILE})
101+
file(RELATIVE_PATH rel_yaml_file ${CMAKE_BINARY_DIR} ${yaml_file})
102102

103103
set(fq_data_files "")
104104
if(ADD_GEN_HDR_DATA_FILES)
@@ -108,26 +108,27 @@ function(add_gen_header target_name)
108108
endif()
109109

110110
set(entry_points "${TARGET_ENTRYPOINT_NAME_LIST}")
111-
list(TRANSFORM entry_points PREPEND "--e=")
111+
list(TRANSFORM entry_points PREPEND "--entry-point=")
112112

113-
set(LIBC_HDRGEN "${LIBC_SOURCE_DIR}/utils/hdrgen/yaml_to_classes.py")
114113
add_custom_command(
115114
OUTPUT ${out_file}
116-
COMMAND ${Python3_EXECUTABLE} ${LIBC_HDRGEN}
117-
${yaml_file}
118-
--h_def_file ${def_file}
115+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
116+
COMMAND ${Python3_EXECUTABLE} "${LIBC_SOURCE_DIR}/utils/hdrgen/main.py"
117+
--output ${rel_out_file}
118+
--depfile ${rel_dep_file}
119119
${entry_points}
120-
--output_dir ${out_file}
121-
DEPENDS ${yaml_file} ${def_file} ${fq_data_files}
122-
COMMENT "Generating header ${ADD_GEN_HDR_GEN_HDR} from ${yaml_file} and ${def_file}"
120+
${rel_yaml_file}
121+
DEPENDS ${yaml_file} ${fq_data_files}
122+
DEPFILE ${dep_file}
123+
COMMENT "Generating header ${ADD_GEN_HDR_GEN_HDR} from ${yaml_file}"
123124
)
124125
if(LIBC_TARGET_OS_IS_GPU)
125126
file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/llvm-libc-decls)
126127
file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/llvm-libc-decls/gpu)
127128
set(decl_out_file ${LIBC_INCLUDE_DIR}/llvm-libc-decls/${relative_path})
128129
add_custom_command(
129130
OUTPUT ${decl_out_file}
130-
COMMAND ${Python3_EXECUTABLE} ${LIBC_HDRGEN}
131+
COMMAND ${Python3_EXECUTABLE} "${LIBC_SOURCE_DIR}/utils/hdrgen/yaml_to_classes.py"
131132
${yaml_file}
132133
--export-decls
133134
${entry_points}

0 commit comments

Comments
 (0)