ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/TemplateInterface.pm
Revision: 1.6.2.1
Committed: Fri Feb 15 14:58:01 2008 UTC (17 years, 2 months ago) by muzaffar
Content type: text/plain
Branch: forBinLess_SCRAM
CVS Tags: V1_2_0-cand1
Changes since 1.6: +6 -58 lines
Log Message:
binary independent scram in forBinLess_SCRAM branch

File Contents

# User Rev Content
1 sashby 1.2 #____________________________________________________________________
2     # File: TemplateInterface.pm
3     #____________________________________________________________________
4     #
5     # Author: Shaun Ashby <Shaun.Ashby@cern.ch>
6     # Update: 2004-07-01 14:03:46+0200
7 muzaffar 1.6.2.1 # Revision: $Id: TemplateInterface.pm,v 1.6 2007/12/14 09:03:47 muzaffar Exp $
8 sashby 1.2 #
9     # Copyright: 2004 (C) Shaun Ashby
10     #
11     #--------------------------------------------------------------------
12     package BuildSystem::TemplateInterface;
13     require 5.004;
14     use Exporter;
15     @ISA=qw(Exporter);
16     @EXPORT_OK=qw( );
17    
18     sub new()
19     ###############################################################
20     # new #
21     ###############################################################
22     # modified : Thu Jul 1 14:04:01 2004 / SFA #
23     # params : #
24     # : #
25     # function : #
26     # : #
27     ###############################################################
28     {
29     my $proto=shift;
30     my $class=ref($proto) || $proto;
31     my $self={};
32    
33     bless $self,$class;
34    
35     # Process the environment hash and extract a
36     # list of vars that are needed for building.
37     # NB: This is done once only!
38     my %exportenv;
39     map
40     {
41     if ($_ =~ /^SCRAM/ || $_ =~ /(LOCAL|RELEASE)TOP$/)
42     {
43     $exportenv{$_} = $ENV{$_} if ($_ !~ /^SCRAMRT\_.*$/);
44     }
45     } keys %ENV;
46    
47     # Add the environment information to the TEMPLATE_DATA hash:
48     $self->{TEMPLATE_DATA} = { 'environment' => \%exportenv };
49    
50     # The filehandle for the generated Makefile:
51     my $makefile="$ENV{LOCALTOP}/$ENV{SCRAM_INTwork}/Makefile";
52    
53 muzaffar 1.5 if (!-f $makefile)
54     {
55 muzaffar 1.6.2.1 if (!-f "$ENV{LOCALTOP}/$ENV{SCRAM_CONFIGDIR}/SCRAM/GMake/Makefile")
56 muzaffar 1.5 {
57 muzaffar 1.6.2.1 die "Missing $ENV{LOCALTOP}/$ENV{SCRAM_CONFIGDIR}/SCRAM/GMake/Makefile file.";
58 muzaffar 1.5 }
59     use File::Copy;
60 muzaffar 1.6.2.1 copy("$ENV{LOCALTOP}/$ENV{SCRAM_CONFIGDIR}/SCRAM/GMake/Makefile",$makefile) or die "Copy failed: $!";
61 muzaffar 1.5 utime 0,0,$makefile;
62     }
63 sashby 1.2
64     # Init and pass in the template location:
65     $self->_init(@_);
66     return $self;
67     }
68    
69     sub _init()
70     {
71     my $self=shift;
72     my ($templatedir)=@_;
73    
74     # Create the new Template object:
75     $self->template_object();
76     return $self;
77     }
78    
79     sub template_object()
80     {
81     my $self=shift;
82 muzaffar 1.6.2.1 require SCRAM::Plugins::BuildRules;
83 sashby 1.2
84 muzaffar 1.6.2.1 $self->{TEMPLATE_OBJECT} = SCRAM::Plugins::BuildRules->new();
85 sashby 1.2 return $self;
86     }
87    
88     sub template_data()
89     {
90     my $self=shift;
91     my ($data) = @_;
92    
93     # Set the things that we must set. The "data" key points
94     # to a DataCollector object. The "branch" data is a
95     # TreeItem object:
96     $self->{TEMPLATE} = $data->template();
97     # Add required data accessed by key:
98     $self->{TEMPLATE_DATA}->{branch} = $data;
99     }
100    
101     sub run()
102     {
103 muzaffar 1.5 use FileHandle;
104 sashby 1.2 my $self=shift;
105 muzaffar 1.5
106     my $item = $self->{TEMPLATE_DATA}->{branch};
107     my $file = $item->safepath().".mk";
108     if ($item->class() eq "PROJECT")
109     {
110     $file = "$ENV{LOCALTOP}/.SCRAM/$ENV{SCRAM_ARCH}/MakeData/${file}";
111     }
112     elsif ($item->publictype())
113     {
114     $file = "$ENV{LOCALTOP}/.SCRAM/$ENV{SCRAM_ARCH}/MakeData/DirCache/${file}";
115     $item->{MKDIR}{"$ENV{LOCALTOP}/.SCRAM/$ENV{SCRAM_ARCH}/MakeData/DirCache"}=1;
116     }
117     else
118     {
119     $file = "$ENV{LOCALTOP}/$ENV{SCRAM_INTwork}/MakeData/DirCache/${file}";
120     $item->{MKDIR}{"$ENV{LOCALTOP}/$ENV{SCRAM_INTwork}/MakeData/DirCache"}=1;
121     }
122    
123     $self->{MAKEFILEFH} = FileHandle->new();
124     $self->{MAKEFILEFH}->open(">$file");
125 sashby 1.2 local *FH = $self->{MAKEFILEFH};
126    
127     $self->{TEMPLATE_OBJECT}->process($self->{TEMPLATE},
128     $self->{TEMPLATE_DATA},
129     $self->{MAKEFILEFH} )
130     || die "SCRAM: Template error --> ",$self->{TEMPLATE_OBJECT}->error;
131 muzaffar 1.5
132     $self->{MAKEFILEFH}->close();
133 sashby 1.2 }
134    
135     1;