]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - vendor/update
Update the vendored http_parser library to v2.9.3.
[user/henk/code/inspircd.git] / vendor / update
1 #!/usr/bin/env perl
2 #
3 # InspIRCd -- Internet Relay Chat Daemon
4 #
5 #   Copyright (C) 2020 Sadie Powell <sadie@witchery.services>
6 #
7 # This file is part of InspIRCd.  InspIRCd is free software: you can
8 # redistribute it and/or modify it under the terms of the GNU General Public
9 # License as published by the Free Software Foundation, version 2.
10 #
11 # This program is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14 # details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19
20
21 BEGIN {
22         require 5.10.0;
23         unless (-f 'configure') {
24                 print "Error: $0 must be run from the main source directory!\n";
25                 exit 1;
26         }
27 }
28
29 use feature ':5.10';
30 use strict;
31 use warnings FATAL => qw(all);
32
33 use File::Basename        qw(basename dirname);
34 use File::Copy            qw(move);
35 use File::Spec::Functions qw(abs2rel catdir catfile);
36 use File::Temp            qw(tempdir);
37 use FindBin               qw($RealDir);
38 use POSIX                 qw(strftime);
39 use TOML                  qw(from_toml);
40
41 use lib dirname $RealDir;
42 use make::common;
43 use make::console;
44
45 my $config = catfile $RealDir, 'update.toml';
46 open(my $fh, $config) or print_error "unable to read $config: $!";
47 my $contents = do { local $/; <$fh> };
48 close $fh;
49
50 my ($data, $error) = from_toml $contents;
51 print_error "unable to parse $config: $!" if $error;
52
53 while (my ($name, $info) = each $data) {
54         print_format "Updating <|GREEN $name|> ...\n";
55
56         my $unpackdir = File::Temp->newdir;
57         my $vendordir = catdir $RealDir, $name;
58         my $success = 0;
59         if (defined $info->{git}) {
60                 $success ||= execute 'git', 'clone', $info->{git}, $unpackdir;
61                 chomp(my $tag = `git -C $unpackdir describe --abbrev=0 --tags HEAD 2>/dev/null`) unless $success;
62                 $success ||= execute 'git', '-C', $unpackdir, 'checkout', $tag if $tag;
63                 chomp($info->{version} = `git -C $unpackdir describe --always --tags HEAD 2>/dev/null`);
64         } elsif (defined $info->{tarball}) {
65                 my $tarball = catfile $unpackdir, basename $info->{tarball};
66                 $success ||= execute 'wget', '--output-document', $tarball, $info->{tarball};
67                 $success ||= execute 'tar', 'fx', $tarball, '-C', $unpackdir, '--strip-components', 1;
68         } else {
69                 print_error "unable to update $name; no git or tarball specified!";
70         }
71         print_error "unable to update $name: download failed!" if $success;
72
73         unlink $vendordir;
74         my $glob = $info->{files} or print_error "unable to update $name: no file glob specified!";
75         for my $file (glob catfile $unpackdir, $glob) {
76                 my $pathname = abs2rel $file, $unpackdir;
77                 for (my $i = 0; $i < ($info->{depth} // 0); ++$i) {
78                         $pathname =~ s/[^\/]+\///;
79                 }
80                 my $filename = catfile $vendordir, $pathname;
81                 my $dirname = dirname $filename;
82                 create_directory $dirname, 0750;
83                 move $file, $filename;
84         }
85 }
86
87 my $readme = catfile $RealDir, 'README.md';
88 open($fh, $readme) or print_error "unable to read $readme: $!";
89 $contents = do { local $/; <$fh> };
90 close $fh;
91
92 open($fh, '>', $readme) or print_error "unable to write $readme: $!";
93 print $fh $contents =~ s/\n\#\#.*//rs;
94 for my $name (sort keys $data) {
95         my $info = $data->{$name};
96         printf $fh "\n## %s\n\n", $name;
97         printf $fh "**Author** &mdash; [%s](mailto:%s)\n\n", $info->{author}, $info->{email} if $info->{email};
98         printf $fh "**Author** &mdash; %s\n\n", $info->{author} unless $info->{email};
99         printf $fh "**License** &mdash; %s\n\n", $info->{license};
100         printf $fh "**Version** &mdash; %s\n\n", $info->{version};
101         my $website = $info->{website} // $info->{git};
102         printf $fh "**Website** &mdash; [%s](%s)\n", $website, $website;
103 }
104 close $fh;