]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Allow "arc liberate" to liberate v2 libraries and upgrade v1 -> v2
authorepriestley <git@epriestley.com>
Wed, 30 May 2012 21:18:11 +0000 (14:18 -0700)
committerepriestley <git@epriestley.com>
Wed, 30 May 2012 21:18:11 +0000 (14:18 -0700)
Summary:
  - "arc liberate" now works for v1 or v2 libraries.
  - "arc liberate --upgrade" converts a v1 to a v2.
  - We delete __init__.php files but do not move Class.php files, since this is vastly simpler. Authors can do this on their own if they want. We'll do it separately.
  - v2 has less lint support than v1, but I think we can move first and migrate lint support later. Much of the v1 lint is bad anyway.

Test Plan: Upgraded libphutil, arcanist and phabricator to v2

Reviewers: vrana, btrahan, jungejason

Reviewed By: vrana

CC: aran
Maniphest Tasks: T1103

Differential Revision: https://secure.phabricator.com/D2588

src/lint/linter/phutilmodule/ArcanistPhutilModuleLinter.php
src/workflow/liberate/ArcanistLiberateWorkflow.php

index 747f21e77b63331fe0ca0201110ad338534e8372..5539219a9f567a13f2c73ae8f00b29b6475c0024 100644 (file)
@@ -108,6 +108,7 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter {
     $moduleinfo = array();
 
     $project_root = $this->getEngine()->getWorkingCopy()->getProjectRoot();
+    $bootloader = PhutilBootloader::getInstance();
 
     foreach ($paths as $path) {
       $absolute_path = $project_root.'/'.$path;
@@ -119,6 +120,12 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter {
         continue;
       }
       $library_name = phutil_get_library_name_for_root($library_root);
+
+      $version = $bootloader->getLibraryFormatVersion($library_name);
+      if ($version != 1) {
+        continue;
+      }
+
       if (!is_dir($path)) {
         $path = dirname($path);
       }
@@ -128,7 +135,7 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter {
       if ($path == $library_root) {
         continue;
       }
-      $map = PhutilBootloader::getInstance()->getLibraryMap($library_name);
+      $map = $bootloader->getLibraryMap($library_name);
       $module_name = Filesystem::readablePath($path, $library_root);
       $module_key = $library_name.':'.$module_name;
       if (empty($modules[$module_key])) {
index dea2a113448aa0c4682b80cc1e2142616c058bf9..a709aa53fc0c36780bc1b91d1a90b62af3863e06 100644 (file)
@@ -69,6 +69,10 @@ EOTEXT
           "Internal. Run the verify step of liberation. You do not need to ".
           "run this unless you are debugging the workflow.",
       ),
+      'upgrade' => array(
+        'hide'  => true,
+        'help'  => "Experimental. Upgrade library to v2.",
+      ),
       '*' => 'argv',
     );
   }
@@ -120,6 +124,69 @@ EOTEXT
       }
     }
 
+    $version = $this->getLibraryFormatVersion($path);
+    switch ($version) {
+      case 1:
+        if ($this->getArgument('upgrade')) {
+          return $this->upgradeLibrary($path);
+        }
+        return $this->liberateVersion1($path);
+      case 2:
+        if ($this->getArgument('upgrade')) {
+          throw new ArcanistUsageException(
+            "Can't upgrade a v2 library!");
+        }
+        return $this->liberateVersion2($path);
+      default:
+        throw new ArcanistUsageException(
+          "Unknown library version '{$version}'!");
+    }
+  }
+
+  private function getLibraryFormatVersion($path) {
+    $map_file = $path.'/__phutil_library_map__.php';
+    if (!Filesystem::pathExists($map_file)) {
+      // Default to library v1.
+      return 1;
+    }
+
+    $map = Filesystem::readFile($map_file);
+
+    $matches = null;
+    if (preg_match('/@phutil-library-version (\d+)/', $map, $matches)) {
+      return (int)$matches[1];
+    }
+
+    return 1;
+  }
+
+  private function liberateVersion2($path) {
+    $bin = $this->getScriptPath('scripts/phutil_rebuild_map.php');
+
+    return phutil_passthru(
+      '%s %C %s',
+      $bin,
+      $this->getArgument('all') ? '--drop-cache' : '',
+      $path);
+  }
+
+  private function upgradeLibrary($path) {
+    $inits = id(new FileFinder($path))
+      ->withPath('*/__init__.php')
+      ->withType('f')
+      ->find();
+
+    echo "Removing __init__.php files...\n";
+    foreach ($inits as $init) {
+      Filesystem::remove($path.'/'.$init);
+    }
+
+    echo "Upgrading library to v2...\n";
+    $this->liberateVersion2($path);
+  }
+
+  private function liberateVersion1($path) {
+
     if ($this->getArgument('remap')) {
       return $this->liberateRunRemap($path);
     }