Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistLiberateWorkflow.php
| Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | public function getArguments() { | ||||
| ); | ); | ||||
| } | } | ||||
| public function runWorkflow() { | public function runWorkflow() { | ||||
| $argv = $this->getArgument('argv'); | $argv = $this->getArgument('argv'); | ||||
| if (count($argv) > 1) { | if (count($argv) > 1) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| pht( | pht( | ||||
| "Provide only one path to '%s'. The path should be a directory ". | 'Provide only one path to "arc liberate". The path should identify '. | ||||
| "where you want to create or update a libphutil library.", | 'a directory where you want to create or update a library.')); | ||||
| 'arc liberate')); | } else if (!$argv) { | ||||
| } else if (count($argv) == 0) { | $init_files = id(new FileFinder(getcwd())) | ||||
| $path = getcwd(); | ->withPath('*/__phutil_library_init__.php') | ||||
| ->find(); | |||||
| if (!$init_files) { | |||||
| throw new ArcanistUsageException( | |||||
| pht( | |||||
| 'Unable to find any libraries under the current working '. | |||||
| 'directory. To create a library, provide a path.')); | |||||
| } | |||||
| $paths = array(); | |||||
| foreach ($init_files as $init) { | |||||
| $paths[] = Filesystem::resolvePath(dirname($init)); | |||||
| } | |||||
| } else { | } else { | ||||
| $path = reset($argv); | $paths = array( | ||||
| Filesystem::resolvePath(head($argv)), | |||||
| ); | |||||
| } | } | ||||
| $is_remap = $this->getArgument('remap'); | $is_remap = $this->getArgument('remap'); | ||||
| $is_verify = $this->getArgument('verify'); | $is_verify = $this->getArgument('verify'); | ||||
| $path = Filesystem::resolvePath($path); | foreach ($paths as $path) { | ||||
| $this->liberatePath($path); | |||||
| } | |||||
| if (Filesystem::pathExists($path) && is_dir($path)) { | return 0; | ||||
| $init = id(new FileFinder($path)) | |||||
| ->withPath('*/__phutil_library_init__.php') | |||||
| ->find(); | |||||
| } else { | |||||
| $init = null; | |||||
| } | } | ||||
| if ($init) { | private function liberatePath($path) { | ||||
| if (count($init) > 1) { | if (!Filesystem::pathExists($path.'/__phutil_library_init__.php')) { | ||||
| throw new ArcanistUsageException( | echo tsprintf( | ||||
| "%s\n", | |||||
| pht( | pht( | ||||
| 'Specified directory contains more than one libphutil library. '. | 'No library currently exists at the path "%s"...', | ||||
| 'Use a more specific path.')); | $path)); | ||||
| } | |||||
| $path = Filesystem::resolvePath(dirname(reset($init)), $path); | |||||
| } else { | |||||
| $found = false; | |||||
| foreach (Filesystem::walkToRoot($path) as $dir) { | |||||
| if (Filesystem::pathExists($dir.'/__phutil_library_init__.php')) { | |||||
| $path = $dir; | |||||
| $found = true; | |||||
| break; | |||||
| } | |||||
| } | |||||
| if (!$found) { | |||||
| echo pht("No library currently exists at that path...\n"); | |||||
| $this->liberateCreateDirectory($path); | $this->liberateCreateDirectory($path); | ||||
| $this->liberateCreateLibrary($path); | $this->liberateCreateLibrary($path); | ||||
| return; | return; | ||||
| } | } | ||||
| } | |||||
| $version = $this->getLibraryFormatVersion($path); | $version = $this->getLibraryFormatVersion($path); | ||||
| switch ($version) { | switch ($version) { | ||||
| case 1: | case 1: | ||||
| if ($this->getArgument('upgrade')) { | if ($this->getArgument('upgrade')) { | ||||
| return $this->upgradeLibrary($path); | return $this->upgradeLibrary($path); | ||||
| } | } | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| Show All 26 Lines | private function getLibraryFormatVersion($path) { | ||||
| if (preg_match('/@phutil-library-version (\d+)/', $map, $matches)) { | if (preg_match('/@phutil-library-version (\d+)/', $map, $matches)) { | ||||
| return (int)$matches[1]; | return (int)$matches[1]; | ||||
| } | } | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| private function liberateVersion2($path) { | private function liberateVersion2($path) { | ||||
| $bin = $this->getScriptPath('scripts/phutil_rebuild_map.php'); | $bin = $this->getScriptPath('scripts/library/library-map.php'); | ||||
| return phutil_passthru( | return phutil_passthru( | ||||
| 'php %s %C %s', | 'php %s %C %s', | ||||
| $bin, | $bin, | ||||
| $this->getArgument('all') ? '--drop-cache' : '', | $this->getArgument('all') ? '--drop-cache' : '', | ||||
| $path); | $path); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | echo pht( | ||||
| '__phutil_library_init__.php', | '__phutil_library_init__.php', | ||||
| $path); | $path); | ||||
| Filesystem::writeFile($init_path, $template); | Filesystem::writeFile($init_path, $template); | ||||
| $this->liberateVersion2($path); | $this->liberateVersion2($path); | ||||
| } | } | ||||
| private function getScriptPath($script) { | private function getScriptPath($script) { | ||||
| $root = dirname(phutil_get_library_root('phutil')); | $root = dirname(phutil_get_library_root('arcanist')); | ||||
| return $root.'/'.$script; | return $root.'/'.$script; | ||||
| } | } | ||||
| } | } | ||||