You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.6 KiB

  1. #!/usr/bin/perl
  2. # Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Library General Public
  6. # License as published by the Free Software Foundation; version 2
  7. # of the License.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # Library General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. ################################################################################
  18. #
  19. # This perl script checks for availability of the Perl modules DBI and
  20. # DBD::mysql using the "current" perl interpreter.
  21. #
  22. # Useful for test environment checking before testing executable perl scripts
  23. # in the MySQL Server distribution.
  24. #
  25. # NOTE: The "shebang" on the first line of this script should always point to
  26. # /usr/bin/perl, so that we can use this script to check whether or not we
  27. # support running perl scripts with such a shebang without specifying the
  28. # perl interpreter on the command line. Such a script is mysqlhotcopy.
  29. #
  30. # When run as "checkDBI_DBD-mysql.pl" the shebang line will be evaluated
  31. # and used. When run as "perl checkDBI_DBD-mysql.pl" the shebang line is
  32. # not used.
  33. #
  34. # NOTE: This script will create a temporary file in MTR's tmp dir.
  35. # If modules are found, a mysql-test statement which sets a special
  36. # variable is written to this file. If one of the modules is not found
  37. # (or cannot be loaded), the file will remain empty.
  38. # A test (or include file) which sources that file can then easily do
  39. # an if-check on the special variable to determine success or failure.
  40. #
  41. # Example:
  42. #
  43. # --let $perlChecker= $MYSQLTEST_VARDIR/std_data/checkDBI_DBD-mysql.pl
  44. # --let $resultFile= $MYSQL_TMP_DIR/dbidbd-mysql.txt
  45. # --chmod 0755 $perlChecker
  46. # --exec $perlChecker
  47. # --source $resultFile
  48. # if (!$dbidbd) {
  49. # --skip Test needs Perl modules DBI and DBD::mysql
  50. # }
  51. #
  52. # The calling script is also responsible for cleaning up after use:
  53. #
  54. # --remove_file $resultFile
  55. #
  56. # Windows notes:
  57. # - shebangs may work differently - call this script with "perl " in front.
  58. #
  59. # See mysql-test/include/have_dbi_dbd-mysql.inc for example use of this script.
  60. # This script should be executable for the user running MTR.
  61. #
  62. ################################################################################
  63. BEGIN {
  64. # By using eval inside BEGIN we can suppress warnings and continue after.
  65. # We need to catch "Can't locate" as well as "Can't load" errors.
  66. eval{
  67. $FOUND_DBI=0;
  68. $FOUND_DBD_MYSQL=0;
  69. # Check for DBI module:
  70. $FOUND_DBI=1 if require DBI;
  71. # Check for DBD::mysql module
  72. $FOUND_DBD_MYSQL=1 if require DBD::mysql;
  73. };
  74. };
  75. # Open a file to be used for transfer of result back to mysql-test.
  76. # The file must be created whether we write to it or not, otherwise mysql-test
  77. # will complain if trying to source it.
  78. # An empty file indicates failure to load modules.
  79. open(FILE, ">", $ENV{'MYSQL_TMP_DIR'}.'/dbidbd-mysql.txt');
  80. if ($FOUND_DBI && $FOUND_DBD_MYSQL) {
  81. # write a mysql-test command setting a variable to indicate success
  82. print(FILE 'let $dbidbd= FOUND_DBI_DBD-MYSQL;'."\n");
  83. }
  84. # close the file.
  85. close(FILE);
  86. 1;