1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-29 18:22:41 +01:00

Allow "arc liberate" to liberate v2 libraries and upgrade v1 -> v2

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
This commit is contained in:
epriestley 2012-05-30 14:18:11 -07:00
parent 7a4c97f9c3
commit a8ddec4f64
2 changed files with 75 additions and 1 deletions

View file

@ -108,6 +108,7 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter {
$moduleinfo = array(); $moduleinfo = array();
$project_root = $this->getEngine()->getWorkingCopy()->getProjectRoot(); $project_root = $this->getEngine()->getWorkingCopy()->getProjectRoot();
$bootloader = PhutilBootloader::getInstance();
foreach ($paths as $path) { foreach ($paths as $path) {
$absolute_path = $project_root.'/'.$path; $absolute_path = $project_root.'/'.$path;
@ -119,6 +120,12 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter {
continue; continue;
} }
$library_name = phutil_get_library_name_for_root($library_root); $library_name = phutil_get_library_name_for_root($library_root);
$version = $bootloader->getLibraryFormatVersion($library_name);
if ($version != 1) {
continue;
}
if (!is_dir($path)) { if (!is_dir($path)) {
$path = dirname($path); $path = dirname($path);
} }
@ -128,7 +135,7 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter {
if ($path == $library_root) { if ($path == $library_root) {
continue; continue;
} }
$map = PhutilBootloader::getInstance()->getLibraryMap($library_name); $map = $bootloader->getLibraryMap($library_name);
$module_name = Filesystem::readablePath($path, $library_root); $module_name = Filesystem::readablePath($path, $library_root);
$module_key = $library_name.':'.$module_name; $module_key = $library_name.':'.$module_name;
if (empty($modules[$module_key])) { if (empty($modules[$module_key])) {

View file

@ -69,6 +69,10 @@ EOTEXT
"Internal. Run the verify step of liberation. You do not need to ". "Internal. Run the verify step of liberation. You do not need to ".
"run this unless you are debugging the workflow.", "run this unless you are debugging the workflow.",
), ),
'upgrade' => array(
'hide' => true,
'help' => "Experimental. Upgrade library to v2.",
),
'*' => 'argv', '*' => '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')) { if ($this->getArgument('remap')) {
return $this->liberateRunRemap($path); return $this->liberateRunRemap($path);
} }