mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-25 13:48:42 -05:00
Fix dependency and sequencing issues of upload-samples target
git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6314 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
parent
e2dcc912a1
commit
3c428b139a
@ -3,120 +3,25 @@ set (SAMPLE_FILES
|
||||
JT9/130418_1742.wav
|
||||
)
|
||||
|
||||
set_directory_properties (PROPERTIES EXCLUDE_FROM_ALL ON)
|
||||
set (contents_file_name contents_${WSJTX_VERSION_MAJOR}.${WSJTX_VERSION_MINOR}.json)
|
||||
set (contents_file ${CMAKE_CURRENT_BINARY_DIR}/${contents_file_name})
|
||||
set (web_tree ${CMAKE_CURRENT_BINARY_DIR}/web)
|
||||
set_source_files_properties (${contents_file} PROPERTIES GENERATED ON)
|
||||
|
||||
set (contents_file_ ${CMAKE_CURRENT_BINARY_DIR}/contents_${WSJTX_VERSION_MAJOR}.${WSJTX_VERSION_MINOR}.json)
|
||||
|
||||
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 SAMPLE_FILES)
|
||||
foreach (sample_ IN LISTS SAMPLE_FILES)
|
||||
string (REGEX MATCHALL "[^/]*/" dirs_ "${sample_}")
|
||||
string (REPLACE "/" "" dirs_ "${dirs_}")
|
||||
string (REGEX MATCH "[^/]*$" name_ "${sample_}")
|
||||
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_})
|
||||
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 ()
|
||||
file (COPY ${sample_} DESTINATION web/samples/${cwd_})
|
||||
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")
|
||||
|
||||
file (COPY ${contents_file_} DESTINATION web/samples)
|
||||
add_custom_command (
|
||||
OUTPUT ${contents_file}
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -Dcontents_file=${contents_file} -DFILES="${SAMPLE_FILES}" -DDEST=${CMAKE_CURRENT_BINARY_DIR} -P make_contents.cmake
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
DEPENDS ${SAMPLE_FILES} make_contents.cmake
|
||||
)
|
||||
|
||||
find_program (RSYNC_EXECUTABLE rsync)
|
||||
if (RSYNC_EXECUTABLE)
|
||||
add_custom_command (
|
||||
add_custom_command (
|
||||
OUTPUT upload.timestamp
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${contents_file} ${web_tree}/samples/${contents_file_name}
|
||||
COMMAND ${RSYNC_EXECUTABLE} ARGS -avz --progress ${CMAKE_CURRENT_BINARY_DIR}/web/samples ${PROJECT_SAMPLES_UPLOAD_DEST}
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E touch upload.timestamp
|
||||
DEPENDS ${contents_file_} ${SAMPLE_FILES}
|
||||
DEPENDS ${contents_file}
|
||||
COMMENT "Uploading WSJT-X samples to web server"
|
||||
)
|
||||
add_custom_target (upload-samples DEPENDS upload.timestamp)
|
||||
endif ()
|
||||
add_custom_target (upload-samples DEPENDS upload.timestamp)
|
||||
|
99
samples/make_contents.cmake
Normal file
99
samples/make_contents.cmake
Normal file
@ -0,0 +1,99 @@
|
||||
string (REPLACE " " ";" FILES ${FILES}) # make back into a list
|
||||
|
||||
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})
|
||||
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 ()
|
||||
file (COPY ${file} DESTINATION ${DEST}/web/samples/${cwd})
|
||||
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")
|
Loading…
Reference in New Issue
Block a user