testbot: Autodetect where the WineTestBot is running from.

Francois Gouget fgouget at codeweavers.com
Mon Oct 29 09:38:19 CDT 2012


This avoids having to hardcode paths in the configuration file.
---

Note that this relies on the new <Perl> section in the Apache 
configuration file so that file must be updated and Apache restarted.


 testbot/bin/CheckForWinetestUpdate.pl |    9 +++++----
 testbot/bin/Engine.pl                 |    9 +++++----
 testbot/bin/Janitor.pl                |    9 +++++----
 testbot/bin/PingEngine.pl             |    9 +++++----
 testbot/bin/RevertVM.pl               |    9 +++++----
 testbot/bin/WinePatchesMLSubmit.pl    |    9 +++++----
 testbot/bin/WinePatchesWebGet.pl      |    9 +++++----
 testbot/bin/WinePatchesWebNotify.pl   |    9 +++++----
 testbot/bin/WineRunBuild.pl           |    9 +++++----
 testbot/bin/WineRunReconfig.pl        |    9 +++++----
 testbot/bin/WineRunTask.pl            |    9 +++++----
 testbot/bin/WineSendLog.pl            |    9 +++++----
 testbot/bin/build/Build.pl            |   10 +++++-----
 testbot/bin/build/Reconfig.pl         |   10 +++++-----
 testbot/doc/vhost_winetestbot.conf    |    6 +++++-
 testbot/lib/WineTestBot/Config.pm     |    6 +++---
 testbot/scripts/CheckWineTestBot.pl   |    9 +++++----
 testbot/scripts/TestAgent             |   17 +++++++++--------
 18 files changed, 92 insertions(+), 74 deletions(-)

diff --git a/testbot/bin/CheckForWinetestUpdate.pl b/testbot/bin/CheckForWinetestUpdate.pl
index de8befb..5ca5aa9 100755
--- a/testbot/bin/CheckForWinetestUpdate.pl
+++ b/testbot/bin/CheckForWinetestUpdate.pl
@@ -22,13 +22,14 @@
 
 use strict;
 
-my $Dir;
 sub BEGIN
 {
-  $0 =~ m=^(.*)/[^/]*$=;
-  $Dir = $1;
+  if ($0 =~ m=^(.*)/[^/]+/[^/]+$=)
+  {
+    $::RootDir = $1;
+    unshift @INC, "$::RootDir/lib";
+  }
 }
-use lib "$Dir/../lib";
 
 use Fcntl;
 use File::Compare;
diff --git a/testbot/bin/Engine.pl b/testbot/bin/Engine.pl
index 7834619..b3cfbee 100755
--- a/testbot/bin/Engine.pl
+++ b/testbot/bin/Engine.pl
@@ -20,13 +20,14 @@
 
 use strict;
 
-my $Dir;
 sub BEGIN
 {
-  $0 =~ m=^(.*)/[^/]*$=;
-  $Dir = $1;
+  if ($0 =~ m=^(.*)/[^/]+/[^/]+$=)
+  {
+    $::RootDir = $1;
+    unshift @INC, "$::RootDir/lib";
+  }
 }
-use lib "$Dir/../lib";
 
 use Errno qw(EAGAIN);
 use Fcntl;
diff --git a/testbot/bin/Janitor.pl b/testbot/bin/Janitor.pl
index 6607c7a..e978aa3 100755
--- a/testbot/bin/Janitor.pl
+++ b/testbot/bin/Janitor.pl
@@ -21,13 +21,14 @@
 
 use strict;
 
-my $Dir;
 sub BEGIN
 {
-  $0 =~ m=^(.*)/[^/]*$=;
-  $Dir = $1;
+  if ($0 =~ m=^(.*)/[^/]+/[^/]+$=)
+  {
+    $::RootDir = $1;
+    unshift @INC, "$::RootDir/lib";
+  }
 }
-use lib "$Dir/../lib";
 
 use WineTestBot::Config;
 use WineTestBot::Jobs;
diff --git a/testbot/bin/PingEngine.pl b/testbot/bin/PingEngine.pl
index 4faddf6..ef43807 100755
--- a/testbot/bin/PingEngine.pl
+++ b/testbot/bin/PingEngine.pl
@@ -20,13 +20,14 @@
 
 use strict;
 
-my $Dir;
 sub BEGIN
 {
-  $0 =~ m=^(.*)/[^/]*$=;
-  $Dir = $1;
+  if ($0 =~ m=^(.*)/[^/]+/[^/]+$=)
+  {
+    $::RootDir = $1;
+    unshift @INC, "$::RootDir/lib";
+  }
 }
-use lib "$Dir/../lib";
 
 use WineTestBot::Engine::Notify;
 
diff --git a/testbot/bin/RevertVM.pl b/testbot/bin/RevertVM.pl
index ee46218..7104a28 100755
--- a/testbot/bin/RevertVM.pl
+++ b/testbot/bin/RevertVM.pl
@@ -23,13 +23,14 @@
 
 use strict;
 
-my $Dir;
 sub BEGIN
 {
-  $0 =~ m=^(.*)/[^/]*$=;
-  $Dir = $1;
+  if ($0 =~ m=^(.*)/[^/]+/[^/]+$=)
+  {
+    $::RootDir = $1;
+    unshift @INC, "$::RootDir/lib";
+  }
 }
-use lib "$Dir/../lib";
 
 use WineTestBot::Config;
 use WineTestBot::Log;
diff --git a/testbot/bin/WinePatchesMLSubmit.pl b/testbot/bin/WinePatchesMLSubmit.pl
index 9ab8b3c..7ee4ecf 100755
--- a/testbot/bin/WinePatchesMLSubmit.pl
+++ b/testbot/bin/WinePatchesMLSubmit.pl
@@ -22,13 +22,14 @@
 
 use strict;
 
-my $Dir;
 sub BEGIN
 {
-  $0 =~ m=^(.*)/[^/]*$=;
-  $Dir = $1;
+  if ($0 =~ m=^(.*)/[^/]+/[^/]+$=)
+  {
+    $::RootDir = $1;
+    unshift @INC, "$::RootDir/lib";
+  }
 }
-use lib "$Dir/../lib";
 
 use File::Copy;
 use WineTestBot::Config;
diff --git a/testbot/bin/WinePatchesWebGet.pl b/testbot/bin/WinePatchesWebGet.pl
index d6b3f2b..ed84a50 100755
--- a/testbot/bin/WinePatchesWebGet.pl
+++ b/testbot/bin/WinePatchesWebGet.pl
@@ -21,13 +21,14 @@
 
 use strict;
 
-my $Dir;
 sub BEGIN
 {
-  $0 =~ m=^(.*)/[^/]*$=;
-  $Dir = $1;
+  if ($0 =~ m=^(.*)/[^/]+/[^/]+$=)
+  {
+    $::RootDir = $1;
+    unshift @INC, "$::RootDir/lib";
+  }
 }
-use lib "$Dir/../lib";
 
 use LWP::UserAgent;
 use HTTP::Request;
diff --git a/testbot/bin/WinePatchesWebNotify.pl b/testbot/bin/WinePatchesWebNotify.pl
index 185a0f1..6940d76 100755
--- a/testbot/bin/WinePatchesWebNotify.pl
+++ b/testbot/bin/WinePatchesWebNotify.pl
@@ -21,13 +21,14 @@
 
 use strict;
 
-my $Dir;
 sub BEGIN
 {
-  $0 =~ m=^(.*)/[^/]*$=;
-  $Dir = $1;
+  if ($0 =~ m=^(.*)/[^/]+/[^/]+$=)
+  {
+    $::RootDir = $1;
+    unshift @INC, "$::RootDir/lib";
+  }
 }
-use lib "$Dir/../lib";
 
 use File::Copy;
 use WineTestBot::Config;
diff --git a/testbot/bin/WineRunBuild.pl b/testbot/bin/WineRunBuild.pl
index 86f03c7..cc0746f 100755
--- a/testbot/bin/WineRunBuild.pl
+++ b/testbot/bin/WineRunBuild.pl
@@ -21,13 +21,14 @@
 
 use strict;
 
-my $Dir;
 sub BEGIN
 {
-  $0 =~ m=^(.*)/[^/]*$=;
-  $Dir = $1;
+  if ($0 =~ m=^(.*)/[^/]+/[^/]+$=)
+  {
+    $::RootDir = $1;
+    unshift @INC, "$::RootDir/lib";
+  }
 }
-use lib "$Dir/../lib";
 
 use WineTestBot::Config;
 use WineTestBot::Jobs;
diff --git a/testbot/bin/WineRunReconfig.pl b/testbot/bin/WineRunReconfig.pl
index 89fe3da..9cc1e5e 100755
--- a/testbot/bin/WineRunReconfig.pl
+++ b/testbot/bin/WineRunReconfig.pl
@@ -21,13 +21,14 @@
 
 use strict;
 
-my $Dir;
 sub BEGIN
 {
-  $0 =~ m=^(.*)/[^/]*$=;
-  $Dir = $1;
+  if ($0 =~ m=^(.*)/[^/]+/[^/]+$=)
+  {
+    $::RootDir = $1;
+    unshift @INC, "$::RootDir/lib";
+  }
 }
-use lib "$Dir/../lib";
 
 use WineTestBot::Config;
 use WineTestBot::Jobs;
diff --git a/testbot/bin/WineRunTask.pl b/testbot/bin/WineRunTask.pl
index bfbffe8..9ec499f 100755
--- a/testbot/bin/WineRunTask.pl
+++ b/testbot/bin/WineRunTask.pl
@@ -20,13 +20,14 @@
 
 use strict;
 
-my $Dir;
 sub BEGIN
 {
-  $0 =~ m=^(.*)/[^/]*$=;
-  $Dir = $1;
+  if ($0 =~ m=^(.*)/[^/]+/[^/]+$=)
+  {
+    $::RootDir = $1;
+    unshift @INC, "$::RootDir/lib";
+  }
 }
-use lib "$Dir/../lib";
 
 use POSIX qw(:fcntl_h);
 use WineTestBot::Config;
diff --git a/testbot/bin/WineSendLog.pl b/testbot/bin/WineSendLog.pl
index 95814fe..768e129 100755
--- a/testbot/bin/WineSendLog.pl
+++ b/testbot/bin/WineSendLog.pl
@@ -21,13 +21,14 @@
 
 use strict;
 
-my $Dir;
 sub BEGIN
 {
-  $0 =~ m=^(.*)/[^/]*$=;
-  $Dir = $1;
+  if ($0 =~ m=^(.*)/[^/]+/[^/]+$=)
+  {
+    $::RootDir = $1;
+    unshift @INC, "$::RootDir/lib";
+  }
 }
-use lib "$Dir/../lib";
 
 use Algorithm::Diff;
 use WineTestBot::Config;
diff --git a/testbot/bin/build/Build.pl b/testbot/bin/build/Build.pl
index a37537e..a50e901 100755
--- a/testbot/bin/build/Build.pl
+++ b/testbot/bin/build/Build.pl
@@ -22,14 +22,14 @@
 
 use strict;
 
-my $Dir;
 sub BEGIN
 {
-  $main::BuildEnv = 1;
-  $0 =~ m=^(.*)/[^/]*$=;
-  $Dir = $1;
+  if ($0 =~ m=^(.*)/[^/]+/[^/]+/[^/]+$=)
+  {
+    $::RootDir = $1;
+    unshift @INC, "$::RootDir/lib";
+  }
 }
-use lib "$Dir/../../lib";
 
 use WineTestBot::Config;
 
diff --git a/testbot/bin/build/Reconfig.pl b/testbot/bin/build/Reconfig.pl
index daa03b1..1e18e2d 100755
--- a/testbot/bin/build/Reconfig.pl
+++ b/testbot/bin/build/Reconfig.pl
@@ -22,14 +22,14 @@
 
 use strict;
 
-my $Dir;
 sub BEGIN
 {
-  $main::BuildEnv = 1;
-  $0 =~ m=^(.*)/[^/]*$=;
-  $Dir = $1;
+  if ($0 =~ m=^(.*)/[^/]+/[^/]+/[^/]+$=)
+  {
+    $::RootDir = $1;
+    unshift @INC, "$::RootDir/lib";
+  }
 }
-use lib "$Dir/../../lib";
 
 use WineTestBot::Config;
 
diff --git a/testbot/doc/vhost_winetestbot.conf b/testbot/doc/vhost_winetestbot.conf
index 9c53876..735292e 100644
--- a/testbot/doc/vhost_winetestbot.conf
+++ b/testbot/doc/vhost_winetestbot.conf
@@ -7,7 +7,11 @@
   PerlSwitches -Tw
   <Perl>
     use strict;
-    use lib qw(/home/winehq/tools/testbot/lib);
+    BEGIN
+    {
+      $::RootDir = "/home/winehq/tools/testbot";
+      unshift @INC, "$::RootDir/lib";
+    }
     use ObjectModel::CGI::Page;
     use WineTestBot::CGI::PageBase;
     SetPageBaseCreator(\&CreatePageBase);
diff --git a/testbot/lib/WineTestBot/Config.pm b/testbot/lib/WineTestBot/Config.pm
index 98fcbb0..d5a1b2a 100644
--- a/testbot/lib/WineTestBot/Config.pm
+++ b/testbot/lib/WineTestBot/Config.pm
@@ -48,9 +48,9 @@ require Exporter;
              $JobPurgeDays $JobArchiveDays $WebHostName);
 @EXPORT_OK = qw($DbDataSource $DbUsername $DbPassword);
 
-$LogDir = "/home/winehq/tools/testbot/var";
-$DataDir = "/home/winehq/tools/testbot/var";
-$BinDir = "/home/winehq/tools/testbot/bin";
+$LogDir = "$::RootDir/var";
+$DataDir = "$::RootDir/var";
+$BinDir = "$::RootDir/bin";
 
 $MaxRevertingVMs = 1;
 $MaxRunningVMs = 2;
diff --git a/testbot/scripts/CheckWineTestBot.pl b/testbot/scripts/CheckWineTestBot.pl
index f6f0666..b749eff 100755
--- a/testbot/scripts/CheckWineTestBot.pl
+++ b/testbot/scripts/CheckWineTestBot.pl
@@ -20,13 +20,14 @@
 
 use strict;
 
-my $Dir;
 sub BEGIN
 {
-  $0 =~ m=^(.*)/[^/]*$=;
-  $Dir = $1;
+  if ($0 =~ m=^(.*)/[^/]+/[^/]+$=)
+  {
+    $::RootDir = $1;
+    unshift @INC, "$::RootDir/lib";
+  }
 }
-use lib "$Dir/../lib";
 
 use WineTestBot::Config;
 use WineTestBot::Engine::Notify;
diff --git a/testbot/scripts/TestAgent b/testbot/scripts/TestAgent
index 2e9850d..a16bd5f 100755
--- a/testbot/scripts/TestAgent
+++ b/testbot/scripts/TestAgent
@@ -18,19 +18,20 @@
 # You should have received a copy of the GNU Lesser General Public
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
-use strict;
-
-my $name0=$0;
-$name0 =~ s+^.*/++;
 
+use strict;
 
-my $Dir;
 sub BEGIN
 {
-  $0 =~ m=^(.*)/[^/]*$=;
-  $Dir = $1;
+  if ($0 =~ m=^(.*)/[^/]+/[^/]+$=)
+  {
+    $::RootDir = $1;
+    unshift @INC, "$::RootDir/lib";
+  }
 }
-use lib "$Dir/../lib";
+
+my $name0=$0;
+$name0 =~ s+^.*/++;
 
 use WineTestBot::Config;
 use WineTestBot::TestAgent;
-- 
1.7.10.4




More information about the wine-patches mailing list