Skip to content

Commit

Permalink
Auto update cpp&py project version when build with maven
Browse files Browse the repository at this point in the history
  • Loading branch information
HTHou committed Nov 19, 2024
1 parent 84fd5fe commit 076448e
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 49 deletions.
5 changes: 2 additions & 3 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions cpp/VersionUpdater.groovy
Original file line number Diff line number Diff line change
@@ -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"
}
50 changes: 25 additions & 25 deletions cpp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
<packaging>pom</packaging>
<name>TsFile: C++</name>
<properties>
<groovy.version>4.0.22</groovy.version>
<!-- Tell Sonar where to find the sources -->
<sonar.sources>common,examples,tsfile</sonar.sources>
<sonar.cfamily.build-wrapper-output>${project.build.directory}/build-wrapper-output</sonar.cfamily.build-wrapper-output>
Expand Down Expand Up @@ -120,6 +119,31 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.1.1</version>
<executions>
<!-- rename the cmake binary and generate a script that adds the sonar build-wrapper -->
<execution>
<id>sync-project-version</id>
<phase>process-sources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>${project.basedir}/VersionUpdater.groovy</source>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy</artifactId>
<version>${groovy.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<profiles>
Expand Down Expand Up @@ -159,30 +183,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<executions>
<!-- rename the cmake binary and generate a script that adds the sonar build-wrapper -->
<execution>
<id>modify-cmake</id>
<phase>process-test-sources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>${project.basedir}/SonarcloudBuildWrapperHack.groovy</source>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy</artifactId>
<version>${groovy.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<spotless.version>2.43.0</spotless.version>
<google.java.format.version>1.22.0</google.java.format.version>
<drill.freemarker.maven.plugin.version>1.21.1</drill.freemarker.maven.plugin.version>
<groovy.version>4.0.22</groovy.version>
</properties>
<build>
<pluginManagement>
Expand Down
41 changes: 41 additions & 0 deletions python/VersionUpdater.groovy
Original file line number Diff line number Diff line change
@@ -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"
}
26 changes: 25 additions & 1 deletion python/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
<name>TsFile: Python</name>
<properties>
<unity.version>2.6.0</unity.version>
<groovy.version>4.0.21</groovy.version>
<!-- Tell Sonar where to find the sources -->
<sonar.sources>tsfile</sonar.sources>
<sonar.cfamily.build-wrapper-output>${project.build.directory}/build-wrapper-output</sonar.cfamily.build-wrapper-output>
Expand Down Expand Up @@ -177,6 +176,31 @@
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.1.1</version>
<executions>
<!-- rename the cmake binary and generate a script that adds the sonar build-wrapper -->
<execution>
<id>sync-project-version</id>
<phase>process-sources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>${project.basedir}/VersionUpdater.groovy</source>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy</artifactId>
<version>${groovy.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
40 changes: 22 additions & 18 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import shutil
import os

version = "1.2.0.dev"
system = platform.system()


Expand Down Expand Up @@ -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")
Expand All @@ -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")

Expand All @@ -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"',
Expand Down

0 comments on commit 076448e

Please sign in to comment.