File Coverage

blib/lib/LCFG/Build/Tool/RPM.pm
Criterion Covered Total %
statement 19 21 90.4
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 26 28 92.8


line stmt bran cond sub pod time code
1             package LCFG::Build::Tool::RPM; # -*-cperl-*-
2 1     1   1789 use strict;
  1         1  
  1         29  
3 1     1   5 use warnings;
  1         2  
  1         112  
4              
5             # $Id: RPM.pm.in 15905 2011-02-17 17:01:27Z squinney@INF.ED.AC.UK $
6             # $Source: /var/cvs/dice/LCFG-Build-Tools/lib/LCFG/Build/Tool/RPM.pm.in,v $
7             # $Revision: 15905 $
8             # $HeadURL: https://svn.lcfg.org/svn/source/tags/LCFG-Build-Tools/LCFG_Build_Tools_0_4_0/lib/LCFG/Build/Tool/RPM.pm.in $
9             # $Date: 2011-02-17 17:01:27 +0000 (Thu, 17 Feb 2011) $
10              
11             our $VERSION = '0.4.0';
12              
13 1     1   5 use LCFG::Build::Utils::RPM;
  1         2  
  1         9  
14 1     1   25 use File::Basename ();
  1         2  
  1         12  
15 1     1   4 use File::Copy ();
  1         2  
  1         17  
16 1     1   4 use File::Spec ();
  1         1  
  1         12  
17              
18 1     1   390 use Moose;
  0            
  0            
19              
20             extends 'LCFG::Build::Tool::Pack';
21              
22             has 'sourceonly' => (
23             is => 'rw',
24             isa => 'Bool',
25             default => 0,
26             documentation => 'Only build source package',
27             );
28              
29             has 'deps' => (
30             is => 'rw',
31             isa => 'Bool',
32             default => 1,
33             documentation => 'Build dependency checking',
34             );
35              
36             has 'sign' => (
37             is => 'rw',
38             isa => 'Bool',
39             default => 0,
40             documentation => 'Embed a GPG signature in the package',
41             );
42              
43             override 'abstract' => sub {
44             return q{Build binary RPMs from the tagged source tree};
45             };
46              
47             override 'execute' => sub {
48             my ($self) = @_;
49              
50             super; # packs the source
51              
52             my %opts;
53             if ( !$self->deps ) {
54             $opts{nodeps} = 1;
55             }
56             if ( $self->sourceonly ) {
57             $opts{sourceonly} = 1;
58             }
59             if ( $self->sign ) {
60             $opts{sign} = 1;
61             }
62              
63             my $spec = $self->spec;
64              
65             my $module = $spec->fullname;
66             my $version = $spec->version;
67              
68             my $dirname = join q{-}, $module, $version;
69             my $outdir = File::Spec->catdir( $self->resultsdir, $dirname );
70              
71             my $tarname = $spec->tarname;
72             my $tarfile = File::Spec->catfile( $outdir, $tarname );
73              
74             my $packname = join q{-}, $spec->fullname, $spec->version;
75             my $specname = $packname . '.spec';
76             my $specfile = File::Spec->catfile( $outdir, $specname );
77              
78             my $result = LCFG::Build::Utils::RPM->build( $outdir, $specfile, \%opts );
79              
80             $self->log("Successfully built source package for $module");
81              
82             my $source_path = $result->{source};
83             $self->log("Source: $source_path");
84              
85             if ( !$self->sourceonly ) {
86             $self->log("Successfully built packages for $module");
87              
88             for my $package ( @{ $result->{packages} } ) {
89             $self->log("Package: $package");
90             }
91              
92             }
93              
94             return;
95             };
96              
97             __PACKAGE__->meta->make_immutable;
98              
99             no Moose;
100             1;
101             __END__
102              
103             =head1 NAME
104              
105             LCFG::Build::Tool::RPM - LCFG software packaging tool
106              
107             =head1 VERSION
108              
109             This documentation refers to LCFG::Build::Tool::RPM version 0.4.0
110              
111             =head1 SYNOPSIS
112              
113             my $tool = LCFG::Build::Tool::RPM->new( dir => '.' );
114              
115             $tool->execute;
116              
117             my $tool2 = LCFG::Build::Tool::RPM->new_with_options();
118              
119             $tool2->execute;
120              
121             =head1 DESCRIPTION
122              
123             This module provides software release tools for the LCFG build
124             suite.
125              
126             This is a tool to take a tagged copy of the source for a project
127             managed with the LCFG build tools and package it into a gzipped source
128             tar file. Build metadata files for supported platforms (e.g. a
129             specfile for building binary RPMs) are also generated at the same
130             time. It is also possible to do limited autoconf-style macro
131             substitution prior to the source being packaged. This allows the
132             generation of 'pristine' tar files where downstream users will be
133             unaware of the additional source-file processing that has been carried
134             out prior to distribution. Binary RPM packages will then be generated
135             from the gzipped source tar file using the generated specfile.
136              
137             More information on the LCFG build tools is available from the website
138             http://www.lcfg.org/doc/buildtools/
139              
140             =head1 ATTRIBUTES
141              
142             The following attributes are modifiable via the command-line (i.e. via
143             @ARGV) as well as the normal way when the Tool object is
144             created. Unless stated the options take strings as arguments and can
145             be used like C<--foo=bar>. Boolean options can be expressed as either
146             C<--foo> or C<--no-foo> to signify true and false values.
147              
148             =over 4
149              
150             =item dryrun
151              
152             A boolean value which indicates whether actions which permanently
153             alter the contents of files should be carried out. The default value
154             is false (0). When running in dry-run mode various you will typically
155             get extra output to the screen showing what would have been done.
156              
157             =item quiet
158              
159             A boolean value which indicates whether the actions should attempt to
160             be quieter. The default value is false (0).
161              
162             =item dir
163              
164             The path of the project directory which contains the software for
165             which you want to create a release. If this is not specified then a
166             default value of the current directory (.) will be used. This
167             directory must already contain the LCFG build metadata file (lcfg.yml)
168             for the software.
169              
170             =item resultsdir
171              
172             When a project is packaged for release the generated products (the
173             gzipped source tar file, various build metadata files and possibly
174             binary RPMS, etc) are stored into a directory named after the
175             combination of the full name of the project and the version
176             number. For example, a project named 'foo' with version '1.2.3' would
177             have an output directory of 'foo-1.2.3'. You should note that if the
178             C<base> attribute is specified in the metadata file (this is the case
179             for LCFG components) then that is also used. If the previous example
180             was an LCFG component it would have a directory named
181             'lcfg-foo-1.2.3'.
182              
183             This attribute controls the parent directory into which that generated
184             directory will be placed. The default on a Unix system is
185             C<$HOME/lcfgbuild/> which will be created if it does not already
186             exist.
187              
188             =item gencmake
189              
190             This is a boolean value which controls whether CMake build files will
191             be created when the source code for the project is packaged. The
192             default is to take the setting from C<gencmake> option in the
193             C<buildinfo> section of the LCFG build metadata file.
194              
195             =item translate
196              
197             This is a boolean value which controls whether source files will be
198             translated BEFORE they are packaged. The default is to take the
199             setting from C<translate_before_pack> option in the C<buildinfo>
200             section of the LCFG build metadata file.
201              
202             =item remove_after_translate
203              
204             This is a boolean value which controls whether input files will be
205             removed after they have been translated. They are only removed if the
206             input and output filenames do not match (e.g. foo.cin becomes
207             foo). The default is to take the setting from
208             C<remove_input_after_translate> option in the C<buildinfo> section of
209             the LCFG build metadata file.
210              
211             =item sourceonly
212              
213             This is a boolean value which controls whether the binary packages
214             should be built as well as the source RPM.
215              
216             =item sign
217              
218             This is a boolean value which controls whether C<rpmbuild> should
219             embed a GPG signature in the package.
220              
221             =item deps
222              
223             This is a boolean value which controls whether C<rpmbuild> checks the
224             dependencies specified in the RPM specfile when it builds the source
225             or binary RPMs.
226              
227             =back
228              
229             The following methods are not modifiable by the command-line, they are
230             however directly modifiable via the Tool object if
231             necessary. Typically you will only need to query these attributes,
232             they are automatically created when you need them using values for
233             some of the other command-line attributes.
234              
235             =over 4
236              
237             =item spec
238              
239             This is a reference to the current project metadata object, see
240             L<LCFG::Build::PkgSpec> for full details.
241              
242             =item vcs
243              
244             This is a reference to the current version-control object, see
245             L<LCFG::Build::VCS> for full details.
246              
247             =back
248              
249             =head1 SUBROUTINES/METHODS
250              
251             =over 4
252              
253             =item execute
254              
255             This method first calls the execute() method in L<LCFG::Build::Tool::Pack>
256             to generate a gzipped source tar file and the build metadata files for
257             the various supported platforms (e.g. a specfile for creating binary
258             RPMs). Once that is done C<rpmbuild> is used to create binary RPMs
259             from the generated source tar file and specfile.
260              
261             =item fail($message)
262              
263             Immediately fails (i.e. dies) and displays the message.
264              
265             =item log($message)
266              
267             Logs the message to the screen if the C<quiet> attribute has not been
268             specified. A message string is prefixed with 'LCFG: ' to help visually
269             separate it from other output.
270              
271             =back
272              
273             =head1 DEPENDENCIES
274              
275             This module is L<Moose> powered and uses L<MooseX::App::Cmd> to handle
276             command-line options.
277              
278             The following modules from the LCFG build tools suite are also
279             required: L<LCFG::Build::Tool::Pack>, L<LCFG::Build::PkgSpec>,
280             L<LCFG::Build::VCS> and VCS helper module for your preferred
281             version-control system.
282              
283             For building RPMs you will also need L<LCFG::Build::Utils::RPM>.
284              
285             =head1 SEE ALSO
286              
287             L<LCFG::Build::Tools>, L<LCFG::Build::Skeleton>, lcfg-reltool(1)
288              
289             =head1 PLATFORMS
290              
291             This is the list of platforms on which we have tested this
292             software. We expect this software to work on any Unix-like platform
293             which is supported by Perl.
294              
295             Fedora12, Fedora13, ScientificLinux5, ScientificLinux6, MacOSX7
296              
297             =head1 BUGS AND LIMITATIONS
298              
299             There are no known bugs in this application. Please report any
300             problems to bugs@lcfg.org, feedback and patches are also always very
301             welcome.
302              
303             =head1 AUTHOR
304              
305             Stephen Quinney <squinney@inf.ed.ac.uk>
306              
307             =head1 LICENSE AND COPYRIGHT
308              
309             Copyright (C) 2008 University of Edinburgh. All rights reserved.
310              
311             This library is free software; you can redistribute it and/or modify
312             it under the terms of the GPL, version 2 or later.
313              
314             =cut