2nd Pass
[dbsrgits/DBIx-Class.git] / maint / Makefile.PL.inc / 56_autogen_testddl.pl
1 require File::Spec;
2 my $ddl_fn = {
3    sqlite  => File::Spec->catfile(qw(t lib sqlite.sql)),
4    dbdfile => File::Spec->catfile(qw(t lib dbdfile.sql)),
5 };
6
7 # If the author doesn't have the prereqs, we will end up obliterating
8 # the ddl file, and all tests will fail, therefore don't do anything
9 # on error
10 # The EUMM build-stage generation will run unconditionally and
11 # errors will not be trapped
12 require DBIx::Class::Optional::Dependencies;
13 if ( DBIx::Class::Optional::Dependencies->req_ok_for ('deploy') ) {
14   foreach my $type (qw(sqlite dbdfile)) {
15     print "Regenerating t/lib/$type.sql\n";
16     if (my $out = ` "$^X" -Ilib maint/gen_schema_$type `) {
17       open (my $fh, '>:unix', $ddl_fn->{$type}) or die "Unable to open $ddl_fn->{$type}: $!";
18       print $fh $out;
19       close $fh;
20
21       # if we don't do it some git tools (e.g. gitk) get confused that the
22       # ddl file is modified, when it clearly isn't
23       system('git status --porcelain >' . File::Spec->devnull);
24     }
25   }
26 }
27
28 my $postamble = <<"EOP";
29
30 clonedir_generate_files : dbic_clonedir_regen_test_ddl
31
32 dbic_clonedir_regen_test_ddl :
33 EOP
34 foreach my $type (qw(sqlite dbdfile)) {
35   $postamble .= <<"EOP";
36 \t\$(ABSPERLRUN) -Ilib -- maint/gen_schema_$type > @{[ $mm_proto->quote_literal($ddl_fn->{$type}) ]}
37 @{[ $crlf_fixup->($ddl_fn->{$type}) ]}
38 EOP
39 }
40
41 postamble $postamble;
42
43 # keep the Makefile.PL eval happy
44 1;