forked from rogerclarkmelbourne/Arduino_STM32
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpackage
More file actions
executable file
·213 lines (172 loc) · 6.39 KB
/
package
File metadata and controls
executable file
·213 lines (172 loc) · 6.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/perl -w
# Takes no arguments, operates on the file web/testing.json
# The first run, you will need a copy of web/testing.json that already has the target
# platforms and tools
#
# This tool creates the zip files for the various targets (STM32F1, STM32F3, STM32F4)
# And also creates the zip or tar.gz files for the various hosts (win, linux, macosx)
#
# After it is done, copy the files in web/ to your webserver's directory in $base_url.
# The rsync tool can make this easier
#
# packages needed to run under cygwin/Windows:
# zip, coreutils, tar, perl, perl_base, perl-JSON-XS, perl-Clone
# packages needed to run under Fedora:
# zip, coreutils, tar, perl, perl-JSON-XS, perl-Clone
# packages needed to run under Debian/Ubuntu:
# zip, coreutils, tar, perl, perl-modules, libjson-xs-perl, libclone-perl
# configurable settings
#######################
my $base_url = "http://dan.drown.org/arduino/";
my(@target_list) = ("STM32F1", "STM32F3", "STM32F4");
my(@host_list) = ("win", "linux", "linux64", "macosx");
my $json_file = "web/testing.json";
my $destination_dir = "web/";
# libraries
#######################
use strict;
use File::stat;
use JSON::XS qw(encode_json decode_json);
use Clone qw(clone);
# code starts here
#######################
sub zip {
my($directory, $version) = @_;
my $base_filename = $directory;
$base_filename =~ s!/!_!g;
my $zipfile = $destination_dir."$base_filename-$version.zip";
unlink($zipfile);
system("zip -r $zipfile $directory");
my $sha256 = `sha256sum $zipfile`;
$sha256 =~ s/ .*//s;
my $filestats = stat($zipfile);
$zipfile =~ s@$destination_dir@@;
return { filename => $zipfile, sha256 => $sha256, size => $filestats->size() };
}
sub tar_gz {
my($directory, $version) = @_;
my $base_filename = $directory;
$base_filename =~ s!/!_!g;
my $tarfile = $destination_dir."$base_filename-$version.tar.gz";
unlink($tarfile);
system("tar zcf $tarfile --group=stm32 --owner=stm32 $directory");
my $sha256 = `sha256sum $tarfile`;
$sha256 =~ s/ .*//s;
my $filestats = stat($tarfile);
$tarfile =~ s@$destination_dir@@;
return { filename => $tarfile, sha256 => $sha256, size => $filestats->size() };
}
sub read_json {
my($filename) = @_;
open(JSON, "<", $filename) or die("error opening $filename: $!");
my($data) = decode_json(join("",<JSON>));
close(JSON);
return $data;
}
sub write_json {
my($data,$filename) = @_;
my $json = JSON::XS->new->pretty;
open(JSON, ">", "$filename.tmp") or die("unable to write temporary file: $!");
print JSON $json->encode($data)."\n";
close(JSON);
rename("$filename.tmp",$filename);
}
sub prepare_platform_pkg {
my($old_platforms,$targets,$version) = @_;
my(@new_records);
foreach my $target (keys %$targets) {
if(not defined $old_platforms->{$target}) {
die("target $target not found in the previous version's list of targets");
}
my $new_version = clone($old_platforms->{$target});
$new_version->{version} = $version;
$new_version->{url} = $base_url.$targets->{$target}{filename};
$new_version->{archiveFileName} = $targets->{$target}{filename};
$new_version->{checksum} = "SHA-256:".$targets->{$target}{sha256};
$new_version->{size} = $targets->{$target}{size};
for(my $i = 0; $i < @{$new_version->{toolsDependencies}}; $i++) {
if($new_version->{toolsDependencies}[$i]{name} eq "stm32tools") {
$new_version->{toolsDependencies}[$i]{version} = $version;
last;
}
}
push(@new_records, $new_version);
}
return \@new_records;
}
sub prepare_tools_pkg {
my($old_version_number,$new_version_number,$tool_data,$tool_archives) = @_;
my($new_tools);
for(my $i = 0; $i < @$tool_data; $i++) {
if($tool_data->[$i]{name} eq "stm32tools" and $tool_data->[$i]{version} eq $old_version_number) {
$new_tools = clone($tool_data->[$i]);
last;
}
}
if(not ref($new_tools)) {
die("unable to find version $old_version_number of tools stm32tools");
}
$new_tools->{version} = $new_version_number;
for(my $i = 0; $i < @{$new_tools->{systems}}; $i++) {
my $tool_archive;
if($new_tools->{systems}[$i]{host} eq "i686-mingw32") {
$tool_archive = $tool_archives->{win};
} elsif($new_tools->{systems}[$i]{host} =~ /^(x86_64|i386)-apple-darwin$/) {
$tool_archive = $tool_archives->{macosx};
} elsif($new_tools->{systems}[$i]{host} =~ /^i686-pc-linux-gnu$/) {
$tool_archive = $tool_archives->{linux};
} elsif($new_tools->{systems}[$i]{host} =~ /^x86_64-pc-linux-gnu$/) {
$tool_archive = $tool_archives->{linux64};
} else {
die("unknown tool pkg host: ".$new_tools->{systems}[$i]{host});
}
$new_tools->{systems}[$i]{url} = $base_url.$tool_archive->{filename};
$new_tools->{systems}[$i]{archiveFileName} = $tool_archive->{filename};
$new_tools->{systems}[$i]{checksum} = "SHA-256:".$tool_archive->{sha256};
$new_tools->{systems}[$i]{size} = $tool_archive->{size};
}
return $new_tools;
}
sub new_version {
my($old_version) = @_;
my($major,$minor,$release) = split(/\./,$old_version,3);
$release++;
return "$major.$minor.$release";
}
sub last_target_platforms {
my($testing_pkgs,$version_number) = @_;
my(%target_platforms);
foreach my $platform (@{$testing_pkgs->{packages}{platforms}}) {
if($platform->{version} eq $version_number and $platform->{category} eq "STM32") {
$target_platforms{$platform->{architecture}} = $platform;
}
}
return \%target_platforms;
}
sub main {
my($testing_pkgs) = read_json($json_file);
my $lastversion = $testing_pkgs->{packages}{platforms}[-1]{version};
my($last_target_platforms) = last_target_platforms($testing_pkgs, $lastversion);
my $version = new_version($lastversion);
my(%targets);
foreach my $target (@target_list) {
my($target_zip) = zip($target,$version);
$targets{$target} = $target_zip;
}
my(%tools);
foreach my $host (@host_list) {
my($tool_zip);
if($host eq "win") {
$tool_zip = zip("tools/$host",$version);
} else {
$tool_zip = tar_gz("tools/$host",$version);
}
$tools{$host} = $tool_zip;
}
my($new_version) = prepare_platform_pkg($last_target_platforms, \%targets, $version);
my($new_tools) = prepare_tools_pkg($lastversion, $version, $testing_pkgs->{packages}{tools}, \%tools);
push(@{$testing_pkgs->{packages}{platforms}}, @$new_version);
push(@{$testing_pkgs->{packages}{tools}}, $new_tools);
write_json($testing_pkgs,$json_file);
}
main();