~ubuntu-branches/ubuntu/karmic/sbuild/karmic-proposed

« back to all changes in this revision

Viewing changes to lib/Sbuild/Options.pm

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2009-05-09 16:06:44 UTC
  • mfrom: (8.1.6 upstream) (3.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090509160644-9k0fgp6c2ajcu54h
Tags: 0.58.2-1ubuntu1
* Merge from debian unstable, remaining changes:
  - bin/sbuild, lib/Sbuild/{Base,Conf,Options}.pm: add --setup-hook
    to allow pre-build modifications to underlying chroots (needed
    to adjust pockets and components in sources.list).  (debian bug
    500746).

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
use warnings;
27
27
 
28
28
use Getopt::Long qw(:config no_ignore_case auto_abbrev gnu_getopt);
29
 
use Sbuild qw(isin help_text version_text usage_error);
 
29
use Sbuild qw(help_text version_text usage_error);
 
30
use Sbuild::Base;
30
31
use Sbuild::Conf;
31
32
 
32
33
BEGIN {
33
34
    use Exporter ();
34
35
    our (@ISA, @EXPORT);
35
36
 
36
 
    @ISA = qw(Exporter);
 
37
    @ISA = qw(Exporter Sbuild::Base);
37
38
 
38
39
    @EXPORT = qw();
39
40
}
40
41
 
41
 
sub new ();
42
 
sub get (\%$);
43
 
sub set (\%$$);
44
 
sub parse_options (\%);
45
 
 
46
 
sub new () {
47
 
    my $self  = {};
48
 
    bless($self);
49
 
 
50
 
    $self->{'User Arch'} = '';
51
 
    $self->{'Build Arch All'} = 0;
52
 
    $self->{'Auto Giveback'} = 0;
53
 
    $self->{'Auto Giveback Host'} = 0;
54
 
    $self->{'Auto Giveback Socket'} = 0;
55
 
    $self->{'Auto Giveback User'} = 0;
56
 
    $self->{'Auto Giveback WannaBuild User'} = 0;
57
 
    $self->{'Manual Srcdeps'} = [];
58
 
    $self->{'Batch Mode'} = 0;
59
 
    $self->{'WannaBuild Database'} = 0;
60
 
    $self->{'Build Source'} = 0;
61
 
    $self->{'Distribution'} = 'unstable';
62
 
    $self->{'Override Distribution'} = 0;
63
 
    $self->{'binNMU'} = undef;
64
 
    $self->{'binNMU Version'} = undef;
65
 
    $self->{'Chroot'} = undef;
66
 
    $self->{'LD_LIBRARY_PATH'} = undef;
67
 
    $self->{'GCC Snapshot'} = 0;
 
42
sub new {
 
43
    my $class = shift;
 
44
    my $conf = shift;
 
45
 
 
46
    my $self = $class->SUPER::new($conf);
 
47
    bless($self, $class);
68
48
 
69
49
    if (!$self->parse_options()) {
70
50
        usage_error("sbuild", "Error parsing command-line options");
73
53
    return $self;
74
54
}
75
55
 
76
 
sub get (\%$) {
77
 
    my $self = shift;
78
 
    my $key = shift;
79
 
 
80
 
    return $self->{$key};
81
 
}
82
 
 
83
 
sub set (\%$$) {
84
 
    my $self = shift;
85
 
    my $key = shift;
86
 
    my $value = shift;
87
 
 
88
 
# TODO: Check if key exists before setting it.
89
 
 
90
 
    return $self->{$key} = $value;
91
 
}
92
 
 
93
 
sub parse_options (\%) {
 
56
sub parse_options {
94
57
    my $self = shift;
95
58
 
96
59
    return GetOptions ("h|help" => sub { help_text("1", "sbuild"); },
97
60
                       "V|version" => sub {version_text("sbuild"); },
98
 
                       "arch=s" => \$self->{'User Arch'},
 
61
                       "arch=s" => sub {
 
62
                           $self->set_conf('ARCH', $_[1]);
 
63
                       },
99
64
                       "A|arch-all" => sub {
100
 
                           $self->set('Build Arch All', 1);
 
65
                           $self->set_conf('BUILD_ARCH_ALL', 1);
101
66
                       },
102
67
                       "auto-give-back=s" => sub {
103
 
                           $self->set('Auto Giveback', 1);
 
68
                           $self->set_conf('AUTO_GIVEBACK', 1);
104
69
                           if ($_[1]) {
105
70
                               my @parts = split( '@', $_[1] );
106
 
                               $self->set('Auto Giveback Socket',
 
71
                               $self->set_conf('AUTO_GIVEBACK_SOCKET',
107
72
                                          $parts[$#parts-3])
108
73
                                   if @parts > 3;
109
 
                               $self->set('Auto Giveback WannaBuild User',
 
74
                               $self->set_conf('AUTO_GIVEBACK_WANNABUILD_USER',
110
75
                                          $parts[$#parts-2])
111
76
                                   if @parts > 2;
112
 
                               $self->set('Auto Giveback User',
 
77
                               $self->set_conf('AUTO_GIVEBACK_USER',
113
78
                                          $parts[$#parts-1])
114
79
                                   if @parts > 1;
115
 
                               $self->set('Auto Giveback Host',
 
80
                               $self->set_conf('AUTO_GIVEBACK_HOST',
116
81
                                          $parts[$#parts]);
117
82
                           }
118
83
                       },
119
84
                       "f|force-depends=s" => sub {
120
 
                           push( @{$self->get('Manual Srcdeps')}, "f".$_[1] );
 
85
                           push(@{$self->get_conf('MANUAL_SRCDEPS')},
 
86
                                "f".$_[1]);
121
87
                       },
122
88
                       "a|add-depends=s" => sub {
123
 
                           push( @{$self->get('Manual Srcdeps')}, "a".$_[1] );
 
89
                           push(@{$self->get_conf('MANUAL_SRCDEPS')},
 
90
                                "a".$_[1] );
124
91
                       },
125
92
                       "check-depends-algorithm=s" => sub {
126
 
                           die "Bad build dependency check algorithm\n"
127
 
                               if( ! ($_[1] eq "first-only" 
128
 
                                      || $_[1] eq "alternatives") );
129
 
                           $Sbuild::Conf::check_depends_algorithm = $_[1];
 
93
                           $self->set_conf('CHECK_DEPENDS_ALGORITHM', $_[1]);
130
94
                       },
131
95
                       "b|batch" => sub {
132
 
                           $self->set('Batch Mode', 1);
 
96
                           $self->set_conf('BATCH_MODE', 1);
133
97
                       },
134
98
                       "make-binNMU=s" => sub {
135
 
                           $self->set('binNMU', $_[1]);
136
 
                           $self->set('binNMU Version',
137
 
                                      $self->get('binNMU Version') || 1);
 
99
                           $self->set_conf('BIN_NMU', $_[1]);
 
100
                           $self->set_conf('BIN_NMU_VERSION', 1)
 
101
                               if (!defined $self->get_conf('BIN_NMU_VERSION'));
138
102
                       },
139
103
                       "binNMU=i" => sub {
140
 
                           $self->set('binNMU Version', $_[1]);
 
104
                           $self->set_conf('BIN_NMU_VERSION', $_[1]);
141
105
                       },
142
106
                       "c|chroot=s" => sub {
143
 
                           $self->set('Chroot', $_[1]);
 
107
                           $self->set_conf('CHROOT', $_[1]);
144
108
                       },
145
109
                       "database=s" => sub {
146
 
                           $self->set('WannaBuild Database', $_[1]);
147
 
                       },
148
 
                       "D|debug+" => \$Sbuild::Conf::debug,
149
 
                       "apt-update" => \$Sbuild::Conf::apt_update,
 
110
                           $self->set_conf('WANNABUILD_DATABASE', $_[1]);
 
111
                       },
 
112
                       "D|debug" => sub {
 
113
                           $self->set_conf('DEBUG',
 
114
                                           $self->get_conf('DEBUG') + 1);
 
115
                       },
 
116
                       "apt-update" => sub {
 
117
                           $self->set_conf('APT_UPDATE', $_[1]);
 
118
                       },
150
119
                       "d|dist=s" => sub {
151
 
                           $self->set('Distribution', $_[1]);
152
 
                           $self->set('Distribution', "oldstable")
153
 
                               if $self->{'Distribution'} eq "o";
154
 
                           $self->set('Distribution', "stable")
155
 
                               if $self->{'Distribution'} eq "s";
156
 
                           $self->set('Distribution', "testing")
157
 
                               if $self->{'Distribution'} eq "t";
158
 
                           $self->set('Distribution', "unstable")
159
 
                               if $self->{'Distribution'} eq "u";
160
 
                           $self->set('Distribution', "experimental")
161
 
                               if $self->{'Distribution'} eq "e";
162
 
                           $self->set('Override Distribution', 1);
163
 
                       },
164
 
                       "force-orig-source" => \$Sbuild::Conf::force_orig_source,
165
 
                       "m|maintainer=s" => \$Sbuild::Conf::maintainer_name,
166
 
                       "k|keyid=s" => \$Sbuild::Conf::key_id,
167
 
                       "e|uploader=s" => \$Sbuild::Conf::uploader_name,
168
 
                       "n|nolog" => \$Sbuild::Conf::nolog,
169
 
                       "purge=s" => sub {
170
 
                           $Sbuild::Conf::purge_build_directory = $_[1];
171
 
                           die "Bad purge mode\n"
172
 
                               if !isin($Sbuild::Conf::purge_build_directory,
173
 
                                        qw(always successful never));
 
120
                           $self->set_conf('DISTRIBUTION', $_[1]);
 
121
                           $self->set_conf('DISTRIBUTION', "oldstable")
 
122
                               if $self->get_conf('DISTRIBUTION') eq "o";
 
123
                           $self->set_conf('DISTRIBUTION', "stable")
 
124
                               if $self->get_conf('DISTRIBUTION') eq "s";
 
125
                           $self->set_conf('DISTRIBUTION', "testing")
 
126
                               if $self->get_conf('DISTRIBUTION') eq "t";
 
127
                           $self->set_conf('DISTRIBUTION', "unstable")
 
128
                               if $self->get_conf('DISTRIBUTION') eq "u";
 
129
                           $self->set_conf('DISTRIBUTION', "experimental")
 
130
                               if $self->get_conf('DISTRIBUTION') eq "e";
 
131
                           $self->set_conf('OVERRIDE_DISTRIBUTION', 1);
 
132
                       },
 
133
                       "force-orig-source" => sub {
 
134
                           $self->set_conf('FORCE_ORIG_SOURCE', 1);
 
135
                       },
 
136
                       "m|maintainer=s" => sub {
 
137
                           $self->set_conf('MAINTAINER_NAME', $_[1]);
 
138
                       },
 
139
                       "k|keyid=s" => sub {
 
140
                           $self->set_conf('KEY_ID', $_[1]);
 
141
                       },
 
142
                       "e|uploader=s" => sub {
 
143
                           $self->set_conf('UPLOADER_NAME', $_[1]);
 
144
                       },
 
145
                       "n|nolog" => sub {
 
146
                           $self->set('NOLOG', 1);
 
147
                       },
 
148
                       "p|purge=s" => sub {
 
149
                           $self->set_conf('PURGE_BUILD_DIRECTORY', $_[1]);
174
150
                       },
175
151
                       "s|source" => sub {
176
 
                           $self->set('Build Source', 1);
177
 
                       },
178
 
                       "stats-dir=s" => \$Sbuild::Conf::stats_dir,
179
 
                       "setup-cmd=s" => \$Sbuild::Conf::setup_cmd,
 
152
                           $self->set_conf('BUILD_SOURCE', 1);
 
153
                       },
 
154
                       "archive=s" => sub {
 
155
                           $self->set_conf('ARCHIVE', $_[1]);
 
156
                       },
 
157
                       "stats-dir=s" => sub {
 
158
                           $self->set_conf('STATS_DIR', $_[1]);
 
159
                       },
 
160
                       "setup-hook=s" => sub {
 
161
                           $self->set_conf('SETUP_HOOK', $_[1]);
 
162
                       },
180
163
                       "use-snapshot" => sub {
181
 
                           $self->set('GCC Snapshot', 1);
182
 
                           $self->set('LD_LIBRARY_PATH',
183
 
                                      "/usr/lib/gcc-snapshot/lib");
184
 
                           $Sbuild::Conf::path =
185
 
                               "/usr/lib/gcc-snapshot/bin:$Sbuild::Conf::path";
186
 
                       },
187
 
                       "v|verbose+" => \$Sbuild::Sbuild::Conf::verbose,
 
164
                           $self->set_conf('GCC_SNAPSHOT', 1);
 
165
                           $self->set_conf('LD_LIBRARY_PATH',
 
166
                                           '/usr/lib/gcc-snapshot/lib' .
 
167
                                           $self->get_conf('LD_LIBRARY_PATH') ne '' ? ':' . $self->get_conf('LD_LIBRARY_PATH') : '');
 
168
                           $self->set_conf('PATH',
 
169
                                           '/usr/lib/gcc-snapshot/bin' .
 
170
                                           $self->get_conf('PATH') ne '' ? ':' . $self->get_conf('PATH') : '');
 
171
                       },
 
172
                       "v|verbose" => sub {
 
173
                           $self->set_conf('VERBOSE',
 
174
                                          $self->get_conf('VERBOSE') + 1);
 
175
                       },
188
176
                       "q|quiet" => sub {
189
 
                           $Sbuild::Sbuild::Conf::verbose-- if $Sbuild::Conf::verbose;
 
177
                           $self->set_conf('VERBOSE',
 
178
                                           $self->get_conf('VERBOSE') - 1)
 
179
                               if $self->get_conf('VERBOSE');
190
180
                       },
191
181
        );
192
182
}