Die instead of warning if roundtrip regen fails
[dbsrgits/SQL-Translator.git] / Makefile.PL
CommitLineData
860d3652 1use inc::Module::Install 1.06;
6e64adbe 2use strict;
3use warnings;
4
475a7db7 5# to deal wuth x.y.z versions properly
cc553312 6configure_requires 'ExtUtils::MakeMaker' => '6.54';
475a7db7 7
860d3652 8perl_version '5.008001';
9
6e64adbe 10my $deps = {
11 requires => {
cc553312 12 'Digest::SHA' => '0',
13 'Carp::Clan' => '0',
7e666ece 14 'Parse::RecDescent' => '1.967009',
cf915bd8 15 'DBI' => '1.54',
cc553312 16 'File::ShareDir' => '1.0',
a5bfeba8 17 'Moo' => '1.000003',
0fb58589 18 'Package::Variant' => '1.001001',
68d75205 19 'Sub::Quote' => '0',
45287c81 20 'Try::Tiny' => '0.04',
7c7966a1 21 'List::MoreUtils' => '0.09',
3ab19c1b 22 'Scalar::Util' => '0',
6e64adbe 23 },
24 recommends => {
cc553312 25 'Template' => '2.20',
26 'GD' => '0',
27 'GraphViz' => '0',
28 'Graph::Directed' => '0',
29 'Spreadsheet::ParseExcel' => '0.41',
cc553312 30 'Text::RecordParser' => '0.02',
31 'XML::LibXML' => '1.69',
6e64adbe 32 },
33 test_requires => {
edc7ae17 34 'JSON' => '2.0',
cc553312 35 'YAML' => '0.66',
cb9a77e1 36 'XML::Writer' => '0.500',
860d3652 37 'Test::More' => '0.88',
cc553312 38 'Test::Differences' => '0',
860d3652 39 'Test::Exception' => '0.31',
6e64adbe 40 },
41};
42
6e64adbe 43
44name 'SQL-Translator';
45author 'Ken Youens-Clark <kclark@cpan.org>';
46abstract 'SQL DDL transformations and more';
c45d3cbc 47license 'perl';
3f5ee660 48repository 'git://git.shadowcat.co.uk/dbsrgits/SQL-Translator.git';
6e64adbe 49bugtracker 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=SQL-Translator';
50
51resources Ratings => 'http://cpanratings.perl.org/d/SQL-Translator';
52
09d9cd5e 53Meta->{values}{x_authority} = 'cpan:JROBINSON';
54
6e64adbe 55all_from 'lib/SQL/Translator.pm';
c45d3cbc 56readme_from 'lib/SQL/Translator.pm';
6e64adbe 57
58for my $type (qw/requires recommends test_requires/) {
59 no strict qw/refs/;
60 my $f = \&$type;
61 for my $mod (keys %{$deps->{$type} || {} }) {
62 $f->($mod, $deps->{$type}{$mod});
63 }
64}
65
6e64adbe 66install_script (qw|
467b7282 67 script/sqlt-diagram
68 script/sqlt-diff
69 script/sqlt-diff-old
70 script/sqlt-dumper
71 script/sqlt-graph
72 script/sqlt
6e64adbe 73|);
74
75install_share();
76
aee4b66e 77tests_recursive ();
78
79
80# temporary(?) until I get around to fix M::I wrt xt/
81# needs Module::Install::AuthorTests
82eval {
83 # this should not be necessary since the autoloader is supposed
84 # to work, but there were reports of it failing
85 require Module::Install::AuthorTests;
86 recursive_author_tests (qw/xt/);
87 1;
88} || do {
89 if ($Module::Install::AUTHOR) {
90 my $err = $@;
91
92 # better error message in case of missing dep
93 eval { require Module::Install::AuthorTests }
94 || die "\nYou need Module::Install::AuthorTests installed to run this Makefile.PL in author mode:\n\n$@\n";
95
96 die $err;
97 }
98};
6e64adbe 99
100auto_install();
101
dc34f950 102if ($Module::Install::AUTHOR) {
103 _recompile_grammars();
104 _recreate_rt_source();
105}
106
6e64adbe 107WriteAll();
dc34f950 108
dc34f950 109sub _recompile_grammars {
0eb3b94a 110 return; # disabled until RT#74593 is resolved
111
bdf60588 112 require File::Spec;
113
114 my $compiled_parser_dir = File::Spec->catdir(qw/
115 share PrecompiledParsers Parse RecDescent DDL SQLT
116 /);
117
118 # Currently consider only single-name parsers containing a grammar marker
119 # This is somewhat fragile, but better than loading all kinds of parsers
120 # to some of which we may not even have the deps
121 my $parser_libdir = 'lib/SQL/Translator/Parser';
122 for my $parser_fn (glob "$parser_libdir/*.pm") {
123 die "$parser_fn does not look like a readable file\n"
124 unless ( -f $parser_fn and -r $parser_fn );
125
126 my ($type) = $parser_fn =~ /^\Q$parser_libdir\E\/(.+)\.pm$/i
127 or die "$parser_fn not named in expected format\n";
128
129 my $parser_source = do { local (@ARGV, $/) = $parser_fn; <> };
130 next unless $parser_source =~ /\$GRAMMAR.+?END_OF_GRAMMAR/s;
131
132
133 my $precomp_parser_fn = File::Spec->catfile($compiled_parser_dir, "$type.pm");
134
135 next if (
136 -f $precomp_parser_fn
137 and
138 (stat($parser_fn))[9] <= (stat($precomp_parser_fn))[9]
139 );
140
141
142 print "Precompiling parser for $type\n";
143
144 require $parser_fn;
145 require Parse::RecDescent;
146
147 Parse::RecDescent->Precompile(
148 do {
149 no strict 'refs';
150 ${"SQL::Translator::Parser::${type}::GRAMMAR"}
151 || die "No \$GRAMMAR global found in SQL::Translator::Parser::$type ($parser_fn)\n"
152 },
153 "Parse::RecDescent::DDL::SQLT::$type"
154 );
155
156 rename( "$type.pm", $precomp_parser_fn )
157 or die "Unable to move $type.pm to $compiled_parser_dir: $!\n";
158 }
159
dc34f950 160}
161
162sub _recreate_rt_source {
163 my $base_xml = "t/data/roundtrip.xml";
164 my $autogen_yaml = "t/data/roundtrip_autogen.yaml";
165
166 print "Updating $autogen_yaml\n";
167
168 unlink $autogen_yaml;
169
170 eval {
171
172 use lib 'lib';
173
174 require SQL::Translator;
175 require SQL::Translator::Parser::XML;
176
177 open (my $fh, '>', $autogen_yaml) or die "$autogen_yaml: $!\n";
178
179 my $tr = SQL::Translator->new;
180 my $yaml = $tr->translate (
181 parser => 'XML',
182 file => $base_xml,
183 producer => 'YAML',
184 ) or die sprintf ("Unable to translate %s to YAML: %s\n",
185 $base_xml,
186 $tr->error || 'error unknown'
187 );
188
189 print $fh $yaml;
190 close $fh;
191 };
192
193 if ($@) {
16bbaff2 194 die <<EOE;
dc34f950 195
196=========================================================================
d53db6a7 197=============== WARNING !!! =================
dc34f950 198=========================================================================
199
200Unable to update the roundtrip schema (attempt triggered by AUTHOR mode).
16bbaff2 201Aborting Makefile generation, please fix the errors indicated below
202(typically by installing the missing modules).
dc34f950 203
d53db6a7 204-------------------------------------------------------------------------
dc34f950 205$@
206
207EOE
dc34f950 208 }
209}