Skip to content

Commit

Permalink
Build.PL now checks for DBD drivers and attempts to DTRT
Browse files Browse the repository at this point in the history
svn path=/bioperl-db/trunk/; revision=16309
  • Loading branch information
cjfields committed Nov 2, 2009
1 parent 3aa03b6 commit a3eb01d
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 43 deletions.
128 changes: 87 additions & 41 deletions Build.PL
Expand Up @@ -9,24 +9,38 @@ use Module::Build;
use File::Spec;
use File::Basename;

# add any supported drivers here
my @supported = qw(mysql Pg Oracle);

my $build = Module::Build->new(
module_name => 'Bio::DB',
module_name => 'Bio::DB::BioDB',
dist_name => 'BioPerl-DB',
dist_version => '1.006900',
dist_author => 'BioPerl Team <bioperl-l@bioperl.org>',
dist_abstract => 'BioPerl-DB - package for biological databases',
license => 'perl',
requires => {
'perl' => '5.6.1',
'Bio::Root::Version' => '1.006900',
'DBI' => 0
'perl' => '5.6.1',
'Bio::Root::Version' => '1.006900',
'DBI' => 0
},
recommends => {
'Graph::Directed' => 0
},
get_options => {
accept => { }
'Graph::Directed' => 0
},
auto_features => {
Pg_support => {
description => "Postgres databases",
requires => { 'DBD::Pg' => 0},
},
mysql_support => {
description => "MySQL databases",
requires => { 'DBD::mysql' => 0},
},
Oracle_support => {
description => "Oracle databases",
requires => { 'DBD::Oracle' => 0},
},
},
dynamic_config => 1,
create_makefile_pl => 'passthrough'
);
Expand Down Expand Up @@ -60,18 +74,29 @@ exit;

# setup t/DBHarness.biosql.conf
sub biosql_conf {
my $continue = $accept || $build->y_n("Have you already installed BioSQL? y/n", 'y');
$continue || die "\nBioSQL must be installed prior to installation of bioperl-db; see the INSTALL file\n";
my $continue = $accept ||
$build->y_n("Have you already installed BioSQL? y/n", 'y');
$continue ||
die "\nBioSQL must be installed prior to installation of bioperl-db; ".
"see the INSTALL file\n";

my @drivers = grep {$build->features($_.'_support')}
qw(mysql Pg Oracle);

die "You must install a supported database driver\n" unless @drivers;

my $config_file = File::Spec->catfile('t', 'DBHarness.biosql.conf');
if (-e $config_file) {
($accept || $build->y_n("Do you want to use the existing '$config_file' config file? y/n", 'y')) && return;
($accept || $build->y_n(
"Do you want to use the existing '$config_file' config file? y/n",
'y')) && return;
unlink($config_file);
}

open(my $out, ">", $config_file) or die "Error: could not write to config file '$config_file'\n";
open(my $out, ">", $config_file)
or die "Error: could not write to config file '$config_file'\n";

my %config = (driver => 'mysql',
my %config = (driver => $drivers[0],
host => '127.0.0.1',
user => 'root',
port => 3306,
Expand All @@ -80,45 +105,60 @@ sub biosql_conf {
database => 'biosql',
schema_sql => '../biosql-schema/sql/biosqldb-mysql.sql');

$config{driver} = $build->prompt("DBD driver to use (mandatory)?", $config{driver});
$config{host} = $build->prompt("Machine to connect to (mandatory)?", $config{host});
$config{user} = $build->prompt("User to connect to server as (mandatory)?", $config{user});
$config{driver} = $build->prompt("DBD driver to use (mandatory)?",
$config{driver});
$config{host} = $build->prompt("Machine to connect to (mandatory)?",
$config{host});
$config{user} = $build->prompt("User to connect to server as (mandatory)?",
$config{user});

$config{port} = $build->prompt("Port the server is running on (optional, '' for undef/none)?", $config{port});
$config{port} = $build->prompt("Port the server is running on (optional, ".
"'' for undef/none)?", $config{port});
$config{port} = undef if $config{port} eq "''";

$config{password} = $build->prompt("Password (optional)?", $config{password} || 'undef');
$config{password} = $build->prompt("Password (optional)?",
$config{password} || 'undef');
$config{password} = '' if $config{password} eq 'undef';

$build->log_info("
# The next answer will be used to identify the database name in
# the connect string, e.g., using database=, dbname=, or sid=,
# depending on the driver.
# If this is not set the test scripts will build a temporary
# database from scratch at the beginning and destroy it at the
# end. Conversely, if you do set it then the database must exist,
# or else the tests will fail.
# Generally, it is preferred to pre-build the database, simply for
# efficiency reasons, and it will also enable debugging your
# schema content if some test acts up.
\n");
$config{dbname} = $build->prompt("Name of your existing Biosql database, as it is known to your RDBMS (optional, '' for none)?", $config{dbname});
$build->log_info(<<COMMENT);
# The next answer will be used to identify the database name in
# the connect string, e.g., using database=, dbname=, or sid=,
# depending on the driver.
#
# If this is not set the test scripts will build a temporary
# database from scratch at the beginning and destroy it at the
# end. Conversely, if you do set it then the database must exist,
# or else the tests will fail.
#
# Generally, it is preferred to pre-build the database, simply for
# efficiency reasons, and it will also enable debugging your
# schema content if some test acts up.\n
COMMENT
$config{dbname} = $build->prompt("Name of your existing Biosql database, ".
"as it is known to your RDBMS ".
"(optional, '' for none)?",
$config{dbname});
$config{dbname} = '' if $config{dbname} eq "''";

unless ($config{dbname}) {
$config{schema_sql} = $build->prompt("Set schema_sql to use the version appropriate for your RDBMS (mandatory)", $config{schema_sql});
$config{schema_sql} = $build->prompt("Set schema_sql to use the ".
"version appropriate for your ".
"RDBMS (mandatory)",
$config{schema_sql});
}
$config{schema_sql} = "['$config{schema_sql}']"; # don't know why it is stored as an array ref, is this correct?
# don't know why it is stored as an array ref, is this correct?
$config{schema_sql} = "['$config{schema_sql}']";

$build->log_info("
# The next answer does not refer to the schema or RDBMS; it only
# identifies which of the databases supported in bioperl-db you
# want to be using. Since at present bioperl-db only supports biosql,
# this must be biosql.
\n");
$config{database} = $build->prompt("The name of the database within bioperl-db?", $config{database});
$build->log_info(<<COMMENT);
# The next answer does not refer to the schema or RDBMS; it only
# identifies which of the databases supported in bioperl-db you
# want to be using. Since at present bioperl-db only supports biosql,
# this must be biosql.
COMMENT
$config{database} = $build->prompt("The name of the database within ".
"bioperl-db?", $config{database});

print $out "{\n";
print $out "{\n";
while (my ($key, $val) = each %config) {
# no empty strings, undefined conf setting should be undef (w/o quotes)
$val = "'$val'" unless $key eq 'schema_sql' || !defined($val);
Expand All @@ -130,6 +170,12 @@ sub biosql_conf {
print $out "}\n";
close($out);

# maybe add the capability of using a temporary (test) database, and
# load the SQL on the fly? A little trickier (SQL is in a different
# repo and is driver-dependent)

# probably should add a database ping here and die gracefully otherwise.

# we deliberately don't add the config file to cleanup, but it shouldn't
# cause problems because it is in MANIFEST.SKIP
}
Expand Down
3 changes: 1 addition & 2 deletions lib/Bio/DB/BioDB.pm
@@ -1,5 +1,4 @@
# $Id$

#
# (c) Hilmar Lapp, hlapp at gmx.net, 2002.
# (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
Expand All @@ -23,7 +22,7 @@ Bio::DB::BioDB - class creating the adaptor factory for a particular database
=head1 SYNOPSIS
$dbadp = Bio::DB::BioDB->new(
-database => 'biosql',
-database => 'biosql',
-user => 'root',
-dbname => 'pog',
-host => 'caldy',
Expand Down

0 comments on commit a3eb01d

Please sign in to comment.