File: update-bizarre

package info (click to toggle)
rust-derive-deftly 1.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,652 kB
  • sloc: perl: 1,032; sh: 373; python: 227; makefile: 11
file content (164 lines) | stat: -rwxr-xr-x 3,857 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl -w
#
# usage:
#   maint/update-bizarre [--check]
#
# Updates the Cargo.toml files in tests/pub-export/bizarre-*
# from the main ones in /Cargo.toml and /macros/Cargo.toml.
#
# Also, updates tests/compat/old-b/old-b.rs
# from tests/pub-export/pub-b.rs
#
our $explanation_xref = <<'END';
# See tests/pub-export/pub-b/pub-b.rs for the general explanation
# of the bizarre-* crates.
END
#
# We do it like this mostly because build.rs cannot generate Cargo.toml's.
# So we would need to have a completely autogenerated crate and re-invoke
# cargo build / cargo test from the test case.
#
# That is best avoided where possible, because it results in compile errors
# etc. pointing to autogenerated files, and makes it much harder to
# see what is going on in the test output.

use Carp;
use Getopt::Long;

our $check;

GetOptions(
	   "check" => \$check,
	  )
  or die("$0: bad usage\n");

our $bizvsn = '0.0.666';
our $found_differences = 0;
our ($input, $output);

sub filter_start ($$$) {
    die if defined $input;
    $input = shift @_;
    $output = shift @_;
    my ($header) = @_;
    
    open I, $input or confess "$input: $!";
    open O, ">$output.new" or confess "$output: $!";
    print O $header or confess $!;
}

sub filter_finish () {
    I->error and confess $!;
    O->error and confess $!;
    close O or confess $!;

    if ($check) {
	my $r = system 'diff', '-u', "$output", "$output.new";
	$r == 0 || $r == 256 || confess 'diff failed';
	if ($r) {
	    $found_differences ||= 1;
	} else {
	    unlink "$output.new" or confess $!;
	}
    } else {
	rename "$output.new", "$output" or confess "$input: $!";
    }

    $input = undef;
}

sub process_cargo_toml ($$$$$) {
    my ($input, $output, $src_path, $in_features, $before_lib) = @_;
(sub { # anonymous subref has its own `...` operator state

    filter_start $input, $output, <<END;
# WARNING - AUTOMATICALLY GENERATED
# This file is generated by maint/update-bizarre from $input
$explanation_xref
END

    my $pkg;

    my $had_lib;
    my $in_lib = <<END;
path = "../../../$src_path"
doc = false
doctest = false
END

    while (<I>) {
	next if m{^\s*\#};
	s{(\S)[ \t]+}{$1 }g;
	s{\s+$}{\n};
	if (m{^\[package\]}...m{^\[}) {
	    s{^name ?= ?"([^"]+)"$}{name = "bizarre-$1"} and $pkg=$1;
	    s{^version ?=.*}{version = "$bizvsn"};
	    s{^(?:homepage|repository|readme) ?=.*\n}{};
	    $_ = <<END if m{^description ?=.*};
description="Bizarrely incompatible copy of $pkg, for testing"

publish = false
END
	}
	if (m{^\[dependencies\]}...m{^\[}) {
	    $_ = <<END if m{^(\S+) ?= ?\{ ?path ?= ?"([^"]+)".*};
$1 = { package = "bizarre-$1", path = "../bizarre-$2", version = "$bizvsn" }
END
        }
	if (m{^\[features\]}) {
	    $_ = $_.$in_features;
	}
	if (m{^\[lib\]}...m{^\[}) {
	    if (m{^\[lib\]}) {
		$had_lib = 1;
		$_ = $before_lib . $_ . $in_lib;
	    }
	    s{^(?:path|doc|doctest) ?=.*\n}{};
	}
	next if (m{^\[workspace\]}...m{^\[}) && m{^\[workspace\]|^[^\[]};
	print O or confess $!;
    }
    if (!$had_lib) {
	print O "\n".$before_lib."[lib]\n".$in_lib or confess $!;
    }
    
    filter_finish();

})->()
}

sub process_pub_b_old_b () {
    filter_start
      'tests/pub-export/pub-b/pub-b.rs',
      'tests/compat/old-b/old-b.rs',
      <<END;
//! Forward/backward compatibility tests
//! See tests/compat/README.md
END
    while (<I>) {
	s{^\s*//.*\n}{};
	s{//.*}{};
	s{_bizarre}{}g;
	print O;
    }

    filter_finish();
}

process_cargo_toml('Cargo.toml',
		   'tests/pub-export/bizarre-facade/Cargo.toml',
		   'src/lib.rs', '', '');

process_cargo_toml('macros/Cargo.toml',
		   'tests/pub-export/bizarre-macros/Cargo.toml',
		   'macros/macros.rs', <<END_FEATURES, <<END);
bizarre = []
default = ["bizarre"]
END_FEATURES
END

process_pub_b_old_b();

if ($found_differences) {
    die "$0: --check, found differences.  Rerun $0 and commit.";
}