Skip to content

Backport compatible changes from v4.0.0 to v3.7.0 #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dae73e5
Implement block quote whitespace normalization
wravery Dec 10, 2021
8d1889f
Export a type erased JSON writer object
wravery Dec 13, 2021
7fbcab6
Only install new CMake files for install configs
wravery Dec 15, 2021
541c944
Update JSON documentation to describe response::Writer
wravery Dec 16, 2021
111c301
Minor correction to comment about parseSchema
wravery Dec 16, 2021
5f5934b
Default initialize input type struct members
wravery Dec 16, 2021
98afa30
Re-use the same Library.rc.in and Generator.rc.in files across targets
wravery Dec 17, 2021
deb31f1
Get latest release of PEGTL
wravery Oct 27, 2021
c627ba7
Bump minor version for v3.7.0 release
wravery Dec 17, 2021
f72e955
Fix double std::move(variables) in tests
wravery Nov 1, 2021
db39c99
Encapsulate code gen in reusable cmake functions
wravery Dec 3, 2021
20aa7b1
Put back older command line args for schemagen
wravery Dec 17, 2021
435b48e
Extract clientgen cmake functions as well
wravery Dec 3, 2021
c4dd72a
Disambiguate copy_sample_dlls target names
wravery Dec 3, 2021
a689906
Remove out-of-date WORKING_DIRECTORY
wravery Dec 3, 2021
d48d1d6
Install update-client-files script
wravery Dec 3, 2021
acdcbae
Add comments indicating not to copy include statements
wravery Dec 3, 2021
9422dc3
Fix mismatch in sentinel file names and cleanup targets
wravery Dec 6, 2021
9873870
Codegen targets should depend on the generators
wravery Dec 7, 2021
44a6261
Use R"gql(...)gql"sv for names in getTypeNames
wravery Dec 8, 2021
09ab2b5
Update files with latest schemagen
wravery Dec 17, 2021
6ae3790
Escape string literals with GraphQL tokens
wravery Dec 8, 2021
0062814
Include fewer headers and rely on forward declaration in ...Schema.h
wravery Dec 9, 2021
31eb925
Fix #156
wravery Dec 9, 2021
bbb959a
StarWarsData.cpp doesn't need the convenience header
wravery Dec 9, 2021
02403ff
Block reserved names in non-Introspection schemas
wravery Dec 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PEGTL
Submodule PEGTL updated 98 files
+9 −1 .github/workflows/android.yml
+12 −2 .github/workflows/clang-analyze.yml
+11 −3 .github/workflows/clang-format.yml
+12 −2 .github/workflows/clang-tidy.yml
+9 −1 .github/workflows/code-coverage.yml
+8 −2 .github/workflows/codeql-analysis.yml
+40 −30 .github/workflows/linux.yml
+9 −1 .github/workflows/macos.yml
+11 −3 .github/workflows/no-exceptions.yml
+10 −2 .github/workflows/sanitizer.yml
+9 −1 .github/workflows/windows.yml
+5 −0 CMakeLists.txt
+6 −2 README.md
+68 −2 doc/Actions-and-States.md
+19 −0 doc/Changelog.md
+11 −0 doc/Contrib-and-Examples.md
+1 −1 doc/Errors-and-Exceptions.md
+1 −1 doc/Grammar-Analysis.md
+2 −4 doc/Installing-and-Using.md
+7 −2 doc/Parse-Tree.md
+3 −0 doc/README.md
+10 −1 doc/Rule-Reference.md
+1 −0 include/tao/pegtl.hpp
+3 −3 include/tao/pegtl/argv_input.hpp
+1 −0 include/tao/pegtl/ascii.hpp
+5 −2 include/tao/pegtl/buffer_input.hpp
+24 −6 include/tao/pegtl/change_action_and_state.hpp
+25 −6 include/tao/pegtl/change_state.hpp
+69 −0 include/tao/pegtl/contrib/add_state.hpp
+3 −3 include/tao/pegtl/contrib/analyze.hpp
+55 −0 include/tao/pegtl/contrib/check_bytes.hpp
+0 −2 include/tao/pegtl/contrib/control_action.hpp
+4 −4 include/tao/pegtl/contrib/http.hpp
+1 −1 include/tao/pegtl/contrib/instantiate.hpp
+39 −7 include/tao/pegtl/contrib/integer.hpp
+3 −3 include/tao/pegtl/contrib/internal/set_stack_guard.hpp
+3 −3 include/tao/pegtl/contrib/internal/vector_stack_guard.hpp
+106 −0 include/tao/pegtl/contrib/iri.hpp
+88 −0 include/tao/pegtl/contrib/limit_bytes.hpp
+83 −0 include/tao/pegtl/contrib/limit_depth.hpp
+121 −0 include/tao/pegtl/contrib/peg.hpp
+142 −0 include/tao/pegtl/contrib/proto3.hpp
+45 −0 include/tao/pegtl/contrib/separated_seq.hpp
+8 −4 include/tao/pegtl/contrib/state_control.hpp
+1 −1 include/tao/pegtl/contrib/uri.hpp
+3 −3 include/tao/pegtl/internal/cstream_reader.hpp
+6 −6 include/tao/pegtl/internal/file_mapper_posix.hpp
+6 −6 include/tao/pegtl/internal/file_mapper_win32.hpp
+2 −2 include/tao/pegtl/internal/file_reader.hpp
+3 −2 include/tao/pegtl/internal/istream_reader.hpp
+6 −6 include/tao/pegtl/internal/marker.hpp
+20 −31 include/tao/pegtl/internal/ranges.hpp
+29 −13 include/tao/pegtl/internal/state.hpp
+21 −8 include/tao/pegtl/memory_input.hpp
+4 −4 include/tao/pegtl/mmap_input.hpp
+0 −2 include/tao/pegtl/must_if.hpp
+7 −6 include/tao/pegtl/normal.hpp
+20 −33 include/tao/pegtl/parse.hpp
+5 −0 include/tao/pegtl/parse_error.hpp
+3 −3 include/tao/pegtl/position.hpp
+2 −2 include/tao/pegtl/read_input.hpp
+4 −4 include/tao/pegtl/string_input.hpp
+2 −2 include/tao/pegtl/version.hpp
+37 −23 include/tao/pegtl/visit.hpp
+3 −2 src/example/pegtl/CMakeLists.txt
+15 −9 src/example/pegtl/abnf2pegtl.cpp
+520 −0 src/example/pegtl/expression.cpp
+0 −2 src/example/pegtl/indent_aware.cpp
+101 −0 src/example/pegtl/iri.cpp
+2 −2 src/example/pegtl/json_classes.hpp
+5 −3 src/example/pegtl/json_errors.hpp
+12 −2 src/example/pegtl/json_parse.cpp
+0 −25 src/example/pegtl/lua53_print_debug.cpp
+0 −25 src/example/pegtl/lua53_print_names.cpp
+37 −0 src/example/pegtl/peg.peg
+545 −0 src/example/pegtl/peg2pegtl.cpp
+1 −118 src/example/pegtl/proto3.cpp
+4 −4 src/example/pegtl/token_input.cpp
+6 −0 src/test/pegtl/CMakeLists.txt
+50 −0 src/test/pegtl/check_bytes.cpp
+24 −0 src/test/pegtl/contains.cpp
+1 −0 src/test/pegtl/contrib_analyze.cpp
+4 −4 src/test/pegtl/contrib_control_action.cpp
+1 −1 src/test/pegtl/contrib_if_then.cpp
+2 −2 src/test/pegtl/contrib_instantiate.cpp
+30 −29 src/test/pegtl/contrib_integer.cpp
+57 −0 src/test/pegtl/contrib_iri.cpp
+24 −0 src/test/pegtl/contrib_separated_seq.cpp
+19 −17 src/test/pegtl/contrib_uri.cpp
+9 −3 src/test/pegtl/error_message.cpp
+2 −2 src/test/pegtl/internal_file_mapper.cpp
+1 −1 src/test/pegtl/internal_file_opener.cpp
+50 −0 src/test/pegtl/limit_bytes.cpp
+50 −0 src/test/pegtl/limit_depth.cpp
+1 −1 src/test/pegtl/rule_apply.cpp
+1 −1 src/test/pegtl/rule_apply0.cpp
+1 −1 src/test/pegtl/rule_if_apply.cpp
+1 −1 src/test/pegtl/verify_impl.hpp
7 changes: 7 additions & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION ${GRAPHQL_INSTALL_CMAKE_DIR}/${PROJECT_NAME})

install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}-functions.cmake
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}-update-schema-files.cmake
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}-update-client-files.cmake
CONFIGURATIONS ${GRAPHQL_INSTALL_CONFIGURATIONS}
DESTINATION ${GRAPHQL_INSTALL_CMAKE_DIR}/${PROJECT_NAME})
16 changes: 8 additions & 8 deletions cmake/ClientGen.rc.in → cmake/Generator.rc.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <winver.h>

#define CLIENTGEN_RC_VERSION @CLIENTGEN_RC_VERSION@
#define CLIENTGEN_RC_VERSION_STR "@CLIENTGEN_RC_VERSION_STR@"
#define GRAPHQL_RC_VERSION @GRAPHQL_RC_VERSION@
#define GRAPHQL_RC_VERSION_STR "@GRAPHQL_RC_VERSION_STR@"

#ifndef DEBUG
#define VER_DEBUG 0
Expand All @@ -13,8 +13,8 @@
#endif

VS_VERSION_INFO VERSIONINFO
FILEVERSION CLIENTGEN_RC_VERSION
PRODUCTVERSION CLIENTGEN_RC_VERSION
FILEVERSION GRAPHQL_RC_VERSION
PRODUCTVERSION GRAPHQL_RC_VERSION
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
FILEFLAGS VER_DEBUG
FILEOS VOS__WINDOWS32
Expand All @@ -27,12 +27,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "Microsoft Corporation"
VALUE "FileDescription", "Code generator for https://github.com/microsoft/cppgraphqlgen"
VALUE "FileVersion", CLIENTGEN_RC_VERSION_STR
VALUE "InternalName", "clientgen"
VALUE "FileVersion", GRAPHQL_RC_VERSION_STR
VALUE "InternalName", "@GRAPHQL_RC_FILENAME@"
VALUE "LegalCopyright", "Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License."
VALUE "OriginalFilename", "clientgen.exe"
VALUE "OriginalFilename", "@GRAPHQL_RC_FILENAME@.exe"
VALUE "ProductName", "CppGraphQLGen"
VALUE "ProductVersion", CLIENTGEN_RC_VERSION_STR
VALUE "ProductVersion", GRAPHQL_RC_VERSION_STR
END
END

Expand Down
File renamed without changes.
43 changes: 0 additions & 43 deletions cmake/SchemaGen.rc.in

This file was deleted.

14 changes: 13 additions & 1 deletion cmake/cppgraphqlgen-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
cppgraphqlgen
-------------

The following import targets are created
The following import targets are created:

::

Expand All @@ -15,8 +15,20 @@ The following import targets are created
cppgraphqlgen::graphqlintrospection
cppgraphqlgen::graphqljson
cppgraphqlgen::schemagen
cppgraphqlgen::clientgen

The following functions are defined to help with code generation and build targets:

::

update_graphql_schema_files
add_graphql_schema_target
add_graphql_schema_no_introspection_target
update_graphql_client_files
add_graphql_client_target
#]=======================================================================]

include(CMakeFindDependencyMacro)
find_package(Threads REQUIRED)
include("${CMAKE_CURRENT_LIST_DIR}/cppgraphqlgen-targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cppgraphqlgen-functions.cmake")
101 changes: 101 additions & 0 deletions cmake/cppgraphqlgen-functions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

get_filename_component(GRAPHQL_UPDATE_SCHEMA_FILES_SCRIPT
"${CMAKE_CURRENT_LIST_DIR}/cppgraphqlgen-update-schema-files.cmake"
ABSOLUTE)

get_filename_component(GRAPHQL_UPDATE_CLIENT_FILES_SCRIPT
"${CMAKE_CURRENT_LIST_DIR}/cppgraphqlgen-update-client-files.cmake"
ABSOLUTE)

function(update_graphql_schema_files SCHEMA_TARGET SCHEMA_GRAPHQL SCHEMA_PREFIX SCHEMA_NAMESPACE)
set_property(DIRECTORY APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS ${SCHEMA_TARGET}_schema_files)

# Collect optional arguments
set(ADDITIONAL_SCHEMAGEN_ARGS "")
if(ARGC GREATER 4)
math(EXPR LAST_ARG "${ARGC} - 1")
foreach(ARGN RANGE 4 ${LAST_ARG})
set(NEXT_ARG "${ARGV${ARGN}}")
list(APPEND ADDITIONAL_SCHEMAGEN_ARGS "${NEXT_ARG}")
endforeach()
endif()

add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_TARGET}_schema_files
COMMAND
${CMAKE_COMMAND} "-DSCHEMA_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}"
"-DSCHEMA_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}"
"-DSCHEMAGEN_PROGRAM=$<TARGET_FILE:cppgraphqlgen::schemagen>"
"-DSCHEMA_TARGET=${SCHEMA_TARGET}" "-DSCHEMA_GRAPHQL=${SCHEMA_GRAPHQL}"
"-DSCHEMA_PREFIX=${SCHEMA_PREFIX}" "-DSCHEMA_NAMESPACE=${SCHEMA_NAMESPACE}"
"-DADDITIONAL_SCHEMAGEN_ARGS=${ADDITIONAL_SCHEMAGEN_ARGS}"
-P ${GRAPHQL_UPDATE_SCHEMA_FILES_SCRIPT}
DEPENDS ${SCHEMA_GRAPHQL} ${GRAPHQL_UPDATE_SCHEMA_FILES_SCRIPT} cppgraphqlgen::schemagen
COMMENT "Generating ${SCHEMA_TARGET} GraphQL schema"
VERBATIM)
endfunction()

function(add_graphql_schema_target SCHEMA_TARGET)
add_custom_target(${SCHEMA_TARGET}_update_schema ALL
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_TARGET}_schema_files)

file(STRINGS ${SCHEMA_TARGET}_schema_files SCHEMA_FILES)
add_library(${SCHEMA_TARGET}_schema STATIC ${SCHEMA_FILES})
add_dependencies(${SCHEMA_TARGET}_schema ${SCHEMA_TARGET}_update_schema)
target_include_directories(${SCHEMA_TARGET}_schema PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(${SCHEMA_TARGET}_schema PUBLIC cppgraphqlgen::graphqlintrospection)
endfunction()

function(add_graphql_schema_no_introspection_target SCHEMA_NO_INTROSPECTION_TARGET)
add_custom_target(${SCHEMA_NO_INTROSPECTION_TARGET}_update_schema ALL
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NO_INTROSPECTION_TARGET}_schema_files)

file(STRINGS ${SCHEMA_NO_INTROSPECTION_TARGET}_schema_files SCHEMA_FILES)
add_library(${SCHEMA_NO_INTROSPECTION_TARGET}_schema STATIC ${SCHEMA_FILES})
add_dependencies(${SCHEMA_NO_INTROSPECTION_TARGET}_schema ${SCHEMA_NO_INTROSPECTION_TARGET}_update_schema)
target_include_directories(${SCHEMA_NO_INTROSPECTION_TARGET}_schema PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(${SCHEMA_NO_INTROSPECTION_TARGET}_schema PUBLIC cppgraphqlgen::graphqlservice)
endfunction()

function(update_graphql_client_files CLIENT_TARGET SCHEMA_GRAPHQL REQUEST_GRAPHQL CLIENT_PREFIX CLIENT_NAMESPACE)
set_property(DIRECTORY APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS ${CLIENT_TARGET}_client_files)

# Collect optional arguments
set(ADDITIONAL_CLIENTGEN_ARGS "")
if(ARGC GREATER 5)
math(EXPR LAST_ARG "${ARGC} - 1")
foreach(ARGN RANGE 5 ${LAST_ARG})
set(NEXT_ARG "${ARGV${ARGN}}")
list(APPEND ADDITIONAL_CLIENTGEN_ARGS "${NEXT_ARG}")
endforeach()
endif()

add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${CLIENT_TARGET}_client_files
COMMAND
${CMAKE_COMMAND} "-DCLIENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}"
"-DCLIENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}"
"-DCLIENTGEN_PROGRAM=$<TARGET_FILE:cppgraphqlgen::clientgen>" "-DCLIENT_TARGET=${CLIENT_TARGET}"
"-DSCHEMA_GRAPHQL=${SCHEMA_GRAPHQL}" "-DREQUEST_GRAPHQL=${REQUEST_GRAPHQL}"
"-DCLIENT_PREFIX=${CLIENT_PREFIX}" "-DCLIENT_NAMESPACE=${CLIENT_NAMESPACE}"
"-DADDITIONAL_CLIENTGEN_ARGS=${ADDITIONAL_CLIENTGEN_ARGS}"
-P ${GRAPHQL_UPDATE_CLIENT_FILES_SCRIPT}
DEPENDS ${SCHEMA_GRAPHQL} ${REQUEST_GRAPHQL} ${GRAPHQL_UPDATE_CLIENT_FILES_SCRIPT} cppgraphqlgen::clientgen
COMMENT "Generating ${CLIENT_TARGET} client"
VERBATIM)
endfunction()

function(add_graphql_client_target CLIENT_TARGET)
add_custom_target(${CLIENT_TARGET}_update_client ALL
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${CLIENT_TARGET}_client_files)

file(STRINGS ${CLIENT_TARGET}_client_files CLIENT_FILES)
add_library(${CLIENT_TARGET}_client STATIC ${CLIENT_FILES})
add_dependencies(${CLIENT_TARGET}_client ${CLIENT_TARGET}_update_client)
target_include_directories(${CLIENT_TARGET}_client PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(${CLIENT_TARGET}_client PUBLIC cppgraphqlgen::graphqlclient)
endfunction()
58 changes: 58 additions & 0 deletions cmake/cppgraphqlgen-update-client-files.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

# Normalize the filesystem paths
get_filename_component(CLIENT_SOURCE_DIR ${CLIENT_SOURCE_DIR} ABSOLUTE)
get_filename_component(CLIENT_BINARY_DIR ${CLIENT_BINARY_DIR} ABSOLUTE)
get_filename_component(CLIENTGEN_PROGRAM ${CLIENTGEN_PROGRAM} ABSOLUTE)
get_filename_component(SCHEMA_GRAPHQL "${CLIENT_SOURCE_DIR}/${SCHEMA_GRAPHQL}" ABSOLUTE)
get_filename_component(REQUEST_GRAPHQL "${CLIENT_SOURCE_DIR}/${REQUEST_GRAPHQL}" ABSOLUTE)

file(MAKE_DIRECTORY ${CLIENT_BINARY_DIR})

# Cleanup all of the stale files in the binary directory
file(GLOB PREVIOUS_FILES ${CLIENT_BINARY_DIR}/*.h ${CLIENT_BINARY_DIR}/*.cpp
${CLIENT_BINARY_DIR}/${CLIENT_TARGET}_client_files)
foreach(PREVIOUS_FILE ${PREVIOUS_FILES})
file(REMOVE ${PREVIOUS_FILE})
endforeach()

set(CLIENTGEN_ARGS "--schema=${SCHEMA_GRAPHQL}" "--request=${REQUEST_GRAPHQL}" "--prefix=${CLIENT_PREFIX}" "--namespace=${CLIENT_NAMESPACE}")
foreach(CLIENTGEN_ARG ${ADDITIONAL_CLIENTGEN_ARGS})
list(APPEND CLIENTGEN_ARGS ${CLIENTGEN_ARG})
endforeach()

# Regenerate the sources in the binary directory
execute_process(
COMMAND ${CLIENTGEN_PROGRAM} ${CLIENTGEN_ARGS}
OUTPUT_FILE ${CLIENT_TARGET}_client_files
WORKING_DIRECTORY ${CLIENT_BINARY_DIR})

# Get the up-to-date list of files in the binary directory
set(FILE_NAMES "")
file(GLOB NEW_FILES ${CLIENT_BINARY_DIR}/*.h ${CLIENT_BINARY_DIR}/*.cpp)
foreach(NEW_FILE ${NEW_FILES})
get_filename_component(NEW_FILE ${NEW_FILE} NAME)
list(APPEND FILE_NAMES "${NEW_FILE}")
endforeach()

# Don't update the files in the source directory if no files were generated in the binary directory.
if(NOT FILE_NAMES)
message(FATAL_ERROR "Schema generation failed!")
endif()

# Remove stale files in the source directory
cmake_policy(SET CMP0057 NEW)
file(GLOB OLD_FILES ${CLIENT_SOURCE_DIR}/*.h ${CLIENT_SOURCE_DIR}/*.cpp)
foreach(OLD_FILE ${OLD_FILES})
get_filename_component(OLD_FILE ${OLD_FILE} NAME)
if(NOT OLD_FILE IN_LIST FILE_NAMES)
file(REMOVE "${CLIENT_SOURCE_DIR}/${OLD_FILE}")
endif()
endforeach()

# Copy new and modified files from the binary directory to the source directory
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CLIENT_BINARY_DIR}/${CLIENT_TARGET}_client_files
${NEW_FILES}
${CLIENT_SOURCE_DIR})
57 changes: 57 additions & 0 deletions cmake/cppgraphqlgen-update-schema-files.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

# Normalize the filesystem paths
get_filename_component(SCHEMA_SOURCE_DIR ${SCHEMA_SOURCE_DIR} ABSOLUTE)
get_filename_component(SCHEMA_BINARY_DIR ${SCHEMA_BINARY_DIR} ABSOLUTE)
get_filename_component(SCHEMAGEN_PROGRAM ${SCHEMAGEN_PROGRAM} ABSOLUTE)
get_filename_component(SCHEMA_GRAPHQL "${SCHEMA_SOURCE_DIR}/${SCHEMA_GRAPHQL}" ABSOLUTE)

file(MAKE_DIRECTORY ${SCHEMA_BINARY_DIR})

# Cleanup all of the stale files in the binary directory
file(GLOB PREVIOUS_FILES ${SCHEMA_BINARY_DIR}/*.h ${SCHEMA_BINARY_DIR}/*.cpp
${SCHEMA_BINARY_DIR}/${SCHEMA_TARGET}_schema_files)
foreach(PREVIOUS_FILE ${PREVIOUS_FILES})
file(REMOVE ${PREVIOUS_FILE})
endforeach()

set(SCHEMAGEN_ARGS "--schema=${SCHEMA_GRAPHQL}" "--prefix=${SCHEMA_PREFIX}" "--namespace=${SCHEMA_NAMESPACE}")
foreach(SCHEMAGEN_ARG ${ADDITIONAL_SCHEMAGEN_ARGS})
list(APPEND SCHEMAGEN_ARGS ${SCHEMAGEN_ARG})
endforeach()

# Regenerate the sources in the binary directory
execute_process(
COMMAND ${SCHEMAGEN_PROGRAM} ${SCHEMAGEN_ARGS}
OUTPUT_FILE ${SCHEMA_TARGET}_schema_files
WORKING_DIRECTORY ${SCHEMA_BINARY_DIR})

# Get the up-to-date list of files in the binary directory
set(FILE_NAMES "")
file(GLOB NEW_FILES ${SCHEMA_BINARY_DIR}/*.h ${SCHEMA_BINARY_DIR}/*.cpp)
foreach(NEW_FILE ${NEW_FILES})
get_filename_component(NEW_FILE ${NEW_FILE} NAME)
list(APPEND FILE_NAMES "${NEW_FILE}")
endforeach()

# Don't update the files in the source directory if no files were generated in the binary directory.
if(NOT FILE_NAMES)
message(FATAL_ERROR "Schema generation failed!")
endif()

# Remove stale files in the source directory
cmake_policy(SET CMP0057 NEW)
file(GLOB OLD_FILES ${SCHEMA_SOURCE_DIR}/*.h ${SCHEMA_SOURCE_DIR}/*.cpp)
foreach(OLD_FILE ${OLD_FILES})
get_filename_component(OLD_FILE ${OLD_FILE} NAME)
if(NOT OLD_FILE IN_LIST FILE_NAMES)
file(REMOVE "${SCHEMA_SOURCE_DIR}/${OLD_FILE}")
endif()
endforeach()

# Copy new and modified files from the binary directory to the source directory
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
${SCHEMA_BINARY_DIR}/${SCHEMA_TARGET}_schema_files
${NEW_FILES}
${SCHEMA_SOURCE_DIR})
2 changes: 1 addition & 1 deletion cmake/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.6.0
3.7.0
Loading