浏览代码

Utilities/Release: Replace upload step with a "push" script

Replace the `upload_release.cmake` script with a `push.bash` script
that is more configurable from the command line and that does not
hard-code any destinations.  Instead of using `scp` to access
`cmake.org` directly, push the files atomically to a staging
directory from which another process will actually upload them.
Brad King 6 年之前
父节点
当前提交
9bf97363b0
共有 3 个文件被更改,包括 72 次插入42 次删除
  1. 2 2
      Tests/CMakeLists.txt
  2. 70 0
      Utilities/Release/push.bash
  3. 0 40
      Utilities/Release/upload_release.cmake

+ 2 - 2
Tests/CMakeLists.txt

@@ -770,14 +770,14 @@ if(BUILD_TESTING)
     file(WRITE "${_TEST_DIR}/nightly-cmake.sh"
       "cd ${_TEST_DIR}
 ${CMake_BINARY_DIR}/bin/cmake -DCMAKE_CREATE_VERSION=nightly -P ${CMake_SOURCE_DIR}/Utilities/Release/${script}
-${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release/upload_release.cmake
+${CMake_SOURCE_DIR}/Utilities/Release/push.bash --dir dev -- '${CMake_BUILD_NIGHTLY_RELEASES}'
     ")
     add_test(${name} /bin/sh ${_TEST_DIR}/nightly-cmake.sh)
     if(COMMAND SET_TESTS_PROPERTIES AND COMMAND GET_TEST_PROPERTY)
       set_tests_properties (${name} PROPERTIES TIMEOUT ${CMAKE_LONG_TEST_TIMEOUT})
     endif()
   endmacro()
-  if(CMAKE_BUILD_NIGHTLY_RELEASES)
+  if(CMake_BUILD_NIGHTLY_RELEASES)
     ADD_NIGHTLY_BUILD_TEST(CMakeNightlyWin32
       win32_release.cmake)
     ADD_NIGHTLY_BUILD_TEST(CMakeNightlyWin64

+ 70 - 0
Utilities/Release/push.bash

@@ -0,0 +1,70 @@
+#!/usr/bin/env bash
+
+usage='usage: push.bash [<options>] [--] <dest>
+
+Options:
+
+    --dir     <dir>            Specify subdirectory under destination.
+                               Defaults to "v<version>".
+    --version <ver>            CMake <major>.<minor> version number to push.
+                               Defaults to version of source tree.
+'
+
+die() {
+    echo "$@" 1>&2; exit 1
+}
+
+cmake_source_dir="${BASH_SOURCE%/*}/../.."
+
+cmake_version_component()
+{
+  sed -n "
+/^set(CMake_VERSION_${1}/ {s/set(CMake_VERSION_${1} *\([0-9]*\))/\1/;p;}
+" "${cmake_source_dir}/Source/CMakeVersion.cmake"
+}
+
+
+version=''
+dir=''
+while test "$#" != 0; do
+    case "$1" in
+    --dir) shift; dir="$1" ;;
+    --version) shift; version="$1" ;;
+    --) shift ; break ;;
+    -*) die "$usage" ;;
+    *) break ;;
+    esac
+    shift
+done
+test "$#" = 1 || die "$usage"
+readonly dest="$1"
+
+if test -z "$version"; then
+    cmake_version_major="$(cmake_version_component MAJOR)"
+    cmake_version_minor="$(cmake_version_component MINOR)"
+    version="${cmake_version_major}.${cmake_version_minor}"
+fi
+readonly version
+
+if test -z "$dir"; then
+    dir="v${version}"
+fi
+readonly dir
+
+for f in cmake-${version}*; do
+    if ! test -f "${f}"; then
+        continue
+    fi
+
+    echo "pushing '${f}'"
+
+    # Make a copy with a new timestamp and atomically rename into place.
+    tf="${dest}/${dir}/.tmp.${f}"
+    df="${dest}/${dir}/${f}"
+    cp "${f}" "${tf}"
+    mv "${tf}" "${df}"
+
+    # Pause to give each file a distinct time stamp even with 1s resolution
+    # so that sorting by time also sorts alphabetically.
+    sleep 1.1
+done

+ 0 - 40
Utilities/Release/upload_release.cmake

@@ -1,40 +0,0 @@
-set(CTEST_RUN_CURRENT_SCRIPT 0)
-if(NOT VERSION)
-  include(${CMAKE_CURRENT_LIST_DIR}/../../Source/CMakeVersion.cmake)
-  set(VERSION ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR})
-endif()
-if(NOT DEFINED PROJECT_PREFIX)
-  set(PROJECT_PREFIX cmake-${VERSION})
-endif()
-if(NOT DEFINED DIR)
-  set(DIR "v${VERSION}")
-endif()
-file(GLOB FILES ${CMAKE_CURRENT_SOURCE_DIR} "${PROJECT_PREFIX}*")
-list(SORT FILES)
-list(REVERSE FILES)
-message("${FILES}")
-set(UPLOAD_LOC
-  "[email protected]:/projects/FTP/pub/cmake/${DIR}")
-set(count 0)
-foreach(file ${FILES})
-  if(NOT IS_DIRECTORY ${file})
-    message("upload ${file} ${UPLOAD_LOC}")
-    execute_process(COMMAND
-      scp ${file} ${UPLOAD_LOC}
-      RESULT_VARIABLE result)
-    if("${result}" GREATER 0)
-      message(FATAL_ERROR "failed to upload file to ${UPLOAD_LOC}")
-    endif()
-
-    # Pause to give each upload a distinct (to the nearest second)
-    # time stamp
-    if(COMMAND ctest_sleep)
-      ctest_sleep(2)
-    endif()
-
-    math(EXPR count "${count} + 1")
-  endif()
-endforeach()
-if(${count} EQUAL 0)
-   message(FATAL_ERROR "Error no files uploaded.")
-endif()