]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve library resolution chain for 'arc'
authorepriestley <git@epriestley.com>
Fri, 1 Jul 2011 02:20:41 +0000 (19:20 -0700)
committerepriestley <git@epriestley.com>
Fri, 1 Jul 2011 02:26:33 +0000 (19:26 -0700)
Summary:
We currently look:

  - In the working copy
  - Alongside libphutil/
  - In PHP include_path

Before checking next to libphutil/, check next to the working copy. The problem
right now is that javelin/ references diviner/, but it won't find it next to
javelin/, only next to the libphutil/ instance which is loaded off
/home/engshare/devtools.

Test Plan: Moved javelin to tmp/javelin and diviner to tmp/divinerx. Ran 'arc
list' and got a library load error. Moved 'divinerx' to 'diviner' and ran 'arc
list'. It loaded correctly. Ran '--trace' to verify load location.
Reviewed By: cpojer
Reviewers: cpojer, jungejason
CC: aran, cpojer
Differential Revision: 568

scripts/arcanist.php

index 1b190c1d88c22d6b7adaf4b75a73dc2a82dbffee..472841787ac2b1e980a9f60a3d0d044fa939bdac 100755 (executable)
@@ -81,15 +81,47 @@ try {
   }
   if ($libs) {
     foreach ($libs as $name => $location) {
-      if ($config_trace_mode) {
-        echo "Loading phutil library '{$name}' from '{$location}'...\n";
-      }
+
+      // Try to resolve the library location. We look in several places, in
+      // order:
+      //
+      //  1. Inside the working copy. This is for phutil libraries within the
+      //     project. For instance "library/src" will resolve to
+      //     "./library/src" if it exists.
+      //  2. In the same directory as the working copy. This allows you to
+      //     check out a library alongside a working copy and reference it.
+      //     If we haven't resolved yet, "library/src" will try to resolve to
+      //     "../library/src" if it exists.
+      //  3. Using normal libphutil resolution rules. Generally, this means
+      //     that it checks for libraries next to libphutil, then libraries
+      //     in the PHP include_path.
+
+      $resolved = false;
+
+      // Check inside the working copy.
       $resolved_location = Filesystem::resolvePath(
         $location,
         $working_copy->getProjectRoot());
       if (Filesystem::pathExists($resolved_location)) {
         $location = $resolved_location;
+        $resolved = true;
+      }
+
+      // If we didn't find anything, check alongside the working copy.
+      if (!$resolved) {
+        $resolved_location = Filesystem::resolvePath(
+          $location,
+          dirname($working_copy->getProjectRoot()));
+        if (Filesystem::pathExists($resolved_location)) {
+          $location = $resolved_location;
+          $resolved = true;
+        }
+      }
+
+      if ($config_trace_mode) {
+        echo "Loading phutil library '{$name}' from '{$location}'...\n";
       }
+
       try {
         phutil_load_library($location);
       } catch (PhutilBootloaderException $ex) {