Merge pull request #228 from DOCGroup/jwillemsen-patch-1
[MPC.git] / modules / RpmSpecProjectCreator.pm
blobc5ab3745fb4cc8e893fbeef18e0379f8834b1d38
1 package RpmSpecProjectCreator;
3 # ************************************************************
4 # Description : An RPM .spec file Project Creator
5 # Author : Adam Mitz (OCI)
6 # Create Date : 11/23/2010
7 # ************************************************************
9 # ************************************************************
10 # Pragmas
11 # ************************************************************
13 use strict;
14 use File::Path;
16 use ProjectCreator;
18 use vars qw(@ISA);
19 @ISA = qw(ProjectCreator);
21 # ************************************************************
22 # Subroutine Section
23 # ************************************************************
25 sub project_file_extension {
26 return '.dummy';
29 # Don't actually write anything, just keep MPC internal data structures
30 # up-to-date as if it had been written. We don't want a .spec file for each
31 # MPC project because that is too fine-grained. See the corresponding
32 # workspace creator for the actual .spec file creation.
33 sub write_output_file {
34 my $self = shift;
35 my $tover = $self->get_template_override();
36 my @templates = $self->get_template();
37 @templates = ($tover) if (defined $tover);
39 if (scalar @templates != 1) {
40 return 0, 'there should be only one template';
43 my $template = $templates[0];
44 $self->{'current_template'} = $template;
46 my $name = $self->transform_file_name($self->project_file_name(undef,
47 $template));
48 $self->process_assignment('project_file', $name);
49 new TemplateParser($self)->collect_data();
51 if (defined $self->{'source_callback'}) {
52 my $cb = $self->{'source_callback'};
53 my $pjname = $self->get_assignment('project_name');
54 my @list = $self->get_component_list('source_files');
55 if (UNIVERSAL::isa($cb, 'ARRAY')) {
56 my @copy = @$cb;
57 my $s = shift(@copy);
58 &$s(@copy, $name, $pjname, \@list);
60 elsif (UNIVERSAL::isa($cb, 'CODE')) {
61 &$cb($name, $pjname, \@list);
63 else {
64 $self->warning("Ignoring callback: $cb.");
68 # Still need outdir since ProjectCreator::write_install_file (or similar)
69 # may depend on outdir existing before the WorkspaceCreator runs.
70 my $outdir = $self->get_outdir();
71 mkpath($outdir, 0, 0777) if ($outdir ne '.');
73 $self->add_file_written($name);
74 return 1, '';