File Coverage

blib/lib/LCFG/Build/Tool/DevPack.pm
Criterion Covered Total %
statement 22 24 91.6
branch n/a
condition n/a
subroutine 8 8 100.0
pod n/a
total 30 32 93.7


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