File Coverage

blib/lib/LCFG/Build/Tool/Pack.pm
Criterion Covered Total %
statement 16 18 88.8
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 22 24 91.6


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