# 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 . # # =*= License: GPL-3+ =*= import os import icklib class CreateCIDebianBinaryPackages(icklib.BuildStep): def build(self): if not self.run_state.build_using_debian_ci: return self.run_state.progress['step'] = 'Creating debs' self.run_state.logger.important('Creating debs') with self.run_state.logger: archs = self._get_architectures_from_source( self.run_state.clones[0]) arch_all_built = set() for target in self.targets: 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) cleanly_options = [ '--results', remote_artifacts_dir, '--pbuilder-tgz', target.pbuilder_ci_tgz, '--ci', '--buildno', str(self.run_state.build_info.build_number), '--debian-release', target.debian_release, '--debian-codename', target.debian_codename, ] build_it = True if 'all' in archs: if target.debian_codename not in arch_all_built: cleanly_options += ['--build-arch-all-also'] arch_all_built.add(target.debian_codename) elif archs == ['all']: build_it = False if build_it: self.project.run_cleanly( target, remote_git_dir, cleanly_path, cleanly_options + ['deb']) target.sync_from_target( remote_artifacts_dir, self.run_state.build_info.create_artifacts_directory()) target.remove_all([remote_tmp]) def _get_architectures_from_source(self, clone): archs = set() control = os.path.join(clone.dirname, 'debian', 'control') with open(control) as f: for line in f: if line.startswith('Architecture: '): for arch in line.split()[1:]: archs.add(arch) return list(archs) class CreateDebianBinaryPackagesForRelease(icklib.BuildStep): def build(self): for tag in self.run_state.build_tags_using_debian_release: self.run_state.progress['what'] = ( 'Building debs for release {}'.format(tag)) self.run_state.logger.important( 'Building debs for release {tag}', tag=tag) with self.run_state.logger: self.run_state.clones[0].checkout(tag) archs = self._get_architectures_from_source( self.run_state.clones[0]) arch_all_built = set() for target in self.targets: 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) cleanly_options = [ '--results', remote_artifacts_dir, '--pbuilder-tgz', target.pbuilder_ci_tgz, '--release', '--buildno', str(self.run_state.build_info.build_number), '--debian-release', target.debian_release, '--debian-codename', target.debian_codename, ] build_it = True if 'all' in archs: if target.debian_codename not in arch_all_built: cleanly_options += ['--build-arch-all-also'] arch_all_built.add(target.debian_codename) elif archs == ['all']: build_it = False if build_it: self.project.run_cleanly( target, remote_git_dir, cleanly_path, cleanly_options + ['deb']) build_info = self.run_state.build_info target.sync_from_target( remote_artifacts_dir, build_info.create_artifacts_directory()) target.remove_all([remote_tmp]) def _get_architectures_from_source(self, clone): archs = set() control = os.path.join(clone.dirname, 'debian', 'control') with open(control) as f: for line in f: if line.startswith('Architecture: '): for arch in line.split()[1:]: archs.add(arch) return list(archs)