File Coverage

blib/lib/LCFG/Build/Utils/OSXPkg.pm
Criterion Covered Total %
statement 24 61 39.3
branch 0 16 0.0
condition 0 3 0.0
subroutine 8 9 88.8
pod 1 1 100.0
total 33 90 36.6


line stmt bran cond sub pod time code
1             package LCFG::Build::Utils::OSXPkg; # -*-cperl-*-
2 1     1   1589 use strict;
  1         1  
  1         31  
3 1     1   4 use warnings;
  1         2  
  1         49  
4              
5             # $Id: OSXPkg.pm.in 20973 2012-05-18 16:54:45Z squinney@INF.ED.AC.UK $
6             # $Source: /var/cvs/dice/LCFG-Build-Tools/lib/LCFG/Build/Utils/MacOSX.pm.in,v $
7             # $Revision: 20973 $
8             # $HeadURL: https://svn.lcfg.org/svn/source/tags/LCFG-Build-Tools/LCFG_Build_Tools_0_4_0/lib/LCFG/Build/Utils/OSXPkg.pm.in $
9             # $Date: 2012-05-18 17:54:45 +0100 (Fri, 18 May 2012) $
10              
11             our $VERSION = '0.4.0';
12              
13 1     1   5 use File::Copy ();
  1         1  
  1         12  
14 1     1   5 use File::Spec ();
  1         1  
  1         18  
15 1     1   4 use File::Temp ();
  1         7  
  1         13  
16 1     1   5 use LCFG::Build::Utils;
  1         15  
  1         16  
17 1     1   1040 use Sys::Hostname ();
  1         1586  
  1         21  
18 1     1   1103 use Readonly;
  1         4147  
  1         626  
19              
20             Readonly my $CMAKE => '/usr/bin/cmake';
21             Readonly my $MAKE => '/usr/bin/make';
22             Readonly my $PKGBUILD => '/usr/bin/pkgbuild';
23              
24             sub build {
25 0     0 1   my ( $self, $outdir, $tarfile, $dirname,
26             $pkgname, $pkgversion, $pkgident,
27             $filters, $scriptdir, $nopayload ) = @_;
28              
29 0           my $tempdir = File::Temp::tempdir( 'buildtools-XXXXX',
30             TMPDIR => 1,
31             CLEANUP => 1 );
32 0           chdir $tempdir;
33              
34 0           require Archive::Tar;
35 0           require IO::Zlib;
36              
37 0           my $tar = Archive::Tar->new();
38 0           my $tar_ok = $tar->extract_archive( $tarfile, 1);
39 0 0         if ( !$tar_ok ) {
40 0           die "Failed to extract '$tarfile': " . $tar->error . "\n";
41             }
42              
43 0 0         chdir $dirname or
44             die "Failed to change directory into $dirname - check tar file.";
45              
46 0           my @cmake_cmd = ( $CMAKE, '.');
47 0           my $cmake_ok = system @cmake_cmd;
48 0 0         if ( $cmake_ok != 0 ) {
49 0           die "Failed to run cmake.\n";
50             }
51              
52 0           my $builddir = File::Temp::tempdir( 'buildtools-XXXXX',
53             TMPDIR => 1,
54             CLEANUP => 1 );
55              
56 0           my $filename = File::Spec->catfile( $outdir, $pkgname . '.pkg') ;
57              
58 0           my @make_cmd = ( $MAKE, 'install',
59             'DESTDIR=' . $builddir);
60 0           my $make_ok = system @make_cmd;
61 0 0         if ( $make_ok != 0 ) {
62 0           die "Failed to build project .\n";
63             }
64              
65 0           my @pkgbuild_cmd = ( $PKGBUILD,
66             '--identifier' => $pkgident,
67             '--version' => $pkgversion );
68              
69             # If there's no payload, don't specify the files to package
70 0 0         if ( $nopayload ) {
71 0           push @pkgbuild_cmd, '--nopayload';
72             } else {
73 0           push @pkgbuild_cmd, '--root' => $builddir;
74             }
75              
76             # pkgbuild by default filters .DS_Store, CVS and .svn, but doesn't
77             # if we use the --filter option, so add these explicitly
78 0           my @default_filters = ( qw/ .DS_Store CVS .svn / );
79              
80             # Add a command line option for each filter
81 0           foreach my $filter ( @default_filters, @$filters ) {
82 0           push @pkgbuild_cmd, '--filter' => $filter;
83             }
84              
85 0 0 0       if ( ( defined $scriptdir ) && ( -d $scriptdir ) ) {
86 0           push @pkgbuild_cmd, '--scripts' => $scriptdir;
87             }
88 0           push @pkgbuild_cmd, $filename;
89              
90 0           my $pkgbuild_ok = system @pkgbuild_cmd;
91 0 0         if ( $pkgbuild_ok != 0 ) {
92 0           die "Failed to make package.\n";
93             }
94              
95             # Check there really is a package
96 0 0         if ( ! -f $filename ) {
97 0           die "Cannot find expected package: '$filename'.\n";
98             }
99              
100 0           my @packages = ( $filename );
101             return {
102 0           packages => \@packages
103             };
104             }
105              
106             1;
107             __END__
108              
109             =head1 NAME
110              
111             LCFG::Build::Utils::OSXPkg - LCFG software building utilities
112              
113             =head1 VERSION
114              
115             This documentation refers to LCFG::Build::Utils::OSXPkg version 0.4.0
116              
117             =head1 DESCRIPTION
118              
119             This module provides a suite of utilities to help in building MacOSX
120             packages from LCFG projects, particularly LCFG components. The methods
121             are mostly used by tools which implement the LCFG::Build::Tool base
122             class (e.g. LCFG::Build::Tool::OSXPkg) but typically they are designed to
123             be generic enough to be used elsewhere.
124              
125             =head1 SUBROUTINES/METHODS
126              
127             There is one public method you can call on this class.
128              
129             =over 4
130              
131             =item build( $outdir, $tarfile, $dirname, $pkgname, $pkgversion, $pkgident, $filters, $scriptdir, $nopayload )
132              
133             This method assumes that C<$tarfile> contains sources that C<cmake>
134             can build and install. C<pkgbuild> is then called to create the
135             package.
136              
137             =over 4
138              
139             =item B<$outdir>
140              
141             Absolute path to the directory where the package will be created.
142              
143             =item B<$tarfile>
144              
145             Absolute path to the tarfile to unpack, build and package.
146              
147             =item B<$pkgname>
148              
149             The full name of the package you want to generate,
150             e.g. C<lcfg-foo-1.2.3-4>. C<.pkg> will be appended to this for you.
151              
152             =item B<$pkgversion>
153              
154             The version of the package, e.g. C<1.2.3.4>.
155              
156             =item B<$pkgident>
157              
158             A package identifier to pass to C<pkgbuild>, e.g. C<org.lcfg>.
159              
160             =item B<$filters>
161              
162             A reference to an array of filter expressions to pass to C<pkgbuild>.
163              
164             =item B<$scriptdir>
165              
166             Absolute path to a directory of scripts to pass to C<pkgbuild>. There
167             is no filtering of the files in this directory and C<pkgbuild> will
168             copy all its contents into the package.
169              
170             =item B<$nopayload>
171              
172             A boolean that flags whether the package should be created with or
173             without a payload.
174              
175             =back
176              
177             =back
178              
179             =head1 DEPENDENCIES
180              
181             For building packages you will need CMake and pkgbuild.
182              
183             =head1 PLATFORMS
184              
185             This is the list of platforms on which we have tested this
186             software. We expect this software to work on any Unix-like platform
187             which is supported by Perl.
188              
189             Mac OS X 10.7
190              
191             =head1 BUGS AND LIMITATIONS
192              
193             There are no known bugs in this application. Please report any
194             problems to bugs@lcfg.org, feedback and patches are also always very
195             welcome.
196              
197             =head1 AUTHOR
198              
199             Kenneth MacDonald <Kenneth.MacDonald@ed.ac.uk>
200             Stephen Quinney <squinney@inf.ed.ac.uk>
201              
202             =head1 LICENSE AND COPYRIGHT
203              
204             Copyright (C) 2008-2012 University of Edinburgh. All rights reserved.
205              
206             This library is free software; you can redistribute it and/or modify
207             it under the terms of the GPL, version 2 or later.
208              
209             =cut