Skip to content

Commit 6ad0dcf

Browse files
authored
[libc] Revamp hdrgen command line and build integration (llvm#121522)
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 4c43648 commit 6ad0dcf

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: 12 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,8 @@ 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")
10098
set(yaml_file ${CMAKE_SOURCE_DIR}/${ADD_GEN_HDR_YAML_FILE})
101-
set(def_file ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR_DEF_FILE})
10299

103100
set(fq_data_files "")
104101
if(ADD_GEN_HDR_DATA_FILES)
@@ -108,26 +105,27 @@ function(add_gen_header target_name)
108105
endif()
109106

110107
set(entry_points "${TARGET_ENTRYPOINT_NAME_LIST}")
111-
list(TRANSFORM entry_points PREPEND "--e=")
108+
list(TRANSFORM entry_points PREPEND "--entry-point=")
112109

113-
set(LIBC_HDRGEN "${LIBC_SOURCE_DIR}/utils/hdrgen/yaml_to_classes.py")
114110
add_custom_command(
115111
OUTPUT ${out_file}
116-
COMMAND ${Python3_EXECUTABLE} ${LIBC_HDRGEN}
117-
${yaml_file}
118-
--h_def_file ${def_file}
112+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
113+
COMMAND ${Python3_EXECUTABLE} "${LIBC_SOURCE_DIR}/utils/hdrgen/main.py"
114+
--output ${out_file}
115+
--depfile ${dep_file}
119116
${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}"
117+
${yaml_file}
118+
DEPENDS ${yaml_file} ${fq_data_files}
119+
DEPFILE ${dep_file}
120+
COMMENT "Generating header ${ADD_GEN_HDR_GEN_HDR} from ${yaml_file}"
123121
)
124122
if(LIBC_TARGET_OS_IS_GPU)
125123
file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/llvm-libc-decls)
126124
file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/llvm-libc-decls/gpu)
127125
set(decl_out_file ${LIBC_INCLUDE_DIR}/llvm-libc-decls/${relative_path})
128126
add_custom_command(
129127
OUTPUT ${decl_out_file}
130-
COMMAND ${Python3_EXECUTABLE} ${LIBC_HDRGEN}
128+
COMMAND ${Python3_EXECUTABLE} "${LIBC_SOURCE_DIR}/utils/hdrgen/yaml_to_classes.py"
131129
${yaml_file}
132130
--export-decls
133131
${entry_points}

0 commit comments

Comments
 (0)