ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/TemplateInterface.pm
Revision: 1.5
Committed: Tue Nov 6 14:13:49 2007 UTC (17 years, 6 months ago) by muzaffar
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD_SM_071214, v103_xml_071106
Branch point for: HEAD_BRANCH_SM_071214
Changes since 1.4: +34 -4 lines
Log Message:
xml scram with changes to make it fast

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.5 # Revision: $Id: TemplateInterface.pm,v 1.2.4.2 2006/12/04 14:26:35 sashby 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     if (!-f "$ENV{LOCALTOP}/$ENV{SCRAM_CONFIGDIR}/Makefile.head")
56     {
57     die "Missing $ENV{LOCALTOP}/$ENV{SCRAM_CONFIGDIR}/Makefile.head file.";
58     }
59     use File::Copy;
60     copy("$ENV{LOCALTOP}/$ENV{SCRAM_CONFIGDIR}/Makefile.head",$makefile) or die "Copy failed: $!";
61     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     # Set the location where the templates may be found:
75     $self->template_dir($templatedir);
76     # Configure the template object:
77     $self->template_config();
78     # Create the new Template object:
79     $self->template_object();
80     return $self;
81     }
82    
83     sub template_object()
84     {
85     my $self=shift;
86    
87     # Instantiate a new Template object:
88     eval("use Template");
89    
90     if ($@)
91     {
92     print "\nSCRAM Error: It appears that the module \"Template.pm\" is not installed.","\n";
93     print " Please check your installaion. If you are an administrator,","\n";
94     print " you can find the Perl Template Toolkit at www.cpan.org or at","\n";
95     print " the web site of the author (Andy Wardley):","\n";
96     print "\n";
97     print " www.template-toolkit.com","\n";
98     print "\n";
99     print " You should install version 2.xx (2.13 or better).","\n";
100     print "\nscram-developers\@cern.ch","\n\n";
101     exit(1);
102     }
103     else
104     {
105     $self->{TEMPLATE_OBJECT} = Template->new($self->{TEMPLATE_CONFIG});
106     }
107    
108     return $self;
109     }
110    
111     sub template_dir()
112     {
113     my $self=shift;
114 sashby 1.4 my ($templatedir)=@_;
115     my $dir = $ENV{LOCALTOP}."/".$ENV{SCRAM_CONFIGDIR};
116     if ((exists $ENV{SCRAM_PROJECT_TEMPLATEDIR}) &&
117     ($ENV{SCRAM_PROJECT_TEMPLATEDIR} !~ /^\s*$/)) {
118     $dir = $ENV{SCRAM_PROJECT_TEMPLATEDIR};
119 sashby 1.3 }
120 sashby 1.4 $templatedir ||= $dir;
121 sashby 1.2 $self->{TEMPLATE_DIR} = $templatedir;
122     return $self;
123     }
124    
125     sub template_config()
126     {
127     my $self=shift;
128     # Set up Template opts:
129     $self->{TEMPLATE_CONFIG} =
130     {
131 sashby 1.3 INCLUDE_PATH => [ "$self->{TEMPLATE_DIR}","$ENV{LOCALTOP}/$ENV{SCRAM_CONFIGDIR}" ],
132 sashby 1.4 PLUGIN_BASE => [ qw(SCRAM::Plugins BuildSystem::Template::Plugins) ],
133     EVAL_PERL => 1,
134     ABSOLUTE => 1
135     };
136 sashby 1.2
137     return $self;
138     }
139    
140     sub template_data()
141     {
142     my $self=shift;
143     my ($data) = @_;
144    
145     # Set the things that we must set. The "data" key points
146     # to a DataCollector object. The "branch" data is a
147     # TreeItem object:
148     $self->{TEMPLATE} = $data->template();
149     # Add required data accessed by key:
150     $self->{TEMPLATE_DATA}->{branch} = $data;
151     }
152    
153     sub run()
154     {
155 muzaffar 1.5 use FileHandle;
156 sashby 1.2 my $self=shift;
157 muzaffar 1.5
158     my $item = $self->{TEMPLATE_DATA}->{branch};
159     my $file = $item->safepath().".mk";
160     if ($item->class() eq "PROJECT")
161     {
162     $file = "$ENV{LOCALTOP}/.SCRAM/$ENV{SCRAM_ARCH}/MakeData/${file}";
163     }
164     elsif ($item->publictype())
165     {
166     $file = "$ENV{LOCALTOP}/.SCRAM/$ENV{SCRAM_ARCH}/MakeData/DirCache/${file}";
167     $item->{MKDIR}{"$ENV{LOCALTOP}/.SCRAM/$ENV{SCRAM_ARCH}/MakeData/DirCache"}=1;
168     }
169     else
170     {
171     $file = "$ENV{LOCALTOP}/$ENV{SCRAM_INTwork}/MakeData/DirCache/${file}";
172     $item->{MKDIR}{"$ENV{LOCALTOP}/$ENV{SCRAM_INTwork}/MakeData/DirCache"}=1;
173     }
174    
175     $self->{MAKEFILEFH} = FileHandle->new();
176     $self->{MAKEFILEFH}->open(">$file");
177 sashby 1.2 local *FH = $self->{MAKEFILEFH};
178    
179     $self->{TEMPLATE_OBJECT}->process($self->{TEMPLATE},
180     $self->{TEMPLATE_DATA},
181     $self->{MAKEFILEFH} )
182     || die "SCRAM: Template error --> ",$self->{TEMPLATE_OBJECT}->error;
183 muzaffar 1.5
184     $self->{MAKEFILEFH}->close();
185 sashby 1.2 }
186    
187     1;