From: Julian Andres Klode <jak@debian.org>
Date: Sun, 7 Aug 2016 01:34:18 +0000 (+0200)
Subject: CMake: Improve handling of vendor files
X-Git-Tag: 1.3_rc1~9^2~25
X-Git-Url: https://git.saurik.com/apt.git/commitdiff_plain/7d33e7c79cd6c3f0f053d13532ca73ce3bf7c5ce

CMake: Improve handling of vendor files

First of all, instead of creating the files at configure time,
generate the files using normal target. This has the huge advantage
that they are rebuilt if their input changes. While we are at it,
also add dependencies on the vendor entity files.

This also fixes the path to the vendor script, which was given
relatively before, which obviously won't work when running from
inside a deeper subdirectory.

To speed things up, pass the --vendor option to getinfo, so we
do not have to find out the current vendor in getinfo all over
again.

Gbp-Dch: ignore
---

diff --git a/CMake/Misc.cmake b/CMake/Misc.cmake
index 584a4da2a..3329fc20f 100644
--- a/CMake/Misc.cmake
+++ b/CMake/Misc.cmake
@@ -24,16 +24,30 @@ function(add_vendor_file)
     set(oneValueArgs OUTPUT INPUT MODE)
     set(multiValueArgs VARIABLES)
     cmake_parse_arguments(AVF "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
-    message(STATUS "Configuring vendor file ${AVF_OUTPUT}")
 
-    FILE(READ ${CMAKE_CURRENT_SOURCE_DIR}/${AVF_INPUT} input)
-    foreach(variable ${AVF_VARIABLES})
-        execute_process(COMMAND ../vendor/getinfo ${variable} OUTPUT_VARIABLE value OUTPUT_STRIP_TRAILING_WHITESPACE)
-        string(REPLACE "&${variable};" "${value}" input "${input}")
-    endforeach()
-    file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${AVF_OUTPUT} "${input}")
+    set(in ${CMAKE_CURRENT_SOURCE_DIR}/${AVF_INPUT})
+    set(out ${CMAKE_CURRENT_BINARY_DIR}/${AVF_OUTPUT})
+
+    add_custom_command(
+        OUTPUT ${out}
+        COMMAND ${CMAKE_COMMAND} -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
+                                 "-DVARS=${AVF_VARIABLES}"
+                                 -DCURRENT_VENDOR=${CURRENT_VENDOR}
+                                 -DIN=${in}
+                                 -DOUT=${out}
+                                 -P ${PROJECT_SOURCE_DIR}/CMake/vendor_substitute.cmake
+        COMMAND chmod ${AVF_MODE} ${out}
+        DEPENDS ${in}
+                ${PROJECT_SOURCE_DIR}/doc/apt-verbatim.ent
+                ${PROJECT_SOURCE_DIR}/vendor/${CURRENT_VENDOR}/apt-vendor.ent
+                ${PROJECT_SOURCE_DIR}/vendor/getinfo
+                ${PROJECT_SOURCE_DIR}/CMake/vendor_substitute.cmake
+        VERBATIM
+    )
 
-    execute_process(COMMAND chmod ${AVF_MODE} ${CMAKE_CURRENT_BINARY_DIR}/${AVF_OUTPUT})
+    # Woud like to use ${AVF_OUTPUT} as target name, but then ninja gets
+    # cycles.
+    add_custom_target(vendor-${AVF_OUTPUT} ALL DEPENDS ${out})
 endfunction()
 
 # Add symbolic links to a file
diff --git a/CMake/vendor_substitute.cmake b/CMake/vendor_substitute.cmake
new file mode 100644
index 000000000..71449c9e8
--- /dev/null
+++ b/CMake/vendor_substitute.cmake
@@ -0,0 +1,8 @@
+file(READ ${IN} input)
+foreach(variable ${VARS})
+    execute_process(COMMAND ${PROJECT_SOURCE_DIR}/vendor/getinfo
+                            --vendor ${CURRENT_VENDOR} ${variable}
+                    OUTPUT_VARIABLE value OUTPUT_STRIP_TRAILING_WHITESPACE)
+    string(REPLACE "&${variable};" "${value}" input "${input}")
+endforeach()
+file(WRITE ${OUT} "${input}")