MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
have_dbi_dbd-mysql.inc
1 #
2 # Originally created by John Embretsen, 2011-01-26.
3 #
4 # Checks for the existence of Perl modules DBI and DBD::mysql as seen from the
5 # perl installation used by "external" executable perl scripts, i.e. scripts
6 # that are executed as standalone scripts interpreted by the perl installation
7 # specified by the "shebang" line in the top of these scripts.
8 #
9 # If either module is not found, the test will be skipped.
10 #
11 # For use in tests that call perl scripts that require these modules.
12 #
13 # This file is intended to work on Unix. Windows may need different treatment.
14 # Reasoning:
15 # - "shebangs" are not relevant on Windows, but need to be handled here.
16 # - Perl scripts cannot be made executable on Windows, interpreter must be
17 # specified.
18 #
19 # Note that if there are multiple perl installations and not all have the
20 # required modules, this check may fail even if the perl in path does have
21 # the modules available. This may happen if the perl specified by the script's
22 # shebang (e.g. #!/usr/bin/perl) does not have these modules, and script is
23 # called without specifying the perl interpreter. However, this will be
24 # a correct result in cases where a test calls a script with a similar shebang.
25 #
26 ################################################################################
27 
28 --source include/not_windows.inc
29 
30 # We jump through some hoops since there is no direct way to check if an
31 # external command went OK or not from a mysql-test file:
32 #
33 # - In theory, we could do as simple as "exec perl -MDBI -MDBD::mysql -e 1",
34 # however we cannot check the result (exit code) from within a test script.
35 # Also, this may not yield the same result as other uses of perl due to the
36 # shebang issue mentioned above.
37 # - Instead we use a separate helper perl script that checks for the modules.
38 # - If the modules are found, the perl script leaves a file which sets a
39 # variable that can be read by this file.
40 # If the modules are not found, the perl script does not set this variable,
41 # but leaves an empty file instead.
42 #
43 # This is done because there is apparently no direct way to transfer
44 # information from perl to the test script itself.
45 
46 --disable_query_log
47 --disable_result_log
48 --disable_warnings
49 
50 # We do not use embedded perl in this script because that would not have yielded
51 # correct results for a situation where an external Perl script is called like
52 # "scriptname" instead of "perl scriptname" and the shebang in the script points
53 # to a specific perl that may be different than the perl in PATH.
54 #
55 # Instead, we call a separate helper script which checks for the modules in its
56 # own environment. We call it without "perl" in front.
57 
58 --let $perlChecker= $MYSQLTEST_VARDIR/std_data/checkDBI_DBD-mysql.pl
59 --let $resultFile= $MYSQL_TMP_DIR/dbidbd-mysql.txt
60 
61 # Make the script executable and execute it.
62 --chmod 0755 $perlChecker
63 --exec $perlChecker
64 
65 # Source the resulting temporary file and look for a variable being set.
66 --source $resultFile
67 
68 if (!$dbidbd) {
69  --skip Test needs Perl modules DBI and DBD::mysql
70 }
71 
72 # Clean up
73 --remove_file $resultFile
74 
75 --enable_query_log
76 --enable_result_log
77 --enable_warnings
78