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