summaryrefslogtreecommitdiff
path: root/bump-build-dep-versions
blob: cb5d633fce57dfb6d5e624efbd2ea3a09a3ffdf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/python3
# kate: space-indent on; indent-width 4; replace-tabs on; indent-mode python; remove-trailing-space modified;
# vim: expandtab ts=4

############################################################################
#   Copyright © 2015 Jonathan Riddell                                      #
#   Copyright © 2015-2016 José Manuel Santamaría Lema <panfaust@gmail.com> #
#                                                                          #
#   This program is free software; you can redistribute it and/or modify   #
#   it under the terms of the GNU General Public License as published by   #
#   the Free Software Foundation; either version 2 of the License, or      #
#   (at your option) any later version.                                    #
############################################################################

# script to bump build-dep versions in KDE packaging
# run in directory with debian/control file

import argparse
import os
import sys
import re
import subprocess
import json
import warnings

from libka.control_edit import *
from libka.ka_data_utils import *


def bump_build_depends(releasetype, dist):
    #Open the build depends map
    build_depends_map_file = "dev-package-name-lists/%s-%s.json" % (releasetype, dist)
    try:
        build_depends_map = readJsonDataFile(build_depends_map_file,catch_exceptions=False)
    except FileNotFoundError:
        print("Build depends map file path:")
        print(getDataFilesPath()+build_depends_map_file)
        print("Build depends map file not found, aborting.")
        print("You can update the build depends map file with ka-update-metadata -d <distribution> -r <releasetype>")
        sys.exit(1)

    #Open the overrides file if exists
    overrides_file = "dev-package-name-lists/%s-%s-overrides.json" % (releasetype, dist)
    try:
        overrides_map = readJsonDataFile(overrides_file,catch_exceptions=False)
    except FileNotFoundError:
        overrides_map = {}

    #Add the overrides to the build depends map
    build_depends_map.update(overrides_map)

    #Sanitize the control file
    sanitize_control_file('./debian/control')

    #Open the control file
    src_pkg, bin_pkg_list, bin_pkg_map = parse_control('./debian/control');

    warnings.simplefilter('ignore', UserWarning) #Ignore the warnings from python-debian
    warnings.simplefilter('ignore', FutureWarning) #Ignore the warnings from python-debian

    #Bump the build depends using the map from the json file
    bump_version_with_map(src_pkg, 'Build-Depends', build_depends_map)
    if 'Build-Depends-Indep' in src_pkg:
	    bump_version_with_map(src_pkg, 'Build-Depends-Indep', build_depends_map)

    #Bump the depends of the -dev packages as well
    for bin_pkg_name in bin_pkg_list:
        if bin_pkg_name in build_depends_map:
            bin_pkg_to_change = bin_pkg_map[bin_pkg_name]
            if 'Depends' in bin_pkg_to_change:
                bump_version_with_map(bin_pkg_to_change, 'Depends', build_depends_map)

    warnings.simplefilter('default', FutureWarning) #Reset the future warnings
    warnings.simplefilter('default', UserWarning) #Reset the user warnings

    #Dump the contents of the control file
    dump_control('./debian/control',src_pkg, bin_pkg_list, bin_pkg_map)

if __name__ == "__main__":
    #Find out the default distribution
    ka_config = getConfigParser()
    default_dist = ka_config['global']['ubuntu-unstable-name']

    parser = argparse.ArgumentParser(description="This script must be executed inside a package directory "
        "with debian/* files. It bumps all the build dependencies of frameworks/plasma/applications.")
    parser.add_argument("-d", "--dist", required=False, default=default_dist, help="Distribution name")
    parser.add_argument("-r", "--releasetype", required=True, help="Type [frameworks,plasma,applications]")

    #FIXME: Remove these, they are there for compatibility
    parser.add_argument("-v", "--version", required=False, help="Upstream version")

    args = parser.parse_args()

    bump_build_depends(args.releasetype, args.dist)
    #Print the git diff
    print("=== bump-build-dep-versions diff start")
    subprocess.check_call(["git", "--no-pager", "diff"])
    print("=== bump-build-dep-versions diff end")