From aff40072e992a6c0cffd27ff858405220f221b0a Mon Sep 17 00:00:00 2001 From: Haonan Date: Fri, 22 Nov 2024 10:16:58 +0800 Subject: [PATCH] Auto update cpp & py project version when build with maven (#306) * Auto update cpp&py project version when build with maven * fix miss clear dylib --- cpp/CMakeLists.txt | 5 ++-- cpp/VersionUpdater.groovy | 42 ++++++++++++++++++++++++++++++ cpp/pom.xml | 50 ++++++++++++++++++------------------ cpp/src/CMakeLists.txt | 4 +-- pom.xml | 1 + python/VersionUpdater.groovy | 41 +++++++++++++++++++++++++++++ python/pom.xml | 27 ++++++++++++++++++- python/setup.py | 40 ++++++++++++++++------------- 8 files changed, 161 insertions(+), 49 deletions(-) create mode 100644 cpp/VersionUpdater.groovy create mode 100644 python/VersionUpdater.groovy diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 5b96da353..1ba393255 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -20,8 +20,7 @@ cmake_minimum_required(VERSION 3.11) project(TsFile_CPP) cmake_policy(SET CMP0079 NEW) -set(TsFile_CPP_VERSION_MAJOR 0) -set(TsFile_CPP_VERSION_MINOR 1) +set(TsFile_CPP_VERSION 1.2.0.dev) set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -Wall -Werror") message("cmake using: USE_CPP11=${USE_CPP11}") @@ -68,7 +67,7 @@ endif() message("CMAKE DEBUG: CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}") set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) -set(PROJECT_INCLUDE_DIR ${PROJECT_INCLUDE_DIR} +set(PROJECT_INCLUDE_DIR ${PROJECT_INCLUDE_DIR} ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/third_party/lz4 ${PROJECT_SOURCE_DIR}/third_party/lzokay diff --git a/cpp/VersionUpdater.groovy b/cpp/VersionUpdater.groovy new file mode 100644 index 000000000..49cbc6504 --- /dev/null +++ b/cpp/VersionUpdater.groovy @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Synchronize the version in CMakeLists.txt and the one used in the maven pom. +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +def cppProjectFile = new File(project.basedir, "CMakeLists.txt") +def currentMavenVersion = project.version as String +def currentCppVersion = currentMavenVersion +if(currentMavenVersion.contains("-SNAPSHOT")) { + currentCppVersion = currentMavenVersion.split("-SNAPSHOT")[0] + ".dev" +} +println "Current Project Version in Maven: " + currentMavenVersion + +def match = cppProjectFile.text =~ /set\(TsFile_CPP_VERSION\s+(.+?)\)/ +def cppProjectFileVersion = match[0][1] +println "Current Project Version in CMake: " + cppProjectFileVersion + +if (cppProjectFileVersion != currentCppVersion) { + cppProjectFile.text = cppProjectFile.text.replace("set(TsFile_CPP_VERSION " + cppProjectFileVersion + ")", "set(TsFile_CPP_VERSION " + currentCppVersion + ")") + println "Version in CMakeLists.txt updated from " + cppProjectFileVersion + " to " + currentCppVersion + // TODO: When releasing, we might need to manually add this file to the release preparation commit. +} else { + println "Version in CMakeLists.txt is up to date" +} diff --git a/cpp/pom.xml b/cpp/pom.xml index 653246167..c36997356 100644 --- a/cpp/pom.xml +++ b/cpp/pom.xml @@ -28,7 +28,6 @@ pom TsFile: C++ - 4.0.22 common,examples,tsfile ${project.build.directory}/build-wrapper-output @@ -120,6 +119,31 @@ org.apache.maven.plugins maven-surefire-plugin + + org.codehaus.gmaven + groovy-maven-plugin + 2.1.1 + + + + sync-project-version + process-sources + + execute + + + ${project.basedir}/VersionUpdater.groovy + + + + + + org.apache.groovy + groovy + ${groovy.version} + + + @@ -159,30 +183,6 @@ - - org.codehaus.gmaven - groovy-maven-plugin - - - - modify-cmake - process-test-sources - - execute - - - ${project.basedir}/SonarcloudBuildWrapperHack.groovy - - - - - - org.apache.groovy - groovy - ${groovy.version} - - - diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt index ce0e21efc..643e70a1d 100644 --- a/cpp/src/CMakeLists.txt +++ b/cpp/src/CMakeLists.txt @@ -38,8 +38,8 @@ else() target_link_libraries(tsfile common_obj compress_obj cwrapper_obj file_obj read_obj write_obj) endif() -set(LIBTSFILE_PROJECT_VERSION 1.0) -set(LIBTSFILE_SO_VERSION 1.0) +set(LIBTSFILE_PROJECT_VERSION ${TsFile_CPP_VERSION}) +set(LIBTSFILE_SO_VERSION ${TsFile_CPP_VERSION}) set_target_properties(tsfile PROPERTIES VERSION ${LIBTSFILE_PROJECT_VERSION}) set_target_properties(tsfile PROPERTIES SOVERSION ${LIBTSFILE_SO_VERSION}) diff --git a/pom.xml b/pom.xml index d58b2b09f..0b668e5de 100644 --- a/pom.xml +++ b/pom.xml @@ -40,6 +40,7 @@ 2.43.0 1.22.0 1.21.1 + 4.0.22 diff --git a/python/VersionUpdater.groovy b/python/VersionUpdater.groovy new file mode 100644 index 000000000..ee3eab2b8 --- /dev/null +++ b/python/VersionUpdater.groovy @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Synchronize the version in setup.py and the one used in the maven pom. +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +def pyProjectFile = new File(project.basedir, "setup.py") +def currentMavenVersion = project.version as String +def currentPyVersion = currentMavenVersion +if(currentMavenVersion.contains("-SNAPSHOT")) { + currentPyVersion = currentMavenVersion.split("-SNAPSHOT")[0] + ".dev" +} +println "Current Project Version in Maven: " + currentMavenVersion +def match = pyProjectFile.text =~ /version\s*=\s*"(.*?)"/ +def pyProjectFileVersion = match[0][1] +println "Current Project Version in setup.py: " + pyProjectFileVersion + +if (pyProjectFileVersion != currentPyVersion) { + pyProjectFile.text = pyProjectFile.text.replace("version = \"" + pyProjectFileVersion + "\"", "version = \"" + currentPyVersion + "\"") + println "Version in setup.py updated from " + pyProjectFileVersion + " to " + currentPyVersion + // TODO: When releasing, we might need to manually add this file to the release preparation commit. +} else { + println "Version in setup.py is up to date" +} diff --git a/python/pom.xml b/python/pom.xml index 4e576af6e..f02e50218 100644 --- a/python/pom.xml +++ b/python/pom.xml @@ -29,7 +29,6 @@ TsFile: Python 2.6.0 - 4.0.21 tsfile ${project.build.directory}/build-wrapper-output @@ -160,6 +159,7 @@ ${basedir}/tsfile *.so* + *.dylib *.dll *.h *.cpp @@ -177,6 +177,31 @@ + + org.codehaus.gmaven + groovy-maven-plugin + 2.1.1 + + + + sync-project-version + process-sources + + execute + + + ${project.basedir}/VersionUpdater.groovy + + + + + + org.apache.groovy + groovy + ${groovy.version} + + + diff --git a/python/setup.py b/python/setup.py index 01120060f..96b66f81a 100644 --- a/python/setup.py +++ b/python/setup.py @@ -24,6 +24,7 @@ import shutil import os +version = "1.2.0.dev" system = platform.system() @@ -52,19 +53,6 @@ def copy_header(source, target): shutil.copyfile(source, target) -class BuildExt(build_ext): - def build_extensions(self): - numpy_include = np.get_include() - for ext in self.extensions: - ext.include_dirs.append(numpy_include) - super().build_extensions() - - def finalize_options(self): - if platform.system() == "Windows": - self.compiler = 'mingw32' - super().finalize_options() - - project_dir = os.path.dirname(os.path.abspath(__file__)) libtsfile_shard_dir = os.path.join(project_dir, "..", "cpp", "target", "build", "lib") @@ -79,9 +67,9 @@ def finalize_options(self): copy_header(source_include_dir, target_include_dir) if system == "Darwin": - copy_lib_files(libtsfile_shard_dir, libtsfile_dir, "1.0.dylib") + copy_lib_files(libtsfile_shard_dir, libtsfile_dir, version + ".dylib") elif system == "Linux": - copy_lib_files(libtsfile_shard_dir, libtsfile_dir, "so.1.0") + copy_lib_files(libtsfile_shard_dir, libtsfile_dir, "so." + version) else: copy_lib_files(libtsfile_shard_dir, libtsfile_dir, "dll") @@ -92,15 +80,31 @@ def finalize_options(self): libraries=["tsfile"], library_dirs=[libtsfile_dir], include_dirs=[include_dir, np.get_include()], - runtime_library_dirs=[libtsfile_dir] if platform.system() != "Windows" else None, - extra_compile_args=["-std=c++11"] if platform.system() != "Windows" else ["-std=c++11", "-DMS_WIN64"], + runtime_library_dirs=[libtsfile_dir] if system != "Windows" else None, + extra_compile_args=( + ["-std=c++11"] if system != "Windows" else ["-std=c++11", "-DMS_WIN64"] + ), language="c++", ) ] + +class BuildExt(build_ext): + def build_extensions(self): + numpy_include = np.get_include() + for ext in self.extensions: + ext.include_dirs.append(numpy_include) + super().build_extensions() + + def finalize_options(self): + if system == "Windows": + self.compiler = "mingw32" + super().finalize_options() + + setup( name="tsfile", - version="1.2.0.dev0", + version=version, description="Tsfile reader and writer for python", url="https://tsfile.apache.org", author='"Apache TsFile"',