ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/TemplateInterface.pm
Revision: 1.6.2.2.2.1
Committed: Wed Jun 18 10:29:04 2008 UTC (16 years, 10 months ago) by muzaffar
Content type: text/plain
Branch: SCRAM_V2_0
CVS Tags: V2_2_2, V2_2_2_pre4, V2_2_2_pre3, V2_2_2_pre2, V2_2_2_pre1, V2_2_2-pre1, V2_2_1, forV2_2_1, V2_2_0, sm100112, V2_1_4, V2_1_3, V2_1_2, V2_1_1, V2_1_0, V2_0_6, V2_0_5, V2_0_4, V2_0_4_relcand2, V2_0_4_relcand1, V2_0_3, V2_0_3_relcand3, V2_0_3_relcand2, V2_0_3_relcand1
Changes since 1.6.2.2: +18 -6 lines
Log Message:
basic support for big lib added, changes are minor and should not break any thing

File Contents

# Content
1 #____________________________________________________________________
2 # File: TemplateInterface.pm
3 #____________________________________________________________________
4 #
5 # Author: Shaun Ashby <Shaun.Ashby@cern.ch>
6 # Update: 2004-07-01 14:03:46+0200
7 # Revision: $Id: TemplateInterface.pm,v 1.6.2.2 2008/02/15 17:30:59 muzaffar Exp $
8 #
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 if (!-f $makefile)
54 {
55 if (!-f "$ENV{LOCALTOP}/$ENV{SCRAM_CONFIGDIR}/SCRAM/GMake/Makefile")
56 {
57 die "Missing $ENV{LOCALTOP}/$ENV{SCRAM_CONFIGDIR}/SCRAM/GMake/Makefile file.";
58 }
59 use File::Copy;
60 copy("$ENV{LOCALTOP}/$ENV{SCRAM_CONFIGDIR}/SCRAM/GMake/Makefile",$makefile) or die "Copy failed: $!";
61 utime 0,0,$makefile;
62 }
63
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 require SCRAM::Plugins::BuildRules;
83
84 $self->{TEMPLATE_OBJECT} = SCRAM::Plugins::BuildRules->new();
85 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 "branch" data is a
94 # TreeItem object:
95 $self->{TEMPLATE} = $data->template();
96 # Add required data accessed by key:
97 $self->{TEMPLATE_DATA}->{branch} = $data;
98 }
99
100 sub run()
101 {
102 use FileHandle;
103 my $self=shift;
104
105 my $item = $self->{TEMPLATE_DATA}->{branch};
106 my $file = $item->safepath().".mk";
107 if ($item->class() eq "PROJECT")
108 {
109 $file = "$ENV{LOCALTOP}/.SCRAM/$ENV{SCRAM_ARCH}/MakeData/${file}";
110 }
111 elsif ($item->publictype())
112 {
113 $file = "$ENV{LOCALTOP}/.SCRAM/$ENV{SCRAM_ARCH}/MakeData/DirCache/${file}";
114 $item->{MKDIR}{"$ENV{LOCALTOP}/.SCRAM/$ENV{SCRAM_ARCH}/MakeData/DirCache"}=1;
115 }
116 else
117 {
118 $file = "$ENV{LOCALTOP}/$ENV{SCRAM_INTwork}/MakeData/DirCache/${file}";
119 $item->{MKDIR}{"$ENV{LOCALTOP}/$ENV{SCRAM_INTwork}/MakeData/DirCache"}=1;
120 }
121
122 $self->{TEMPLATE_DATA}->{MAKEFILE} = $file;
123 $self->{TEMPLATE_DATA}->{MAKEFILEFH} = FileHandle->new();
124 $self->{TEMPLATE_DATA}->{MAKEFILEFH}->open(">$file");
125
126 #Change the interface for SCRAM V3 series for backward compatibility
127 #with V2 series we still need to keep this interface
128 $self->{TEMPLATE_OBJECT}->process($self->{TEMPLATE},
129 $self->{TEMPLATE_DATA},
130 $self->{TEMPLATE_DATA}->{MAKEFILEFH})
131 || die "SCRAM: Template error --> ",$self->{TEMPLATE_OBJECT}->error;
132
133 $self->{TEMPLATE_DATA}->{MAKEFILEFH}->close();
134 my $file1 = $self->{TEMPLATE_DATA}->{MAKEFILE};
135 if ($file ne $file1)
136 {
137 if (!-s $file1){unlink $file1;}
138 if ($file1=~/\/DirCache\/[^\/]+$/)
139 {
140 use File::Basename;
141 $item->{MKDIR}{dirname($file1)}=1;
142 }
143 }
144 }
145
146 1;