fix for when we are adding /dropping columns in sqlite and need to roundtrip via...
[dbsrgits/SQL-Translator.git] / Makefile.PL
CommitLineData
bc38e1f5 1use inc::Module::Install 1.00;
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
6e64adbe 8my $deps = {
9 requires => {
cc553312 10 'Class::Base' => '0',
11 'Class::Data::Inheritable' => '0.02',
465cea6c 12 'Class::Unload' => '0.07',
cc553312 13 'Digest::SHA' => '0',
14 'Carp::Clan' => '0',
15 'IO::Dir' => '0',
16 'IO::Scalar' => '2.110',
17 'Parse::RecDescent' => '1.964001',
18 'Pod::Usage' => '0',
19 'DBI' => '0',
20 'File::ShareDir' => '1.0',
21 'File::Spec' => '0',
22 'Scalar::Util' => '0',
23 'XML::Writer' => '0.500',
24 'Moo' => '0.009007',
6e64adbe 25 },
26 recommends => {
cc553312 27 'Template' => '2.20',
28 'GD' => '0',
29 'GraphViz' => '0',
30 'Graph::Directed' => '0',
31 'Spreadsheet::ParseExcel' => '0.41',
32 'Text::ParseWords' => '0',
33 'Text::RecordParser' => '0.02',
34 'XML::LibXML' => '1.69',
6e64adbe 35 },
36 test_requires => {
cc553312 37 'YAML' => '0.66',
38 'File::Basename' => '0',
39 'Test::More' => '0.6',
40 'Test::Differences' => '0',
41 'Test::Exception' => '0',
6e64adbe 42 },
43};
44
45perl_version '5.005';
46
47name 'SQL-Translator';
48author 'Ken Youens-Clark <kclark@cpan.org>';
49abstract 'SQL DDL transformations and more';
44659089 50license 'gpl';
3f5ee660 51repository 'git://git.shadowcat.co.uk/dbsrgits/SQL-Translator.git';
6e64adbe 52bugtracker 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=SQL-Translator';
53
54resources Ratings => 'http://cpanratings.perl.org/d/SQL-Translator';
55
56all_from 'lib/SQL/Translator.pm';
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 ($@) {
d53db6a7 194 warn <<EOE;
dc34f950 195
196=========================================================================
d53db6a7 197=============== WARNING !!! =================
dc34f950 198=========================================================================
199
200Unable to update the roundtrip schema (attempt triggered by AUTHOR mode).
d53db6a7 201We will still generate a Makefile, but be aware that if you build a dist
202this way, it *WILL* be broken.
dc34f950 203
d53db6a7 204-------------------------------------------------------------------------
dc34f950 205$@
206
d53db6a7 207Press Enter to continue.
dc34f950 208EOE
d53db6a7 209 <>;
dc34f950 210 }
211}