ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/ToolCache.pm
Revision: 1.4
Committed: Mon Sep 11 14:53:39 2006 UTC (18 years, 7 months ago) by sashby
Content type: text/plain
Branch: MAIN
CVS Tags: V1_2_1b, V1_2_1a, V1_2_3, V1_2_2, V1_2_2_relcand2, V1_2_2_relcand1, V1_2_1, V1_2_0, V1_2_0-cand11, V1_1_7, V1_1_6, V1_2_0-cand10, V1_1_5, V1_2_0-cand9, V1_2_0-cand8, V1_2_0-cand7, V1_2_0-cand6, V1_2_0-cand5, V1_2_0-cand4, V1_2_0-cand3, V1_2_0-cand2, V1_2_0-cand1, V1_1_4, V1_1_3, V1_1_2, V1_1_0_reltag8, V1_1_0_reltag7, V1_1_0_reltag6, V1_1_1, V1_1_0_reltag5, V1_1_0_reltag4, V1_1_0_reltag3, V1_1_0_reltag2, V1_1_0_reltag1, V1_1_0_reltag, V1_0_3-p4, V1_1_0_cand3, V1_1_0_cand2, V1_1_0_cand1, HEAD_SM_071214, forV1_1_0, v103_xml_071106, V1_0_3-p3, V1_0_3-p2, V1_1_0, v110p1, V110p6, V110p5, V110p4, V110p3, before110xmlBRmerge, V110p2, V110p1, V1_0_3-p1, V1_0_3
Branch point for: SCRAM_V2_0, forBinLess_SCRAM, HEAD_BRANCH_SM_071214, v200branch, v103_with_xml
Changes since 1.3: +1 -1 lines
Log Message:
merged from v103_branch

File Contents

# User Rev Content
1 sashby 1.2 #____________________________________________________________________
2     # File: ToolCache.pm
3     #____________________________________________________________________
4     #
5     # Author: Shaun Ashby <Shaun.Ashby@cern.ch>
6     # Update: 2003-10-28 10:14:08+0100
7 sashby 1.4 # Revision: $Id: ToolCache.pm,v 1.2.2.1 2006/05/17 12:11:39 sashby Exp $
8 sashby 1.2 #
9     # Copyright: 2003 (C) Shaun Ashby
10     #
11     #--------------------------------------------------------------------
12     package BuildSystem::ToolCache;
13     require 5.004;
14    
15     use Exporter;
16     @ISA=qw(Exporter);
17     #
18     sub new()
19     {
20     my $proto=shift;
21     my $class=ref($proto) || $proto;
22     my $self =
23     {
24     DOWNLOADED => { tools => undef, url => undef }, # Downloaded tool infos;
25     SELECTED => undef, # The selected tools (info from RequirementsDoc);
26     DEFAULTVERSIONS => {}, # Hash of tools and their default version;
27     RAW => [], # The tools to be set up (the raw data from the tool docs);
28     SETUP => {}, # The saved set-up data;
29     STAMP => undef # The last time the cache was modified
30     };
31    
32     bless $self,$class;
33     return $self;
34     }
35    
36     sub downloadedtools()
37     {
38     my $self=shift;
39     # Returns an array of downloaded tools, basically all
40     # those listed in configuration:
41     @_ ? $self->{DOWNLOADED}{tools} = shift #
42     : $self->{DOWNLOADED}{tools};
43     }
44    
45     sub defaultversions()
46     {
47     my $self=shift;
48     # Returns a hash of tools and their default versions:
49     @_ ? $self->{DEFAULTVERSIONS} = shift #
50     : $self->{DEFAULTVERSIONS};
51     }
52    
53     sub toolurls()
54     {
55     my $self=shift;
56     # Returns a hash of tools and their URLs:
57     @_ ? $self->{DOWNLOADED}->{url} = shift #
58     : $self->{DOWNLOADED}->{url};
59     }
60    
61     sub selected()
62     {
63     my $self=shift;
64     # Returns hash of selected tools:
65     @_ ? $self->{SELECTED} = $_[0]
66     : $self->{SELECTED};
67     }
68    
69     sub addtoselected()
70     {
71     my $self=shift;
72     my ($toolname)=@_;
73     # When "scram setup X" is used to add new tool to environment, we need a way to add this tool
74     # to the list of selected tools. Otherwise, runtime env won't work.
75     # Need to check to see if this tool already exists in the SELECTED hash.
76     # Only try to add a new rank if tool doesn't already exist:
77     if (! exists $self->{SELECTED}->{$toolname})
78     {
79     # First, check the highest rank (just number of elements [i.e., keys in hash]). Next
80     # tool added will get next number:
81     my $nextrank = (keys %{$self->{SELECTED}}) + 1;
82     $self->{SELECTED}->{$toolname} = $nextrank;
83     }
84     }
85    
86     sub store()
87     {
88     my $self=shift;
89     # Store ToolParser objects (tools not set up yet):
90     @_ ? push(@{$self->{RAW}},@_) #
91     : @{$self->{RAW}};
92     }
93    
94     sub rawtools()
95     {
96     my $self=shift;
97     # Return a list of tools
98     return @{$self->{RAW}};
99     }
100    
101     sub setup()
102     {
103     my $self=shift;
104     # Returns a hash of toolname/ToolData objects (set-up tools):
105     return $self->{SETUP};
106     }
107    
108     sub cleanup_raw()
109     {
110     my $self=shift;
111     my ($tremoved)=@_;
112     my $newrtools=[];
113    
114     # Remove the tool from the list of raw tool objects:
115     foreach my $rawtool (@{$self->{RAW}})
116     {
117     # Find the tool name from the ToolParser object $rawtool:
118     if ($tremoved eq $rawtool->toolname())
119     {
120     print "Removing ToolParser $tremoved from cache.","\n";
121     }
122     else
123     {
124     push(@{$newrtools},$rawtool);
125     }
126     }
127    
128     # Remove from list of selected tools and version list:
129     delete $self->{SELECTED}->{$tremoved};
130     delete $self->{DEFAULTVERSIONS}->{$tremoved};
131     # Now save the new tool list:
132     $self->{RAW} = $newrtools;
133     }
134    
135     sub inheritcontent()
136     {
137     my $self=shift;
138     my ($externaltm)=@_;
139    
140     # Inherit all tool data from an external scram-managed project.
141     # Basically copy RAW, SETUP and SELECTED hash data:
142     $self->{RAW} = [ $externaltm->rawtools() ];
143     $self->{SETUP} = $externaltm->setup();
144    
145     my $tmpselected = $externaltm->selected();
146    
147 sashby 1.3 # We add the downloaded SELECTED entries to our existing SELECTED data
148 sashby 1.2 # in the same order as they already appear:
149     foreach my $entry ( sort { %{$tmpselected}->{$a}
150     <=> %{$tmpselected}->{$b}}
151     keys %{$tmpselected} )
152     {
153     # Now add them to selected data:
154     $self->addtoselected($entry);
155     }
156     }
157    
158     ### Read/write from/to cachefile:
159     sub name()
160     {
161     my $self = shift;
162     # Set the name of the cache file:
163     @_ ? $self->{CACHENAME} = shift #
164     : $self->{CACHENAME};
165     }
166    
167     sub writecache()
168     {
169     my $self=shift;
170     use Cache::CacheUtilities;
171     &Cache::CacheUtilities::write($self,$self->{CACHENAME});
172     }
173    
174     1;
175