summaryrefslogtreecommitdiff
path: root/samples/make_contents.cmake
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2026-09-26 23:24:03 +0200
committerChristoph Berg <myon@debian.org>2026-09-26 23:24:03 +0200
commit059831534c7e884f0a607ed86b582fd00d821731 (patch)
tree76bcb67a78f8aa2654fd34c2ad801a62136b0170 /samples/make_contents.cmake
parentd83a420f0517d7fc47aeb288a6a0cf4891784fcc (diff)
New upstream version 3.2.0~rc1+dfsgupstream/3.2.0_rc1+dfsg
Diffstat (limited to 'samples/make_contents.cmake')
-rw-r--r--samples/make_contents.cmake107
1 files changed, 107 insertions, 0 deletions
diff --git a/samples/make_contents.cmake b/samples/make_contents.cmake
new file mode 100644
index 00000000..42f2bead
--- /dev/null
+++ b/samples/make_contents.cmake
@@ -0,0 +1,107 @@
+string (REPLACE " " ";" FILES ${FILES}) # make back into a list
+
+function(JOIN VALUES GLUE OUTPUT)
+ string (REGEX REPLACE "([^\\]|^);" "\\1${GLUE}" _TMP_STR "${VALUES}")
+ string (REGEX REPLACE "[\\](.)" "\\1" _TMP_STR "${_TMP_STR}") #fixes escaping
+ set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
+endfunction()
+
+function (indent)
+ foreach (temp RANGE ${level})
+ file (APPEND ${contents_file} " ")
+ endforeach ()
+endfunction ()
+
+function (end_entry)
+ file (APPEND ${contents_file} "\n")
+ set(first 0 PARENT_SCOPE)
+ math (EXPR level "${level} - 1")
+ indent ()
+ file (APPEND ${contents_file} "]\n")
+ math (EXPR level "${level} - 2")
+ indent ()
+ file (APPEND ${contents_file} "}")
+ string (FIND "${dirs}" "${cwd}" pos)
+ set (level ${level} PARENT_SCOPE)
+endfunction ()
+
+file (WRITE ${contents_file} "[")
+set (cwd)
+set (level 0)
+set (first 1)
+list (SORT FILES)
+foreach (file IN LISTS FILES)
+ string (REGEX MATCHALL "[^/]*/" dirs "${file}")
+ string (REPLACE "/" "" dirs "${dirs}")
+ string (REGEX MATCH "[^/]*$" name "${file}")
+ string (FIND "${dirs}" "${cwd}" pos)
+ list (LENGTH cwd cwd_count)
+ if (${pos} EQUAL 0)
+ # same root
+ while (${cwd_count} GREATER 0)
+ list (REMOVE_AT dirs 0)
+ math (EXPR cwd_count "${cwd_count} - 1")
+ endwhile ()
+ else ()
+ # reduce cwd until matched
+ while ((NOT ${pos} EQUAL 0) AND ${cwd_count} GREATER 0)
+ math (EXPR cwd_count "${cwd_count} - 1")
+ list (REMOVE_AT cwd ${cwd_count})
+ string (FIND "${dirs}" "${cwd}" pos)
+ end_entry ()
+ endwhile ()
+ # back to same root
+ while (${cwd_count} GREATER 0)
+ list (REMOVE_AT dirs 0)
+ math (EXPR cwd_count "${cwd_count} - 1")
+ endwhile ()
+ endif ()
+ list (LENGTH cwd cwd_count)
+ list (LENGTH dirs path_count)
+ while (${path_count} GREATER 0)
+ list (GET dirs 0 dir)
+ list (APPEND cwd "${dir}")
+ list (REMOVE_AT dirs 0)
+ if (${first})
+ file (APPEND ${contents_file} "\n")
+ set (first 0)
+ else ()
+ file (APPEND ${contents_file} ",\n")
+ endif ()
+ indent ()
+ file (APPEND ${contents_file} "{\n")
+ math (EXPR level "${level} + 1")
+ indent ()
+ file (APPEND ${contents_file} "\"type\": \"directory\",\n")
+ indent ()
+ file (APPEND ${contents_file} "\"name\": \"${dir}\",\n")
+ indent ()
+ file (APPEND ${contents_file} "\"entries\": [")
+ set (first 1)
+ math (EXPR level "${level} + 2")
+ math (EXPR path_count "${path_count} - 1")
+ endwhile ()
+ JOIN ("${cwd}" "/" path)
+ file (COPY "${file}" DESTINATION "${DEST}/web/samples/${path}")
+ if (${first})
+ file (APPEND ${contents_file} "\n")
+ set (first 0)
+ else ()
+ file (APPEND ${contents_file} ",\n")
+ endif ()
+ indent ()
+ file (APPEND ${contents_file} "{\n")
+ math (EXPR level "${level} + 1")
+ indent ()
+ file (APPEND ${contents_file} "\"type\": \"file\",\n")
+ indent ()
+ file (APPEND ${contents_file} "\"name\": \"${name}\"\n")
+ math (EXPR level "${level} - 1")
+ indent ()
+ file (APPEND ${contents_file} "}")
+ set (first 0)
+endforeach ()
+if (${level} GREATER 1)
+ end_entry ()
+endif ()
+file (APPEND ${contents_file} "\n]\n")