4 # Usage: buildtoolbox.pl toolbox-archive [toolbox-name]
9 my ($TOOLBOXFILE, # Toolbox archive to compile
10 $TOOLBOXNAME); # Name of the toolbox
13 # Return true if toolbox file extension is zip
15 return $TOOLBOXFILE =~ /\.zip$/;
19 # Get all files (names) of the compressed (in tar.gz) sources
20 sub get_tree_from_tgz {
23 open my $fd, "tar -tzf ${TOOLBOXFILE}|";
24 push(@files, $_) while <$fd>;
31 # Get all files (names) of the compressed (in zip) sources
32 sub get_tree_from_zip {
35 # tail & head are here to skip header & footer
36 open my $fd, "unzip -l ${TOOLBOXFILE} | tail -n +4 | head -n -2 |";
39 # output format: size date time filename
40 /\s*\d+\s+\d+-\d+-\d+\s+\d+:\d+\s+(.+)/ or die "Bad output of unzip";
50 # Get all files (names) of the compressed sources
53 return get_tree_from_zip();
56 return get_tree_from_tgz();
60 # get_description_from_tgz:
61 # Extract DESCRIPTION file from the archive (in tar.gz format)
62 sub get_description_from_tgz {
63 open my $fd, "tar -xOzf ${TOOLBOXFILE} ${TOOLBOXNAME}/DESCRIPTION |";
67 # get_description_from_tgz:
68 # Extract DESCRIPTION file from the archive (in zip format)
69 sub get_description_from_zip {
70 open my $fd, "unzip -c ${TOOLBOXFILE} ${TOOLBOXNAME}/DESCRIPTION | tail -n +3 | head -n -1 |";
75 # Extract DESCRIPTION file from the archive
78 return get_description_from_zip();
81 return get_description_from_tgz();
86 # Check if DESCRIPTION file is correct, and parse it (return a hash
88 # First argument is a file descriptor for the DESCRIPTION file (see
90 sub read_description {
92 my @required = qw(Toolbox Version Title Author Maintainer
93 Description License Category);
94 my @optional = qw(Date Depends URL Entity);
95 my (%infos, $key, $val);
96 my (%lines, %correct);
100 die "\":\" not followed by a space at line $." if(/:(?! )/);
101 if(/:/) { # New field
102 ($key, $val) = split(/: /, $_, 2);
107 else { # Continuation of previous field
112 # Check presence of required fields, mark them as correct
113 foreach (@required) {
114 if(!defined($infos{$_})) {
115 die "Mandatory field \"$_\" not defined";
122 # Mark optional fields as correct
123 foreach (@optional) {
124 if(defined($infos{$_})) {
129 # Check that there's no incorrect (= unknown) fields
130 foreach (keys(%infos)) {
131 if($correct{$_} == 0) {
132 die "Unknown field \"$_\" (defined at line $lines{$_})";
143 # 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...)
150 foreach (@_) { print "=> $_ \n"; };
153 #~ # Make a hash from the tree (paths are keys, values are all to 1)
154 #~ $treehash{$_} = 1;
156 #~ # Check that all files are under a root which has the same name as the toolbox
157 #~ if(!m#^\Q$TOOLBOXNAME\E/#) {
158 #~ die "Incorrect archive: \"$_\" is not a child of \"$TOOLBOXNAME\"";
162 #~ # Check that basic files are here
163 #~ my @required = qw(DESCRIPTION DESCRIPTION-FUNCTIONS readme.txt license.txt
164 #~ builder.sce loader.sce);
165 #~ push(@required, "etc/$TOOLBOXNAME.start");
166 #~ push(@required, "etc/$TOOLBOXNAME.end");
168 #~ foreach (@required) {
169 #~ print "$TOOLBOXNAME/$_\n";
171 #~ if(!defined($treehash{"$TOOLBOXNAME/$_"})) {
172 #~ die "Incorrect archive: required file \"$_\" not present";
177 # Init global vars, check arguments
178 $TOOLBOXFILE = shift;
179 if(!defined($TOOLBOXFILE)) {
180 die "Toolbox source file required";
183 if(! -r $TOOLBOXFILE) {
184 die "$TOOLBOXFILE doesn't exists or can't be read";
187 $TOOLBOXNAME = shift || $1 if ($TOOLBOXFILE =~ /^([^.]+)/);
192 my @tree = get_tree();
194 check_tree(@tree, 1);