~ubuntu-branches/ubuntu/karmic/debhelper/karmic

« back to all changes in this revision

Viewing changes to Debian/Debhelper/Dh_Lib.pm

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-04-24 19:22:46 UTC
  • Revision ID: james.westby@ubuntu.com-20090424192246-ytzyl3azu8bosewc
Tags: 7.2.8ubuntu1
* Merge with Debian unstable. Remaining Ubuntu changes:
  - dh_installudev: Default priority is now 40 by default, the target
    directory is /lib/udev/rules.d, and rules use '-' as separator instead of
    '_'.  Remove files from /etc/udev/rules.d unless they are user modified;
    if modified and of default priority, take care to rename.
    This should eventually go to Debian as well, see Debian #491117.
  - dh_auto_install: add "--install-layout=deb" to setup.py install calls
    (new Python 2.6 policy).
* dh_installxfonts: Drop versioned dependency for xfonts-utils. This
  was only necessary for dapper backports, but since dapper desktop goes
  EOL in two months, and we haven't done dapper backports in ages, this is
  just an unnecessary delta.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
            &filedoublearray &getpackages &basename &dirname &xargs %dh
16
16
            &compat &addsubstvar &delsubstvar &excludefile &package_arch
17
17
            &is_udeb &udeb_filename &debhelper_script_subst &escape_shell
18
 
            &inhibit_log);
 
18
            &inhibit_log &load_log &write_log);
19
19
 
20
20
my $max_compat=7;
21
21
 
22
22
sub init {
23
 
        # If DH_OPTIONS is set, prepend it @ARGV.
24
 
        if (defined($ENV{DH_OPTIONS})) {
25
 
                # Ignore leading/trailing whitespace.
26
 
                $ENV{DH_OPTIONS}=~s/^\s+//;
27
 
                $ENV{DH_OPTIONS}=~s/\s+$//;
28
 
                unshift @ARGV,split(/\s+/,$ENV{DH_OPTIONS});
29
 
        }
 
23
        my %params=@_;
30
24
 
31
 
        # Check to see if an argument on the command line starts with a dash.
32
 
        # if so, we need to pass this off to the resource intensive 
 
25
        # Check to see if an option line starts with a dash,
 
26
        # or DH_OPTIONS is set.
 
27
        # If so, we need to pass this off to the resource intensive 
33
28
        # Getopt::Long, which I'd prefer to avoid loading at all if possible.
34
 
        my $parseopt=undef;
35
 
        my $arg;
36
 
        foreach $arg (@ARGV) {
37
 
                if ($arg=~m/^-/) {
38
 
                        $parseopt=1;
39
 
                        last;
40
 
                }       
41
 
        }
42
 
        if ($parseopt) {
 
29
        if ((defined $ENV{DH_OPTIONS} && length $ENV{DH_OPTIONS}) ||
 
30
            (defined $ENV{DH_INTERNAL_OPTIONS} && length $ENV{DH_INTERNAL_OPTIONS}) ||
 
31
            grep /^-/, @ARGV) {
43
32
                eval "use Debian::Debhelper::Dh_Getopt";
44
 
                error($!) if $@;
45
 
                %dh=Debian::Debhelper::Dh_Getopt::parseopts();
 
33
                error($@) if $@;
 
34
                Debian::Debhelper::Dh_Getopt::parseopts($params{options});
46
35
        }
47
36
 
48
37
        # Another way to set excludes.
85
74
        # Check if packages to build have been specified, if not, fall back to
86
75
        # the default, doing them all.
87
76
        if (! defined $dh{DOPACKAGES} || ! @{$dh{DOPACKAGES}}) {
88
 
                if ($dh{DOINDEP} || $dh{DOARCH} || $dh{DOSAME}) {
89
 
                        error("You asked that all arch in(dep) packages be built, but there are none of that type.");
90
 
                }
91
77
                push @{$dh{DOPACKAGES}},@allpackages;
92
78
        }
93
79
 
114
100
my $write_log=1;
115
101
sub END {
116
102
        if ($? == 0 && $write_log) {
117
 
                my $cmd=basename($0);
118
 
                foreach my $package (@{$dh{DOPACKAGES}}) {
119
 
                        my $ext=pkgext($package);
120
 
                        my $log="debian/${ext}debhelper.log";
121
 
                        open(LOG, ">>", $log) || error("failed to write to ${log}: $!");
122
 
                        print LOG $cmd."\n";
123
 
                        close LOG;
124
 
                }
 
103
                write_log(basename($0), @{$dh{DOPACKAGES}});
 
104
        }
 
105
}
 
106
 
 
107
sub load_log {
 
108
        my ($package, $db)=@_;
 
109
        my $ext=pkgext($package);
 
110
 
 
111
        my @log;
 
112
        open(LOG, "<", "debian/${ext}debhelper.log") || return;
 
113
        while (<LOG>) {
 
114
                chomp;
 
115
                push @log, $_;
 
116
                $db->{$package}{$_}=1 if defined $db;
 
117
        }
 
118
        close LOG;
 
119
        return @log;
 
120
}
 
121
 
 
122
sub write_log {
 
123
        my $cmd=shift;
 
124
        my @packages=@_;
 
125
 
 
126
        foreach my $package (@packages) {
 
127
                my $ext=pkgext($package);
 
128
                my $log="debian/${ext}debhelper.log";
 
129
                open(LOG, ">>", $log) || error("failed to write to ${log}: $!");
 
130
                print LOG $cmd."\n";
 
131
                close LOG;
125
132
        }
126
133
}
127
134
 
167
174
        verbose_print(escape_shell(@_));
168
175
 
169
176
        if (! $dh{NO_ACT}) {
170
 
                my $ret=system(@_);
171
 
                $ret == 0 || error("command returned error code $ret");
 
177
                system(@_) == 0 || _error_exitcode($_[0]);
172
178
        }
173
179
}
174
180
 
181
187
        
182
188
        if (! $dh{NO_ACT}) {
183
189
                # The join makes system get a scalar so it forks off a shell.
184
 
                system(join(" ",@_)) == 0
185
 
                        || error("command returned error code");
 
190
                system(join(" ", @_)) == 0 || _error_exitcode(join(" ", @_))
186
191
        }                       
187
192
}
188
193
 
 
194
sub _error_exitcode {
 
195
        my $command=shift;
 
196
        if ($? == -1) {
 
197
                error("$command failed to to execute: $!");
 
198
        }
 
199
        elsif ($? & 127) {
 
200
                error("$command died with signal ".($? & 127));
 
201
        }
 
202
        else {
 
203
                error("$command returned exit code ".($? >> 8));
 
204
        }
 
205
}
 
206
 
189
207
# Run a command that may have a huge number of arguments, like xargs does.
190
208
# Pass in a reference to an array containing the arguments, and then other
191
209
# parameters that are the command and any parameters that should be passed to
293
311
                }
294
312
 
295
313
                if ($c < 4 && ! $warned_compat) {
296
 
                        warning("Compatibility levels before 4 are deprecated.");
 
314
                        warning("Compatibility levels before 5 are deprecated.");
297
315
                        $warned_compat=1;
298
316
                }
299
317