summaryrefslogtreecommitdiffstats
path: root/atoms_cc
diff options
context:
space:
mode:
authorSimon Lipp <simon.lipp@scilab.org>2008-06-25 16:00:38 +0000
committerSimon Lipp <simon.lipp@scilab.org>2008-06-25 16:00:38 +0000
commit1dfb8c5fa73e81d71618f0670880d850efcb8ccd (patch)
tree0c11af9684e6a680bf4dc9eeb68f41260e25e12e /atoms_cc
parent18edf384f213a32893f9b83a446a6079f4a0accb (diff)
downloadscilab-1dfb8c5fa73e81d71618f0670880d850efcb8ccd.zip
scilab-1dfb8c5fa73e81d71618f0670880d850efcb8ccd.tar.gz
atoms_cc/buildtoolbox.pl:
* correct usage (see wiki:atoms_cc) * get_tree* returns a hash (easier to use, said Pierre) * no \n in filenames * get check_tree working (not finished)
Diffstat (limited to 'atoms_cc')
-rwxr-xr-xatoms_cc/buildtoolbox.pl80
1 files changed, 36 insertions, 44 deletions
diff --git a/atoms_cc/buildtoolbox.pl b/atoms_cc/buildtoolbox.pl
index 8235597..827e726 100755
--- a/atoms_cc/buildtoolbox.pl
+++ b/atoms_cc/buildtoolbox.pl
@@ -1,7 +1,7 @@
1#!/usr/bin/perl -w 1#!/usr/bin/perl -w
2 2
3# buildtoolbox.pl 3# buildtoolbox.pl
4# Usage: buildtoolbox.pl toolbox-archive [toolbox-name] 4# Usage: buildtoolbox.pl toolbox-archive [config file [stage]]
5 5
6use strict; 6use strict;
7use Cwd; 7use Cwd;
@@ -18,36 +18,41 @@ sub is_zip {
18# get_tree_from_tgz: 18# get_tree_from_tgz:
19# Get all files (names) of the compressed (in tar.gz) sources 19# Get all files (names) of the compressed (in tar.gz) sources
20sub get_tree_from_tgz { 20sub get_tree_from_tgz {
21 my (@files); 21 my %files;
22 22
23 open my $fd, "tar -tzf ${TOOLBOXFILE}|"; 23 open my $fd, "tar -tzf ${TOOLBOXFILE}|";
24 push(@files, $_) while <$fd>; 24
25 chomp(@files); 25 while(<$fd>) {
26 chomp;
27 $files{$_} = 1;
28 }
29
26 close $fd; 30 close $fd;
27 return @files; 31 return %files;
28} 32}
29 33
30# get_tree_from_zip: 34# get_tree_from_zip:
31# Get all files (names) of the compressed (in zip) sources 35# Get all files (names) of the compressed (in zip) sources
32sub get_tree_from_zip { 36sub get_tree_from_zip {
33 my (@files, $line); 37 my (%files, $line);
34 38
35 # tail & head are here to skip header & footer 39 # tail & head are here to skip header & footer
36 open my $fd, "unzip -l ${TOOLBOXFILE} | tail -n +4 | head -n -2 |"; 40 open my $fd, "unzip -l ${TOOLBOXFILE} | tail -n +4 | head -n -2 |";
37 41
38 while(<$fd>) { 42 while(<$fd>) {
39 # output format: size date time filename 43 # zip output format: size date time filename
40 /\s*\d+\s+\d+-\d+-\d+\s+\d+:\d+\s+(.+)/ or die "Bad output of unzip"; 44 /\s*\d+\s+\d+-\d+-\d+\s+\d+:\d+\s+(.+)/ or die "Bad output of unzip";
41 push(@files, $1); 45 chomp $1;
46 $files{$1} = 1;
42 } 47 }
43 48
44 chomp(@files);
45 close $fd; 49 close $fd;
46 return @files; 50 return %files;
47} 51}
48 52
49# get_tree: 53# get_tree:
50# Get all files (names) of the compressed sources 54# Get all files (names) of the compressed sources, in a hash
55# (hash values are meaningless, set to 1)
51sub get_tree { 56sub get_tree {
52 if(is_zip()) { 57 if(is_zip()) {
53 return get_tree_from_zip(); 58 return get_tree_from_zip();
@@ -137,41 +142,32 @@ sub read_description {
137 return %infos; 142 return %infos;
138} 143}
139 144
140
141
142# check_tree: 145# check_tree:
143# Given a source tree of a toolbox (see get_tree), check if it is correct 146# Given a source tree of a toolbox (see get_tree), check if it is correct
144# (required files are present, files are at their right place, and so on...) 147# (required files are present, files are at their right place, and so on...)
145sub check_tree { 148sub check_tree {
146 #~ my @tree = shift; 149 my %tree = @_;
147 #~ my %treehash;
148 150
149 #~ print "$#tree\n"; 151 # Check that all files are under a root which has the same name as the toolbox
150 foreach (@_) { print "=> $_ \n"; }; 152 foreach (keys %tree) {
153 if(!m#^\Q$TOOLBOXNAME\E/#) {
154 die "Incorrect archive: \"$_\" is not a child of \"$TOOLBOXNAME\"";
155 }
156 }
151 157
152 #~ foreach (@tree) { 158 # Check that basic files are here
153 #~ # Make a hash from the tree (paths are keys, values are all to 1) 159 my @required = qw(DESCRIPTION DESCRIPTION-FUNCTIONS readme.txt license.txt
154 #~ $treehash{$_} = 1; 160 builder.sce loader.sce);
155 161 push(@required, "etc/$TOOLBOXNAME.start");
156 #~ # Check that all files are under a root which has the same name as the toolbox 162 push(@required, "etc/$TOOLBOXNAME.end");
157 #~ if(!m#^\Q$TOOLBOXNAME\E/#) {
158 #~ die "Incorrect archive: \"$_\" is not a child of \"$TOOLBOXNAME\"";
159 #~ }
160 #~ }
161 163
162 #~ # Check that basic files are here 164 foreach (@required) {
163 #~ my @required = qw(DESCRIPTION DESCRIPTION-FUNCTIONS readme.txt license.txt 165 if(!defined($tree{"$TOOLBOXNAME/$_"})) {
164 #~ builder.sce loader.sce); 166 die "Incorrect archive: required file \"$_\" not present";
165 #~ push(@required, "etc/$TOOLBOXNAME.start"); 167 }
166 #~ push(@required, "etc/$TOOLBOXNAME.end"); 168 }
167 169
168 #~ foreach (@required) { 170 #
169 #~ print "$TOOLBOXNAME/$_\n";
170 #~ print %treehash;
171 #~ if(!defined($treehash{"$TOOLBOXNAME/$_"})) {
172 #~ die "Incorrect archive: required file \"$_\" not present";
173 #~ }
174 #~ }
175} 171}
176 172
177# Init global vars, check arguments 173# Init global vars, check arguments
@@ -184,12 +180,8 @@ if(! -r $TOOLBOXFILE) {
184 die "$TOOLBOXFILE doesn't exists or can't be read"; 180 die "$TOOLBOXFILE doesn't exists or can't be read";
185} 181}
186 182
187$TOOLBOXNAME = shift || $1 if ($TOOLBOXFILE =~ /^([^.]+)/); 183$TOOLBOXNAME = $1 if ($TOOLBOXFILE =~ /^([^.]+)/);
188
189
190
191 184
192my @tree = get_tree();
193 185
194check_tree(@tree, 1); 186check_tree(get_tree());
195 187