| 1 | # Copyright © 2023 Guillem Jover <guillem@debian.org> | ||||||||||||||||||||
| 2 | # | ||||||||||||||||||||
| 3 | # This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||
| 4 | # it under the terms of the GNU General Public License as published by | ||||||||||||||||||||
| 5 | # the Free Software Foundation; either version 2 of the License, or | ||||||||||||||||||||
| 6 | # (at your option) any later version. | ||||||||||||||||||||
| 7 | # | ||||||||||||||||||||
| 8 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||
| 11 | # GNU General Public License for more details. | ||||||||||||||||||||
| 12 | # | ||||||||||||||||||||
| 13 | # You should have received a copy of the GNU General Public License | ||||||||||||||||||||
| 14 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =encoding utf8 | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | =head1 NAME | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | Dpkg::BuildTree - handle build tree actions | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | The Dpkg::BuildTree module provides functions to handle build tree actions. | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | B<Note>: This is a private module, its API can change at any time. | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | =cut | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | package Dpkg::BuildTree 0.01; | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 1 | ▶ | use v5.36; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 1 | ▶ | use Cwd; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 1 | ▶ | use Dpkg::Source::Functions qw(erasedir); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | =head1 METHODS | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =over 4 | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | =item $bt = Dpkg::BuildTree->new(%opts) | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | Create a new Dpkg::BuildTree object. | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | Options: | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | =over 8 | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | =item B<dir> | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | The build tree directory. | ||||||||||||||||||||
| 53 | If not specified, it assumes the current working directory. | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | =back | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | =cut | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 1 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.3
Pod
documented
| |||||||||||||||||||||
| 60 | 1 | my ($this, %opts) = @_; | |||||||||||||||||||
| 61 | 1 | ▶ | my $class = ref($this) || $this; | ||||||||||||||||||
|
Condition33%1/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table33%1/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | my $self = { | ||||||||||||||||||||
| 64 | 1 | ▶ | buildtree => $opts{dir} || getcwd(), | ||||||||||||||||||
|
Condition33%1/3
$opts{'dir'} || getcwd()
MC/DC0%0/2
$opts{'dir'} || getcwd()
$opts{'dir'}
getcwd()
Truth table33%1/3
A || B
A= $opts{'dir'}B= getcwd()
| |||||||||||||||||||||
| 65 | }; | ||||||||||||||||||||
| 66 | 1 | bless $self, $class; | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 1 | return $self; | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | =item $bt->clean() | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | Clean the build tree, by removing any dpkg generated artifacts. | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | =cut | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 1 | ▶ | sub clean { | ||||||||||||||||||
|
Subroutine
clean: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||
| 78 | 1 | my $self = shift; | |||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 1 | my $buildtree = $self->{buildtree}; | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | # If this does not look like a build tree, do nothing. | ||||||||||||||||||||
| 83 | 1 | ▶ | return unless -f "$buildtree/debian/control"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 1 | my @files = qw( | |||||||||||||||||||
| 86 | debian/files | ||||||||||||||||||||
| 87 | debian/files.new | ||||||||||||||||||||
| 88 | debian/substvars | ||||||||||||||||||||
| 89 | debian/substvars.new | ||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||
| 91 | 1 | my @dirs = qw( | |||||||||||||||||||
| 92 | debian/tmp | ||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 1 | foreach my $file (@files) { | |||||||||||||||||||
| 96 | 4 | unlink "$buildtree/$file"; | |||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | 1 | foreach my $dir (@dirs) { | |||||||||||||||||||
| 99 | 1 | erasedir("$buildtree/$dir"); | |||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 1 | return; | |||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | =item $bool = $bt->needs_root() | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | Check whether the build tree needs root to build. | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | =cut | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 0 | ▶ | sub needs_root { | ||||||||||||||||||
|
Subroutine
needs_root: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 112 | 0 | my $self = shift; | |||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 0 | require Dpkg::Control::Info; | |||||||||||||||||||
| 115 | 0 | require Dpkg::BuildDriver; | |||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 0 | my $ctrl = Dpkg::Control::Info->new(); | |||||||||||||||||||
| 118 | 0 | my $bd = Dpkg::BuildDriver->new(ctrl => $ctrl); | |||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | return $bd->need_build_task('build', 'binary') || | ||||||||||||||||||||
| 121 | 0 | ▶ | defined $ENV{DEB_GAIN_ROOT_CMD}; | ||||||||||||||||||
|
Condition0%0/3
$bd->need_build_task('build', 'binary') || defined $ENV{'DEB_GAIN_ROOT_CMD'}
MC/DC0%0/2
$bd->need_build_task('build', 'binary') || defined $ENV{'DEB_GAIN_ROOT_CMD'}
$bd->need_build_task('build', 'binary')
defined $ENV{'DEB_GAIN_ROOT_CMD'}
Truth table0%0/3
A || B
A= $bd->need_build_task('build', 'binary')B= defined $ENV{'DEB_GAIN_ROOT_CMD'}
| |||||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | =back | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | =head1 CHANGES | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | =head2 Version 0.xx | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | This is a private module. | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | =cut | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | 1 | 1; | |||||||||||||||||||