Commit cc3e91c8 authored by Victor Yacovlev's avatar Victor Yacovlev

Initial rpm spec generation

parent 3f961adf
{
"unstablePackageSuffix": "-unstable",
"prefix": "%_prefix",
"cmake": "cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$RPM_BUILD_ROOT/%_prefix",
"make": "make -j 5",
"makeInstall": "make install",
"rpmBuildRoot": "$RPM_BUILD_ROOT",
"binDir": "%_bindir",
"libDir": "%_libdir",
"dataDir": "%_datadir",
"includesDir": "%_incdir",
"defAttr": "%defattr(-,root,root)",
"dirsOwnership": true,
"buildRequires": [
"python3",
"cmake >= 3.0",
"gcc-c++ >= 4.8",
"boost-devel >= 1.49",
"libqt5-qtbase-devel >= 5.3.0",
"libqt5-qtsvg-devel >= 5.3.0",
"libqt5-qtx11extras-devel >= 5.3.0"
],
"requires": [
"libQt5Core.so.5(Qt_5.3)",
"libQt5Gui.so.5(Qt_5.3)",
"libQt5Widgets.so.5(Qt_5.3)",
"libQt5Svg.so.5(Qt_5.3)",
"libQt5Xml.so.5(Qt_5.3)",
"libQt5Network.so.5(Qt_5.3)",
"libQt5PrintSupport.so.5(Qt_5.3)",
"libQt5WebKit.so.5(Qt_5.3)",
"libQt5X11Extras.so.5(Qt_5.3)"
],
"rpmGroup": "Productivity/Scientific/Other",
"commonUsedLibsPackage": {
"name": {
"prefix": "lib",
"suffix": ""
}
},
"toolsPackage": {
"name": {
"prefix": "",
"suffix": "-utils"
}
},
"develPackage": {
"name": {
"prefix": "",
"suffix": "-devel"
},
"cmakeFilesLocation": "%_libdir/cmake/Kumir2",
"develScriptsLocation": "%python3_sitelib"
}
}
\ No newline at end of file
import os
import sys
import json
from . import query_version_info
TEMPLATE = """# norootforbuild
Name: $name
Summary: Kumir education system $unstableNotice
License: GPL2+
Version: $version
Group: $rpmGroup
Release: $release
BuildRoot: %_tmppath/%name-%version
Vendor: NIISI RAS
URL: http://www.niisi.ru/kumir/
Packager: $packager
Source: $source
Requires: $kumirLibsPackageName = %version
Requires: /usr/bin/gtk-update-icon-cahce
Requires: /usr/bin/xdg-mime
Conflicts: $mainPackageConflictName
$buildRequires
%description
Kumir education system for schools
$unstableNotice
%prep
%setup -q
%build
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
popd
%install
pushd build
$makeInstall
popd
%clean
rm -rf $rpmBuildRoot
%files$mainFilesPrefs
$binDir/kumir2-ide
$binDir/kumir2-classic
$binDir/kumir2-highgrade
$binDir/kumir2-teacher
$binDir/kumir2-open
$binDir/kumir2-courseeditor
$dataDir/applications/kumir2-ide.desktop
$dataDir/icons/hicolor/*/apps/kumir2-ide.*
$dataDir/applications/kumir2-classic.desktop
$dataDir/icons/hicolor/*/apps/kumir2-classic.*
$dataDir/applications/kumir2-highgrade.desktop
$dataDir/icons/hicolor/*/apps/kumir2-highgrade.*
$dataDir/applications/kumir2-teacher.desktop
$dataDir/icons/hicolor/*/apps/teacher-highgrade.*
$datadir/icons/hicolor/*/mimetypes/*
$datadir/mime/packages/kumir2-mimetypes.xml
%post $name -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
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
/usr/bin/gtk-update-icon-cache -f $dataDir/icons/hicolor &>/dev/null || :
%package $kumirLibsPackageFullName
$requires
%description $kumirLibsPackageFullName
Common files for Kumir-2 platform
%files $kumirLibsPackageFullName$libsFilesPrefs
$libDir/kumir2/*.so
$libDir/kumir2/plugins/*.so
$dataDir/kumir2/*
%post $kumirLibsPackageFullName -p /sbin/ldconfig
%postun $kumirLibsPackageFullName -p /sbin/ldconfig
%package $kumirDevelPackageFullName
Requires: $kumirLibsPackageName = %version
$buildRequiresAsRequires
%description $kumirDevelPackageFullName
Development files to build new Actors and plugins for Kumir-2
%files $kumirDevelPackageFullName$develFilesPrefs
$includesDir/kumir2/*
$includesDir/kumir2-libs/*
$cmakeFilesLocation/*
$develScriptsLocation/gen_actor_source.py
%package $kumirToolsPackageFullName
Requires: $kumirLibsPackageName = %version
%description $kumirToolsPackageFullName
Kumir-2 tools for using in non-GUI mode
%files $kumirToolsPackageFullName
$binDir/kumir2-run
$binDir/kumir2-xrun
$binDir/kumir2-bc
$binDir/docbook2latex
$binDir/pictomir2course
%changelog
* Fri Apr 21 2017 - Kumir Team <kumir@lpm.org.ru>
- TODO: generate changelog from git log
"""
def render(template: str, substitutions: dict):
for key, value in substitutions:
template = template.replace(key, value)
return template
def read_conventions(dist: str):
file_name = "rpm-conventions.{}.json".format(dist.lower())
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)
def generate_rpm_spec_contents(dist: str, release: int, packager: str):
conventions = read_conventions(dist)
subst = {}
version_info = query_version_info.get_version_information(os.getcwd())
if version_info["taggedRelease"]:
subst["name"] = "kumir2"
subst["version"] = version_info["version"]
else:
subst["name"] = "kumir2-" + conventions["unstablePackageSuffix"]
subst["version"] = version_info["date"]
subst["release"] = str(release)
subst["package"] = packager
subst["rpmGroup"] = conventions["rpmGroup"]
def main():
out_file = sys.stdout
conventions = "openSUSE"
out_file_name = None
for arg in sys.argv:
if arg.startswith("--dist="):
conventions = arg[7:]
elif arg.startswith("--out="):
out_file_name = arg[6:]
if out_file_name:
out_file = open(out_file_name, "w")
data = generate_rpm_spec_contents(conventions)
out_file.write(data)
out_file.close()
if __name__ == "__main__":
main()
......@@ -8,6 +8,7 @@ import time
if 3 == sys.version_info.major:
from urllib.parse import unquote
def to_str(x):
assert isinstance(x, str) or isinstance(x, bytes)
if isinstance(x, str):
......@@ -17,6 +18,7 @@ if 3 == sys.version_info.major:
else:
from urllib import unquote
def to_str(x):
assert isinstance(x, str) or isinstance(x, unicode)
return unicode(x)
......@@ -63,36 +65,60 @@ for path_variant in GIT_PATH_SEARCH:
def get_version_information(top_level_dir):
assert isinstance(top_level_dir, str) or isinstance(top_level_dir, unicode)
result = {
"taggedRelease": True,
"version": None,
"hash": None,
"branch": None,
"date": None
}
if os.path.exists(top_level_dir + os.path.sep + ".git"):
try:
version_info = subprocess.check_output(
"git describe --abbrev=0 --tags --exact-match",
shell=True,
stderr=subprocess.PIPE
"git describe --abbrev=0 --tags --exact-match",
shell=True,
stderr=subprocess.PIPE
).strip()
result["version"] = version_info
except subprocess.CalledProcessError:
version_info = to_str(subprocess.check_output(
"git rev-parse --abbrev-ref HEAD",
shell=True
result["taggedRelease"] = False
branch_name = to_str(subprocess.check_output(
"git rev-parse --abbrev-ref HEAD",
shell=True
).strip())
version_info += "-" + to_str(subprocess.check_output(
"git --no-pager log -1 --pretty=format:%H",
shell=True
result["branch"] = branch_name
git_hash = to_str(subprocess.check_output(
"git --no-pager log -1 --pretty=format:%H",
shell=True
).strip())
result["hash"] = git_hash
result["date"] = get_date(top_level_dir)
else:
dir_name = os.path.basename(top_level_dir)
match = re.match(r"kumir2-(.+)", dir_name)
version_info = match.group(1)
return to_str(version_info)
if version_info.startswith("2"):
result["version"] = version_info
else:
result["taggedRelease"] = False
result["date"] = get_date(top_level_dir)
return result
def get_date(top_level_dir):
timestamp = int(get_timestamp(top_level_dir))
localtime = time.localtime(timestamp)
assert isinstance(localtime, time.struct_time)
return "{:04}{:02}{:02}".format(localtime.tm_year, localtime.tm_mon, localtime.tm_mday)
def get_timestamp(top_level_dir):
assert isinstance(top_level_dir, str) or isinstance(top_level_dir, unicode)
if os.path.exists(top_level_dir + os.path.sep + ".git"):
return to_str(subprocess.check_output(
"git --no-pager log -1 --pretty=format:%ct",
shell=True,
stderr=subprocess.PIPE
"git --no-pager log -1 --pretty=format:%ct",
shell=True,
stderr=subprocess.PIPE
)).strip()
else:
return "{}".format(int(time.time()))
......@@ -102,31 +128,28 @@ def is_tag(version):
return version.startswith("2")
def find_suitable_list_file_name(version_name):
def find_suitable_list_file_name(version_info):
base = os.getcwd() + os.path.sep + "subdirs-disabled-{}.txt"
name = base.format(version_name)
if version_info["taggedRelease"]:
name = base.format(version_info["version"])
else:
name = base.format(version_info["branch"])
if os.path.exists(name):
return name
match = re.match(r"(.+)-(alpha|beta|rc|pt|test)[0-9]+", version_name)
if match:
# some release version
if version_info["taggedRelease"]:
match = re.match(r"(.+)-(alpha|beta|rc|pt|test)[0-9]+", version_info["version"])
version_base = match.group(1)
else:
# branch version
match = re.match(r"(.+)-(.+)", version_name)
if match:
version_base = match.group(1)
else:
version_base = None
version_base = version_info["branch"]
if version_base:
name = base.format(version_base)
if os.path.exists(name):
return name
def cmake_disabled_modules():
version_name = get_version_information(os.getcwd())
disabled_list_file_name = find_suitable_list_file_name(version_name)
def disabled_modules():
version_info = get_version_information(os.getcwd())
disabled_list_file_name = find_suitable_list_file_name(version_info)
disabled_list = []
if disabled_list_file_name:
with open(disabled_list_file_name) as source:
......@@ -134,35 +157,42 @@ def cmake_disabled_modules():
for line in lines:
line = line.strip()
if line and not line.startswith("#"):
disabled_list += ["[" + line + "]"]
if disabled_list:
OUT_FILE.write(" ".join(disabled_list))
def _split_into_branch_and_hash(s):
assert isinstance(s, str)
index = s.rfind("-")
if -1==index:
return s, "unknown"
disabled_list += [line]
return disabled_list
def cmake_disabled_modules():
mods = ["[" + entry + "]" for entry in disabled_modules()]
if mods:
return " ".join(mods)
else:
return s[:index], s[index+1:]
return ""
def cmake_version_info():
version_name = get_version_information(os.getcwd())
assert isinstance(version_name, dict)
timestamp = get_timestamp(os.getcwd())
if is_tag(version_name):
OUT_FILE.write("-DGIT_TAG=\"{}\";".format(version_name))
OUT_FILE.write("-DGIT_BRANCH=\"unknown\";")
OUT_FILE.write("-DGIT_HASH=\"unknown\";")
output = ""
if version_name["taggedRelease"]:
output += "-DGIT_TAG=\"{}\";".format(version_name["version"])
output += "-DGIT_BRANCH=\"unknown\";"
output += "-DGIT_HASH=\"unknown\";"
else:
OUT_FILE.write("-DGIT_TAG=\"unknown\";")
branch, ghash = _split_into_branch_and_hash(version_name)
OUT_FILE.write("-DGIT_BRANCH=\"{}\";".format(branch))
OUT_FILE.write("-DGIT_HASH=\"{}\";".format(ghash))
OUT_FILE.write("-DGIT_TIMESTAMP=\"{}\";".format(timestamp))
output += "-DGIT_TAG=\"unknown\";"
output += "-DGIT_BRANCH=\"{}\";".format(version_name["branch"])
output += "-DGIT_HASH=\"{}\";".format(version_name["hash"])
output += "-DGIT_TIMESTAMP=\"{}\";".format(timestamp)
def package_bundle_name():
version_name = get_version_information(os.getcwd())
version_info = get_version_information(os.getcwd())
if version_info["taggedRelease"]:
version_name = version_info["version"]
else:
version_name = version_info["branch"] + "-"
version_name += version_info["hash"] + "-"
version_name += version_info["date"]
prefix = ""
suffix = ""
nl = ""
......@@ -177,28 +207,24 @@ def package_bundle_name():
else:
nl = "\n"
output = prefix + version_name + suffix + nl
OUT_FILE.write(output)
return output
def nsis_include_file():
version_name = get_version_information(os.getcwd())
version_info = get_version_information(os.getcwd())
data = ""
if is_tag(version_name):
data += "OutFile \"kumir2-"+version_name+"-install.exe\"\r\n"
data += "Name \"Кумир "+version_name+"\"\r\n"
data += "InstallDir \"$PROGRAMFILES\\Kumir-"+version_name+"\"\r\n"
data += "!define VERSION_SUFFIX \"" + version_name + "\"\r\n"
else:
branch, ghash = _split_into_branch_and_hash(version_name)
data += "OutFile \"kumir2-" + branch + "-" + ghash + "-install.exe\"\r\n"
data += "Name \"Кумир 2.x-" + branch + "\"\r\n"
data += "InstallDir \"$PROGRAMFILES\\Kumir2x-" + branch + "\"\r\n"
data += "!define VERSION_SUFFIX \"" + branch + "\"\r\n"
if sys.stdout==OUT_FILE:
OUT_FILE.write(data)
if version_info["taggedRelease"]:
data += "OutFile \"kumir2-" + version_info["version"] + "-install.exe\"\r\n"
data += "Name \"Кумир " + version_info["version"] + "\"\r\n"
data += "InstallDir \"$PROGRAMFILES\\Kumir-" + version_info["version"] + "\"\r\n"
data += "!define VERSION_SUFFIX \"" + version_info["version"] + "\"\r\n"
else:
OUT_FILE.write(data.encode("CP1251"))
data += "OutFile \"kumir2-" + version_info["branch"] + "-"
data += version_info["date"] + "-" + version_info["hash"] + "-install.exe\"\r\n"
data += "Name \"Кумир 2.x-" + version_info["branch"] + "\"\r\n"
data += "InstallDir \"$PROGRAMFILES\\Kumir2x-" + version_info["branch"] + "\"\r\n"
data += "!define VERSION_SUFFIX \"" + version_info["branch"] + "\"\r\n"
return data
def main():
......@@ -210,14 +236,19 @@ def main():
mode = arg[7:]
elif arg.startswith("--out="):
out_file_name = arg[6:]
custom_encoding = False
if out_file_name:
if mode.startswith("nsis"):
open_mode = "wb"
custom_encoding = "CP1251"
else:
open_mode = "w"
OUT_FILE = open(out_file_name, open_mode)
if mode in globals():
globals()[mode]()
data = globals()[mode]()
if custom_encoding:
data = data.encode(custom_encoding)
OUT_FILE.write(data)
OUT_FILE.close()
......
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