-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathGenerateScripts.cmake
More file actions
105 lines (92 loc) · 3.9 KB
/
Copy pathGenerateScripts.cmake
File metadata and controls
105 lines (92 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Functions to generate downgrade scripts
# generate_downgrade_script(<options>)
#
# Create a downgrade script from a source version to a target version. The
# ScriptFiles.cmake manifest is read from the target version's git tag to
# determine which files make up the prolog and epilog.
#
# SOURCE_VERSION <version>
# Version to generate downgrade script from.
#
# TARGET_VERSION <version>
# Version to generate downgrade script to.
#
# OUTPUT_DIRECTORY <dir>
# Output directory for script file. Defaults to CMAKE_CURRENT_BINARY_DIR.
#
# INPUT_DIRECTORY <dir>
# Input directory for downgrade files. Defaults to CMAKE_CURRENT_SOURCE_DIR.
#
# FILES <file> ...
# Downgrade-specific files to include between the prolog and epilog.
#
# The output script concatenates:
# 1. Prolog from the target version (header.sql, pre-version-change.sql)
# 2. Downgrade files from the source version
# 3. Epilog from the target version (function defs, source files, post-update)
#
# All files undergo @VARIABLE@ template substitution with MODULE_PATHNAME set
# to the target version's shared library path.
function(generate_downgrade_script)
set(options)
set(oneValueArgs SOURCE_VERSION TARGET_VERSION OUTPUT_DIRECTORY
INPUT_DIRECTORY FILES)
cmake_parse_arguments(_downgrade "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN})
if(NOT _downgrade_OUTPUT_DIRECTORY)
set(_downgrade_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()
if(NOT _downgrade_INPUT_DIRECTORY)
set(_downgrade_INPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()
foreach(_downgrade_file ${_downgrade_FILES})
if(NOT EXISTS ${_downgrade_INPUT_DIRECTORY}/${_downgrade_file})
message(FATAL_ERROR "No downgrade file ${_downgrade_file} found!")
endif()
endforeach()
# Fetch manifest with list of files for the prolog and epilog from the target
# version.
git_versioned_get(VERSION ${_downgrade_TARGET_VERSION} FILES
${CMAKE_SOURCE_DIR}/cmake/ScriptFiles.cmake)
# This will include the variables in this scope, but not in the parent scope
# so we can read them locally without affecting the parent scope.
include(
${CMAKE_BINARY_DIR}/v${_downgrade_TARGET_VERSION}/cmake/ScriptFiles.cmake)
set(_downgrade_PRE_FILES "header.sql;views_detached.sql;${PRE_DOWNGRADE_FILES}")
set(_downgrade_POST_FILES "${PRE_INSTALL_FUNCTION_FILES};${SOURCE_FILES}" ${POST_UPDATE_FILES})
# Fetch epilog from target version.
git_versioned_get(
VERSION
${_downgrade_TARGET_VERSION}
FILES
${_downgrade_POST_FILES}
RESULT_FILES
_epilog_files
IGNORE_ERRORS)
# Assemble the full file list: prolog + downgrade files + epilog
set(_files)
foreach(_downgrade_file ${_downgrade_PRE_FILES})
get_filename_component(_downgrade_filename ${_downgrade_file} NAME)
configure_file(${_downgrade_file} ${_downgrade_INPUT_DIRECTORY}/${_downgrade_filename} COPYONLY)
list(APPEND _files ${_downgrade_INPUT_DIRECTORY}/${_downgrade_filename})
endforeach()
foreach(_downgrade_file ${_downgrade_FILES})
list(APPEND _files ${_downgrade_INPUT_DIRECTORY}/${_downgrade_file})
endforeach()
list(APPEND _files ${_epilog_files})
# Set template variables for the target version
set(MODULE_PATHNAME "$libdir/timescaledb-${_downgrade_TARGET_VERSION}")
set(LOADER_PATHNAME "$libdir/timescaledb")
set(PROJECT_VERSION_MOD ${PREVIOUS_VERSION})
# Process all template files and concatenate into the output script
set(_script timescaledb--${_downgrade_SOURCE_VERSION}--${_downgrade_TARGET_VERSION}.sql)
set(_output ${_downgrade_OUTPUT_DIRECTORY}/${_script})
message(STATUS "Generating script ${_script}")
file(WRITE ${_output} "")
foreach(_file ${_files})
configure_file(${_file} ${_file}.gen @ONLY)
file(READ ${_file}.gen _contents)
file(APPEND ${_output} "${_contents}")
endforeach()
install(FILES ${_output} DESTINATION "${PG_SHAREDIR}/extension")
endfunction()