Commit f7e6c2ed authored by Victor Yacovlev's avatar Victor Yacovlev

RPM CMakeLists fixes

parent cc3e91c8
{
"unstablePackageSuffix": "-unstable",
"prefix": "%_prefix",
"cmake": "cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$RPM_BUILD_ROOT/%_prefix",
"make": "make -j 5",
"makeInstall": "make install",
"installPrefix": "%_prefix",
"cmakeCommand": "cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$rpmBuildRoot/%_prefix",
"makeCommand": "make -j",
"makeInstallCommand": "make install",
"rpmBuildRoot": "$RPM_BUILD_ROOT",
"binDir": "%_bindir",
"libDir": "%_libdir",
......@@ -11,12 +11,13 @@
"includesDir": "%_incdir",
"defAttr": "%defattr(-,root,root)",
"dirsOwnership": true,
"useBundledBoost": false,
"buildRequires": [
"python3",
"cmake >= 3.0",
"gcc-c++ >= 4.8",
"boost-devel >= 1.49",
"boost-devel >= 1.54",
"libqt5-qtbase-devel >= 5.3.0",
"libqt5-qtsvg-devel >= 5.3.0",
"libqt5-qtx11extras-devel >= 5.3.0"
......
import functools
import os
import sys
import json
from . import query_version_info
import query_version_info
TEMPLATE = """# norootforbuild
Name: $name
......@@ -20,31 +21,44 @@ Requires: $kumirLibsPackageName = %version
Requires: /usr/bin/gtk-update-icon-cahce
Requires: /usr/bin/xdg-mime
Conflicts: $mainPackageConflictName
$buildRequires
$buildRequiresList
%description
Kumir education system for schools
$unstableNotice
%prep
%setup -q
%setup -q -n $archivePrefix
%build
$removeBundledBoostIfNeed
mkdir build
pushd build
$cmake -DUSE_QT=5 -DKUMIR2_SDK_CMAKE_DIR=$RPM_BUILD_ROOT/$cmakeFilesLocation -DKUMIR2_SDK_SCRIPTS_DIR=$RPM_BUILD_ROOT/$develScriptsLocation ../
$make
$cmakeCommand \
-DUSE_QT=5 \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-DKUMIR2_REAL_PREFIX=$installPrefix \
-DKUMIR2_SDK_CMAKE_DIR=$rpmBuildRoot/$cmakeFilesLocation \
-DKUMIR2_SDK_SCRIPTS_DIR=$RPM_BUILD_ROOT/$develScriptsLocation \
-DPROVIDED_VERSION_INFO:BOOL=ON \
-DGIT_TAG="$gitTag" \
-DGIT_BRANCH="$gitBranch" \
-DGIT_HASH="$gitHash" \
-DGIT_TIMESTAMP="$gitTimestamp" \
../
$makeCommand
popd
%install
pushd build
$makeInstall
$makeInstallCommand
popd
%clean
rm -rf $rpmBuildRoot
%files$mainFilesPrefs
%files
$mainFilesPrefs
$binDir/kumir2-ide
$binDir/kumir2-classic
$binDir/kumir2-highgrade
......@@ -63,26 +77,30 @@ $datadir/icons/hicolor/*/mimetypes/*
$datadir/mime/packages/kumir2-mimetypes.xml
%post $name -p /sbin/ldconfig
%post -p /sbin/ldconfig
/bin/touch --no-create $dataDir/icons/hicolor/ &>/dev/null || :
xdg-menu install $dataDir/mime/packages/kumir2-mimetypes.xml || true
%postun $name -p /sbin/ldconfig
%postun -p /sbin/ldconfig
if [ $1 -eq 0 ] ; then
/bin/touch --no-create $dataDir/icons/hicolor/ &>/dev/null
/usr/bin/gtk-update-icon-cache -f $dataDir/icons/hicolor/ &>/dev/null || :
fi
%posttrans $name
%posttrans
/usr/bin/gtk-update-icon-cache -f $dataDir/icons/hicolor &>/dev/null || :
%package $kumirLibsPackageFullName
$requires
Summary: Common files for all Kumir-2 components
Conflicts: $libsPackageConflictName
$requiresList
%description $kumirLibsPackageFullName
Common files for Kumir-2 platform
$unstableNotice
%files $kumirLibsPackageFullName$libsFilesPrefs
%files $kumirLibsPackageFullName
$libsFilesPrefs
$libDir/kumir2/*.so
$libDir/kumir2/plugins/*.so
$dataDir/kumir2/*
......@@ -91,13 +109,17 @@ $dataDir/kumir2/*
%postun $kumirLibsPackageFullName -p /sbin/ldconfig
%package $kumirDevelPackageFullName
Requires: $kumirLibsPackageName = %version
$buildRequiresAsRequires
Summary: Kumir-2 development files
Requires: $kumirLibsPackageName = %version
Conflicts: $develPackageConflictName
$buildRequiresAsRequiresList
%description $kumirDevelPackageFullName
Development files to build new Actors and plugins for Kumir-2
$unstableNotice
%files $kumirDevelPackageFullName$develFilesPrefs
%files $kumirDevelPackageFullName
$develFilesPrefs
$includesDir/kumir2/*
$includesDir/kumir2-libs/*
$cmakeFilesLocation/*
......@@ -105,12 +127,16 @@ $develScriptsLocation/gen_actor_source.py
%package $kumirToolsPackageFullName
Requires: $kumirLibsPackageName = %version
Summary: Kumir-2 non-GUI tools
Requires: $kumirLibsPackageName = %version
Conflicts: $toolsPackageConflictName
%description $kumirToolsPackageFullName
Kumir-2 tools for using in non-GUI mode
$unstableNotice
%files $kumirToolsPackageFullName
$toolsFilesPrefs
$binDir/kumir2-run
$binDir/kumir2-xrun
$binDir/kumir2-bc
......@@ -125,8 +151,11 @@ $binDir/pictomir2course
def render(template: str, substitutions: dict):
for key, value in substitutions:
template = template.replace(key, value)
keys = substitutions.keys()
sorted_keys = sorted(keys, key=len, reverse=True)
for key in sorted_keys:
value = substitutions[key]
template = template.replace("$"+key, value)
return template
......@@ -135,38 +164,137 @@ def read_conventions(dist: str):
if not os.path.exists(file_name):
sys.stderr.write("Warning: No RPM conventions for {}. Using openSUSE\n".format(dist))
file_name = "rpm-conventions.opensuse.json"
with open(file_name, "r"):
return json.read(file_name)
with open(file_name, "r") as f:
return json.load(f)
def generate_rpm_spec_contents(dist: str, release: int, packager: str):
conventions = read_conventions(dist)
lib_prefix = conventions["commonUsedLibsPackage"]["name"]["prefix"]
lib_suffix = conventions["commonUsedLibsPackage"]["name"]["suffix"]
dev_prefix = conventions["develPackage"]["name"]["prefix"]
dev_suffix = conventions["develPackage"]["name"]["suffix"]
tools_prefix = conventions["toolsPackage"]["name"]["prefix"]
tools_suffix = conventions["toolsPackage"]["name"]["suffix"]
unstable_suffix = conventions["unstablePackageSuffix"]
subst = {}
version_info = query_version_info.get_version_information(os.getcwd())
timestamp = query_version_info.get_timestamp(os.getcwd())
subst["gitTimestamp"] = str(timestamp)
if version_info["taggedRelease"]:
subst["name"] = "kumir2"
subst["version"] = version_info["version"]
subst["unstableNotice"] = ""
subst["mainPackageConflictName"] = "kumir2" + unstable_suffix
subst["libsPackageConflictName"] = lib_prefix + "kumir2" + unstable_suffix + lib_suffix
subst["develPackageConflictName"] = dev_prefix + "kumir2" + unstable_suffix + dev_suffix
subst["toolsPackageConflictName"] = tools_prefix + "kumir2" + unstable_suffix + tools_suffix
subst["archivePrefix"] = "kumir2-" + version_info["version"]
subst["gitTag"] = version_info["version"]
subst["gitHash"] = "unknown"
subst["gitBranch"] = "unknown"
else:
subst["name"] = "kumir2-" + conventions["unstablePackageSuffix"]
subst["name"] = "kumir2" + unstable_suffix
subst["version"] = version_info["date"]
subst["unstableNotice"] = "(Nightly *unstable* builds)"
subst["mainPackageConflictName"] = "kumir2"
subst["libsPackageConflictName"] = lib_prefix + "kumir2" + lib_suffix
subst["develPackageConflictName"] = dev_prefix + "kumir2" + dev_suffix
subst["toolsPackageConflictName"] = tools_prefix + "kumir2" + tools_suffix
subst["archivePrefix"] = "kumir2-" + version_info["branch"] + "-"+ version_info["hash"] + "-" + version_info["date"]
subst["gitTag"] = "unknown"
subst["gitHash"] = version_info["hash"]
subst["gitBranch"] = version_info["branch"]
subst["kumirLibsPackageName"] = lib_prefix + subst["name"] + lib_suffix
if lib_prefix:
subst["kumirLibsPackageFullName"] = "-n " + subst["kumirLibsPackageName"]
else:
subst["kumirLibsPackageFullName"] = lib_suffix[1:]
if dev_prefix:
subst["kumirDevelPackageFullName"] = "-n " + dev_prefix + subst["name"] + dev_suffix
else:
subst["kumirDevelPackageFullName"] = dev_suffix[1:]
if tools_prefix:
subst["kumirToolsPackageFullName"] = "-n " + tools_prefix + subst["name"] + tools_suffix
else:
subst["kumirToolsPackageFullName"] = tools_suffix[1:]
subst["release"] = str(release)
subst["package"] = packager
subst["packager"] = packager
subst["rpmGroup"] = conventions["rpmGroup"]
subst["source"] = query_version_info.source_file_name("kumir2-", ".tar.gz")
subst["cmakeCommand"] = conventions["cmakeCommand"]
subst["makeCommand"] = conventions["makeCommand"]
subst["makeInstallCommand"] = conventions["makeInstallCommand"]
subst["rpmBuildRoot"] = conventions["rpmBuildRoot"]
subst["installPrefix"] = conventions["installPrefix"]
subst["binDir"] = conventions["binDir"]
subst["libDir"] = conventions["libDir"]
subst["dataDir"] = conventions["dataDir"]
subst["includesDir"] = conventions["includesDir"]
subst["rpmBuildRoot"] = conventions["rpmBuildRoot"]
subst["mainFilesPrefs"] = conventions["defAttr"]
subst["libsFilesPrefs"] = conventions["defAttr"]
subst["develFilesPrefs"] = conventions["defAttr"]
subst["toolsFilesPrefs"] = conventions["defAttr"]
if not conventions["useBundledBoost"]:
subst["removeBundledBoostIfNeed"] = "rm -rf src/3rdparty/boost*"
else:
subst["removeBundledBoostIfNeed"] = ""
if conventions["dirsOwnership"]:
subst["mainFilesPrefs"] += "\n%dir $binDir"
subst["mainFilesPrefs"] += "\n%dir $dataDir/applications"
subst["mainFilesPrefs"] += "\n%dir $dataDir/icons/hicolor/*/apps"
subst["mainFilesPrefs"] += "\n%dir $dataDir/mime/packages"
subst["libsFilesPrefs"] += "\n%dir $libDir/kumir2"
subst["libsFilesPrefs"] += "\n%dir $libDir/kumir2/plugins"
subst["libsFilesPrefs"] += "\n%dir $dataDir/kumir2"
subst["develFilesPrefs"] += "\n%dir $includesDir/kumir2"
subst["develFilesPrefs"] += "\n%dir $includesDir/kumir2-libs"
subst["develFilesPrefs"] += "\n%dir $cmakeFilesLocation"
subst["develFilesPrefs"] += "\n%dir $develScriptsLocation"
subst["toolsFilesPrefs"] += "\n%dir $binDir"
subst["requiresList"] = "\n".join(["Requires:\t"+entry for entry in conventions["requires"]])
subst["buildRequiresList"] = "\n".join(["BuildRequires:\t" + entry for entry in conventions["buildRequires"]])
subst["buildRequiresAsRequiresList"] = "\n".join(["Requires:\t" + entry for entry in conventions["buildRequires"]])
subst["cmakeFilesLocation"] = conventions["develPackage"]["cmakeFilesLocation"]
subst["develScriptsLocation"] = conventions["develPackage"]["develScriptsLocation"]
data = TEMPLATE
for i in range(0, 3):
data = render(data, subst)
return data
def main():
out_file = sys.stdout
conventions = "openSUSE"
release = 1
out_file_name = None
packager = "Anonymous <anon@example.com>"
for arg in sys.argv:
if arg.startswith("--dist="):
conventions = arg[7:]
elif arg.startswith("--out="):
out_file_name = arg[6:]
elif arg.startswith("--release="):
release = int(arg[10:])
elif arg.startswith("--packager="):
packager = arg[11:]
if packager.startswith('"') and packager.endswith('"'):
packager = packager[1:-1]
if packager.startswith("'") and packager.endswith("'"):
packager = packager[1:-1]
if out_file_name:
out_file = open(out_file_name, "w")
data = generate_rpm_spec_contents(conventions)
data = generate_rpm_spec_contents(conventions, release, packager)
out_file.write(data)
out_file.close()
......
......@@ -185,7 +185,7 @@ def cmake_version_info():
output += "-DGIT_TIMESTAMP=\"{}\";".format(timestamp)
def package_bundle_name():
def source_file_name(prefix: str, suffix: str):
version_info = get_version_information(os.getcwd())
if version_info["taggedRelease"]:
version_name = version_info["version"]
......@@ -193,6 +193,10 @@ def package_bundle_name():
version_name = version_info["branch"] + "-"
version_name += version_info["hash"] + "-"
version_name += version_info["date"]
return prefix + version_name + suffix
def package_bundle_name():
prefix = ""
suffix = ""
nl = ""
......@@ -206,7 +210,7 @@ def package_bundle_name():
nl = "\r\n"
else:
nl = "\n"
output = prefix + version_name + suffix + nl
output = source_file_name(prefix, suffix) + nl
return output
......
......@@ -3,13 +3,25 @@ find_package(Kumir2 REQUIRED)
# Query for version info and pass it as compile definitions
if(EXISTS "${CMAKE_SOURCE_DIR}/version_info.cmake")
message(STATUS "Found explicit version info")
include(${CMAKE_SOURCE_DIR}/version_info.cmake)
add_definitions(-DGIT_HASH=\"${GIT_HASH}\")
add_definitions(-DGIT_TIMESTAMP=\"${GIT_TIMESTAMP}\")
add_definitions(-DGIT_TAG=\"${GIT_TAG}\")
add_definitions(-DGIT_BRANCH=\"${GIT_BRANCH}\")
message(STATUS "File-provided version info: HASH=${GIT_HASH}")
message(STATUS "File-provided version info: TIMESTAMP=${GIT_TIMESTAMP}")
message(STATUS "File-provided version info: TAG=${GIT_TAG}")
message(STATUS "File-provided version info: BRANCH=${GIT_BRANCH}")
elseif(PROVIDED_VERSION_INFO)
add_definitions(-DGIT_HASH=\"${GIT_HASH}\")
add_definitions(-DGIT_TIMESTAMP=\"${GIT_TIMESTAMP}\")
add_definitions(-DGIT_TAG=\"${GIT_TAG}\")
add_definitions(-DGIT_BRANCH=\"${GIT_BRANCH}\")
message(STATUS "Variable-provided version info: HASH=${GIT_HASH}")
message(STATUS "Variable-provided version info: TIMESTAMP=${GIT_TIMESTAMP}")
message(STATUS "Variable-provided version info: TAG=${GIT_TAG}")
message(STATUS "Variable-provided version info: BRANCH=${GIT_BRANCH}")
else()
execute_process(
COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_SOURCE_DIR}/scripts/query_version_info.py" "--mode=cmake_version_info"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment