changeset 438:31cc952fc26d

wip
author Louis Opter <kalessin@kalessin.fr>
date Sun, 17 Apr 2016 17:11:39 -0700
parents 1319ff44979e
children 680a0d813be0
files add_make_release.patch
diffstat 1 files changed, 104 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/add_make_release.patch	Sun Apr 17 15:14:48 2016 -0700
+++ b/add_make_release.patch	Sun Apr 17 17:11:39 2016 -0700
@@ -1,11 +1,35 @@
 # HG changeset patch
-# Parent  b477e34b34545051d5e8b71dfb28a531739ab953
+# Parent  d16f6ed548379278b946b5ed7caf291ba0ac4e6e
 Add a release command that can be used from buildbot
 
 diff --git a/CMakeLists.txt b/CMakeLists.txt
 --- a/CMakeLists.txt
 +++ b/CMakeLists.txt
-@@ -26,6 +26,16 @@
+@@ -3,10 +3,10 @@
+ 
+ PROJECT(LIGHTSD C)
+ 
+-SET(CPACK_PACKAGE_VERSION_MAJOR "1")
+-SET(CPACK_PACKAGE_VERSION_MINOR "2")
+-SET(CPACK_PACKAGE_VERSION_PATCH "0")
+-SET(LIGHTSD_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
++SET(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${LIGHTSD_SOURCE_DIR}/CMakeScripts")
++
++STRING(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE)
++INCLUDE(LightsdVersion)
+ 
+ MESSAGE(STATUS "lightsd version: ${LIGHTSD_VERSION}")
+ MESSAGE(STATUS "CMake version: ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}")
+@@ -15,8 +15,6 @@
+ MESSAGE(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")
+ MESSAGE(STATUS "Source directory: ${LIGHTSD_SOURCE_DIR}")
+ 
+-SET(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${LIGHTSD_SOURCE_DIR}/CMakeScripts")
+-
+ ENABLE_TESTING()
+ 
+ ### Platform checks ############################################################
+@@ -26,6 +24,16 @@
  FIND_PACKAGE(Endian REQUIRED)
  FIND_PACKAGE(Sphinx)
  
@@ -22,7 +46,7 @@
  INCLUDE(CheckFunctionExists)
  INCLUDE(CheckVariableExists)
  INCLUDE(TestBigEndian)
-@@ -92,9 +102,7 @@
+@@ -92,9 +100,7 @@
  
  # 2.8.11 is the first version with TARGET_INCLUDE_DIRECTORIES:
  IF (CMAKE_VERSION VERSION_GREATER 2.8.10)
@@ -33,7 +57,7 @@
      ADD_SUBDIRECTORY(tests)
  ELSE ()
      MESSAGE(
-@@ -105,7 +113,14 @@
+@@ -105,7 +111,14 @@
  ENDIF ()
  
  IF (SPHINX_FOUND)
@@ -119,7 +143,7 @@
 new file mode 100644
 --- /dev/null
 +++ b/dist/CMakeLists.txt
-@@ -0,0 +1,67 @@
+@@ -0,0 +1,75 @@
 +# I wanted to use hg export but then dpkg gave me troubles:
 +IF (BSDTAR_FOUND AND GZIP_FOUND AND XZ_FOUND AND HG_FOUND)
 +    MESSAGE(STATUS "bsdtar, mercurial (hg), gzip and xz found, archives generation enabled")
@@ -159,11 +183,15 @@
 +        DEPENDS "${TAR_ARCHIVE}" "${TARGZ_ARCHIVE}" "${TARXZ_ARCHIVE}"
 +    )
 +ELSE ()
-+    MESSAGE(STATUS "bsdtar and/or mercurial (hg), gzip, xz weren't found, archives generation disabled")
++    MESSAGE(
++        STATUS
++        "bsdtar and/or mercurial (hg), gzip, xz weren't found, "
++        "archives generation disabled"
++    )
 +ENDIF ()
 +
-+IF (PYTHONINTERP_FOUND AND PYTHON_VERSION_MAJOR EQUAL 3 AND VIRTUALENV_FOUND)
-+    MESSAGE(STATUS "Python 3 and virtualenv found, release command enabled")
++IF (PYTHONINTERP_FOUND AND PYTHON_VERSION_MAJOR EQUAL 3 AND VIRTUALENV_FOUND AND HG_FOUND)
++    MESSAGE(STATUS "Python 3, virtualenv and mercurial (hg) found, release command enabled")
 +
 +    SET(VENV_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/py-env")
 +    SET(VENV_PYTHON "${VENV_DIRECTORY}/bin/python")
@@ -185,7 +213,11 @@
 +        VERBATIM
 +    )
 +ELSE ()
-+    MESSAGE(STATUS "Python 3 and/or virtualenv weren't found, release commands disabled")
++    MESSAGE(
++        STATUS
++        "Python 3 and/or virtualenv, mercurial (hg) weren't found, "
++        "release commands disabled"
++    )
 +ENDIF ()
 diff --git a/dist/dpkg/.hgtags b/dist/dpkg/.hgtags
 new file mode 100644
@@ -1030,7 +1062,7 @@
 new file mode 100644
 --- /dev/null
 +++ b/dist/release.py.in
-@@ -0,0 +1,183 @@
+@@ -0,0 +1,231 @@
 +#!/usr/bin/env python3
 +
 +import click
@@ -1039,6 +1071,7 @@
 +import jinja2
 +import semver
 +import subprocess
++import sys
 +
 +LIGHTSD_VERSION = "@LIGHTSD_VERSION@"
 +# where the lightsd sources are:
@@ -1095,10 +1128,10 @@
 +    def commit(self, msg):
 +        self._pre_commit(msg)
 +
-+        dirty = len(subprocess.check_output([
++        dirty = bool(len(subprocess.check_output([
 +            "hg", "-R", self._repo, "status"
-+        ])) != 0
-+        if dirty is False:
++        ])))
++        if dirty is False:  # be idempotent
 +            return
 +
 +        subprocess.check_call([
@@ -1149,25 +1182,72 @@
 +)
 +
 +
++def _update_lightsd_version_cmake_include(version):
++    lightsd_version_file = os.path.join(
++        LIGHTSD_SOURCE_DIR, "CMakeScripts", "LightsdVersion.cmake"
++    )
++    major, minor, patch = version.split(".", 2)
++    with open(lightsd_version_file, "wb") as fp:
++        fp.write("""# NOTE: auto-generated by the release target
++SET(CPACK_PACKAGE_VERSION_MAJOR "{}")
++SET(CPACK_PACKAGE_VERSION_MINOR "{}")
++SET(CPACK_PACKAGE_VERSION_PATCH "{}")
++SET(LIGHTSD_VERSION "${{CPACK_PACKAGE_VERSION_MAJOR}}.${{CPACK_PACKAGE_VERSION_MINOR}}.${{CPACK_PACKAGE_VERSION_PATCH}}")
++""".format(major, minor, patch).encode("utf-8"))  # noqa
++    subprocess.check_call([
++        "hg", "-R", LIGHTSD_SOURCE_DIR, "add", lightsd_version_file
++    ])
++
++
 +@click.group(invoke_without_command=True)
 +@click.pass_context
 +def release(ctx):
 +    if ctx.invoked_subcommand is not None:
 +        return
 +
-+    # TODO: developer "make release" flow
-+    click.echo("Not implemented yet :(")
++    revision, branch = [
++        part.strip() for part in subprocess.check_output([
++            "hg", "-R", LIGHTSD_SOURCE_DIR, "id", "-ib"
++        ]).split()
++    ]
++    qapplied = bool(len(subprocess.check_output([
++        "hg", "-R", LIGHTSD_SOURCE_DIR, "--config", "extensions.mq=", "qapplied"
++    ])))
++    if qapplied or revision.endswith("+") or branch != "default":
++        click.echo(
++            "Can't do a release over a dirty repository! "
++            "(rev={}, branch={}, patched={})".format(
++                revision.decode("utf-8"), branch.decode("utf-8"), qapplied
++            )
++        )
++        sys.exit(1)
 +
-+    lightsd_version_file = os.path.join(
-+        LIGHTSD_SOURCE_DIR, "CMakeScripts", "LightsdVersion.cmake"
++    # Re-gen LightsdVersion.cmake with major.minor.patch, tag, and re-gen
++    # LightsdVersion.cmake after bumping minor adding a prerelease tag:
++    version = semver.parse(LIGHTSD_VERSION)
++    version["prerelease"] = version["build"] = None
++    version = click.prompt(
++        "Confirm the version to release",
++        default=semver.format_version(version),
++        type=version.parse
 +    )
-+    with open(lightsd_version_file, "wb") as fp:
-+        fp.write("""# NOTE: auto-generated by the release target
-+SET(CPACK_PACKAGE_VERSION_MAJOR "{}")
-+SET(CPACK_PACKAGE_VERSION_MINOR "{}")
-+SET(CPACK_PACKAGE_VERSION_PATCH "{}")
-+SET(LIGHTSD_VERSION "${{CPACK_PACKAGE_VERSION_MAJOR}}.${{CPACK_PACKAGE_VERSION_MINOR}}.${{CPACK_PACKAGE_VERSION_PATCH}}")
-+""".format()
++    _update_lightsd_version_cmake_include(version)
++    subprocess.check_call([
++        "hg", "-R", LIGHTSD_SOURCE_DIR,
++        "tag", "-m", "Tagging release {}".format(version), version
++        # TODO: use docutils to extract the changelog section
++    ])
++    version = semver.bump_prerelease(semver.bump_patch(version))
++    _update_lightsd_version_cmake_include(version)
++    subprocess.check_call([
++        "hg", "-R", LIGHTSD_SOURCE_DIR,
++        "commit", "-m", "Back to development, {}".format(version)
++    ])
++
++    subprocess.check_call(["hg", "-R", LIGHTSD_SOURCE_DIR, "out"])
++    if click.confirm("Are you ready to push those commit?"):
++        subprocess.check_call(["hg", "-R", LIGHTSD_SOURCE_DIR, "push"])
++
 +    return
 +
 +