ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildableProduct.pm
Revision: 1.1
Committed: Fri Dec 17 11:02:27 1999 UTC (25 years, 4 months ago) by williamc
Content type: text/plain
Branch: MAIN
CVS Tags: ProtoEnd
Log Message:
Not tested

File Contents

# User Rev Content
1 williamc 1.1 #
2     # BuildableProduct.pm
3     #
4     # Originally Written by Christopher Williams
5     #
6     # Description
7     # -----------
8     # a base class to provide dependency checking functionality for any object
9     #
10     # Interface
11     # ---------
12     # new() : A new BuildableProduct object
13     # update() : update the object if required
14     # dependency(BuildableProduct): add a dependency
15     # build() : build the object
16     # state() : return a string to identify the current
17     # state of the object - by default assumed to be a# file
18     # stateref() : return the state reference of the object after
19     # the last succesful build
20     # id([string]) : get/set the id/filename
21    
22     package BuildSystem::BuildableProduct;
23     require 5.004;
24     @ISA=qw(ObjectUtilities::StorableObject);
25    
26     sub init {
27     my $self=shift;
28     $self->{updating}=0;
29     }
30    
31     #
32     # return values 0=no change, 1= sucessful change, 2=update failed
33     # 3 = update in progress - recursive stoppoint
34     #
35     sub update {
36     my $self=shift;
37    
38     my $rv=0;
39     my $rverror=0;
40     my @strings=();
41     my needupdate=0;
42    
43     # -- check were not in a recursive process
44     return 3 , if ( $self->{updating} == 1 );
45     $self->{updating}=1; # lock updating process
46    
47     # -- check self
48     if ( $self->stateref() != $self->state() );
49    
50     # -- check dependencies
51     my $obj, $v;
52     for (my $i=0; $i<=$#{$self->{dependencies}}; $i++ ) {
53     $obj=$self->{dependencies}[$i];
54     # first make sure they are up to date
55     $obj->update();
56     # are they different from the ones we used to build last time
57     if ( $obj->state() != $self->{dependencystate}[$i] ) {
58     $needupdate=1;
59     }
60    
61     }
62    
63     # --- build
64     if ( $needupdate ) {
65     my ($stat,@buildstring)=$self->build();
66     if ( ! $stat ) {
67     $rv=1;
68     # Build Successful - must update dependency stats
69     for (my $i=0; $i<=$#{$self->{dependencies}}; $i++ ) {
70     $obj=$self->{dependencies}[$i];
71     $self->{dependencystate}[$i]=$obj->state();
72     }
73     }
74     else {
75     push @strings, @buildstring;
76     $rv=2;
77     }
78     }
79     $self->{updating}=0; # unlock updating process
80     return $rv, @strings;
81     }
82    
83     sub dependency {
84     my $self=shift;
85     my $object=shift;
86    
87     push @{$self->{dependencies}}, $object;
88     }
89    
90     sub stateref {
91     my $self=shift;
92     @_?$self->{stateref}=shift
93     :$self->{stateref};
94     }
95    
96     sub id {
97     my $self=shift;
98     @_?$self->{id}=shift
99     :$self->{id};
100     }
101    
102     #
103     # By default assumes a file but easy to override for other types
104     #
105     sub state {
106     my $self=shift;
107     my $moddate=0;
108    
109     # if id is a filename, take its last modification date
110     if ( -f $self->id() ) {
111     $moddate=(stat($self->id()))[9];
112     }
113    
114     return $moddate;
115     }
116    
117     # --------- Persistency Stuff -----------------
118    
119     sub store {
120     my $self=shift;
121     my $location=shift;
122     local $fh=$self->openfile(">".$location);
123     $self->_storedeps($fh);
124     undef $fh;
125     }
126    
127     sub restore {
128     my $self=shift;
129     my $location=shift;
130     local $fh=$self->openfile("<".$location);
131     $self->_restoredeps($fh);
132     undef $fh;
133     }
134    
135     #
136     # Store dependency information
137     #
138     sub _storedeps {
139     my $self=shift;
140     my $fh=shift;
141    
142     print $fh $self->{stateref};
143     for (my $i=0; $i<=$#{$self->{dependencies}}; $i++ ) {
144     print $fh "DEP=".$self->{dependencies}[$i]->id()."\n";
145     print $fh $self->{dependencystat}[$i]."\n";
146     }
147     }
148    
149     sub _restoredeps {
150     my $self=shift;
151     my $fh=shift;
152    
153     my $id;
154     $self->{stateref}=<$fh>;
155     chomp $self->{stateref};
156     while ( ($line=<$fh>)=~/^DEP=/ ) {
157     chomp $line;
158     ($id=$line)=~s/^DEP=//;
159     push @$self->{dependencies}, ($self->ActiveStore()->find("BPS",$id));
160     push @$self->{dependencystat}, <$fh>;
161     }
162     chomp @$self->{dependencystat};
163     }