summaryrefslogtreecommitdiff
path: root/icklib/step_debian_source.py
blob: 72407cf75a8df33d7366389fc3621744765373a0 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# Copyright 2016  Lars Wirzenius
#
# 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 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# =*= License: GPL-3+ =*=


import icklib


class CreateDebianSourcePackagesForCI(icklib.BuildStep):

    def build(self):
        if not self.run_state.build_using_debian_ci:
            return

        dsc_targets = []
        codenames = set()
        for target in self.targets:
            if target.debian_codename not in codenames:
                dsc_targets.append(target)
                codenames.add(target.debian_codename)

        for target in dsc_targets:
            self.run_state.progress['step'] = (
                'Create dsc for {}'.format(target.debian_codename))
            self.run_state.logger.important(
                'Creating dsc for {codename}',
                codename=target.debian_codename)
            with self.run_state.logger:
                remote_tmp = target.mkdtemp()
                remote_git_dir = target.sync_to_target(
                    self.run_state.clones[0].dirname, remote_tmp, 'git')
                remote_artifacts_dir = target.sync_to_target(
                    self.run_state.build_info.create_artifacts_directory(),
                    remote_tmp, 'artifacts')

                cleanly_path = self.project.copy_cleanly_to_target(
                    target, remote_tmp)
                self.project.run_cleanly(
                    target, remote_git_dir, cleanly_path,
                    ['--results', remote_artifacts_dir,
                     '--ci',
                     '--buildno', str(self.run_state.build_info.build_number),
                     '--debian-release', target.debian_release,
                     '--debian-codename', target.debian_codename,
                     'dsc'])

                target.sync_from_target(
                    remote_artifacts_dir,
                    self.run_state.build_info.create_artifacts_directory())

                target.remove_all([remote_tmp])


class CreateDebianSourcePackagesForRelease(icklib.BuildStep):

    def build(self):
        if not self.run_state.build_tags_using_debian_release:
            return

        dsc_targets = self._get_dsc_targets(self.targets)
        for tag in self.run_state.build_tags_using_debian_release:
            for target in dsc_targets:
                self.run_state.progress['step'] = (
                    'Create dsc for {} for tag {}'.format(
                        target.debian_codename, tag))
                self.run_state.logger.important(
                    'Creating dsc for {codename} for tag {tag}',
                    codename=target.debian_codename,
                    tag=tag)
                with self.run_state.logger:
                    remote_tmp = target.mkdtemp()
                    self.run_state.clones[0].checkout(tag)
                    remote_git_dir = target.sync_to_target(
                        self.run_state.clones[0].dirname, remote_tmp, 'git')
                    remote_artifacts_dir = target.sync_to_target(
                        self.run_state.build_info.create_artifacts_directory(),
                        remote_tmp, 'artifacts')

                    cleanly_path = self.project.copy_cleanly_to_target(
                        target, remote_tmp)
                    self.project.run_cleanly(
                        target, remote_git_dir, cleanly_path,
                        ['--results', remote_artifacts_dir,
                         '--release',
                         '--buildno',
                         str(self.run_state.build_info.build_number),
                         '--debian-release', target.debian_release,
                         '--debian-codename', target.debian_codename,
                         'dsc'])

                    target.sync_from_target(
                        remote_artifacts_dir,
                        self.run_state.build_info.create_artifacts_directory())

                    target.remove_all([remote_tmp])

    def _get_dsc_targets(self, targets):
        dsc_targets = []
        codenames = set()
        for target in targets:
            if target.debian_codename not in codenames:
                dsc_targets.append(target)
                codenames.add(target.debian_codename)
        return dsc_targets