function init_phabricator_script() { phutil_load_library('/srv/phab/libphutil/src'); phutil_load_library('/srv/phab/phabricator/src'); phutil_load_library('/srv/phab/Sprint/src'); phutil_load_library('/srv/phab/arcanist/src'); PhabricatorEnv::initializeScriptEnvironment(); }
public function testPhutilExtensions() { $root = dirname(phutil_get_library_root('phutil')); $path = array($root, 'support', 'phutiltestlib'); $path = implode(DIRECTORY_SEPARATOR, $path); phutil_load_library($path); $this->assertEqual(true, class_exists('PhutilTestClassA')); $this->assertEqual(true, class_exists('PhutilTestClassB')); $this->assertEqual(true, class_exists('PhutilTestClassC')); $symbols = id(new PhutilSymbolLoader())->setAncestorClass('PhutilTestClassA')->setConcreteOnly(true)->selectAndLoadSymbols(); $this->assertEqual(2, count($symbols)); }
function init_phabricator_script() { error_reporting(E_ALL | E_STRICT); ini_set('display_errors', 1); $include_path = ini_get('include_path'); ini_set('include_path', $include_path . PATH_SEPARATOR . dirname(__FILE__) . '/../../'); @(include_once 'libphutil/scripts/__init_script__.php'); if (!@constant('__LIBPHUTIL__')) { echo "ERROR: Unable to load libphutil. Update your PHP 'include_path' to " . "include the parent directory of libphutil/.\n"; exit(1); } phutil_load_library('arcanist/src'); phutil_load_library(dirname(__FILE__) . '/../src/'); PhabricatorEnv::initializeScriptEnvironment(); }
<?php /* * Copyright 2011 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ error_reporting(E_ALL | E_STRICT); ini_set('display_errors', 1); $include_path = ini_get('include_path'); ini_set('include_path', $include_path . ':' . dirname(__FILE__) . '/../../'); @(include_once 'libphutil/src/__phutil_library_init__.php'); if (!@constant('__LIBPHUTIL__')) { echo "ERROR: Unable to load libphutil. Update your PHP 'include_path' to " . "include the parent directory of libphutil/.\n"; exit(1); } phutil_load_library(dirname(__FILE__) . '/../src/');
public function buildSkin(AphrontRequest $request) { foreach ($this->phutilLibraries as $library) { phutil_load_library($library); } return newv($this->getSkinClass(), array($request, $this)); }
public static function loadCoreLibraries() { $phabricator_root = dirname(dirname(__FILE__)); $libraries_root = dirname($phabricator_root); $root = null; if (!empty($_SERVER['PHUTIL_LIBRARY_ROOT'])) { $root = $_SERVER['PHUTIL_LIBRARY_ROOT']; } ini_set('include_path', $libraries_root . PATH_SEPARATOR . ini_get('include_path')); @(include_once $root . 'libphutil/src/__phutil_library_init__.php'); if (!@constant('__LIBPHUTIL__')) { self::didFatal("Unable to load libphutil. Put libphutil/ next to phabricator/, or " . "update your PHP 'include_path' to include the parent directory of " . "libphutil/."); } phutil_load_library('arcanist/src'); // Load Phabricator itself using the absolute path, so we never end up doing // anything surprising (loading index.php and libraries from different // directories). phutil_load_library($phabricator_root . '/src'); }
/** * @group aphront */ function setup_aphront_basics() { $aphront_root = dirname(dirname(__FILE__)); $libraries_root = dirname($aphront_root); $root = null; if (!empty($_SERVER['PHUTIL_LIBRARY_ROOT'])) { $root = $_SERVER['PHUTIL_LIBRARY_ROOT']; } ini_set('include_path', $libraries_root . PATH_SEPARATOR . ini_get('include_path')); @(include_once $root . 'libphutil/src/__phutil_library_init__.php'); if (!@constant('__LIBPHUTIL__')) { echo "ERROR: Unable to load libphutil. Put libphutil/ next to " . "phabricator/, or update your PHP 'include_path' to include " . "the parent directory of libphutil/.\n"; exit(1); } // Load Phabricator itself using the absolute path, so we never end up doing // anything surprising (loading index.php and libraries from different // directories). phutil_load_library($aphront_root . '/src'); phutil_load_library('arcanist/src'); }
* You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ $include_path = ini_get('include_path'); ini_set('include_path', $include_path . ':' . dirname(__FILE__) . '/../../'); require_once dirname(dirname(__FILE__)) . '/conf/__init_conf__.php'; $env = isset($_SERVER['PHABRICATOR_ENV']) ? $_SERVER['PHABRICATOR_ENV'] : getenv('PHABRICATOR_ENV'); if (!$env) { echo "Define PHABRICATOR_ENV before running this script.\n"; exit(1); } $conf = phabricator_read_config_file($env); $conf['phabricator.env'] = $env; phutil_require_module('phabricator', 'infrastructure/env'); PhabricatorEnv::setEnvConfig($conf); phutil_load_library('arcanist/src'); foreach (PhabricatorEnv::getEnvConfig('load-libraries') as $library) { phutil_load_library($library); } PhutilErrorHandler::initialize(); $tz = PhabricatorEnv::getEnvConfig('phabricator.timezone'); if ($tz) { date_default_timezone_set($tz); }
private static function buildConfigurationSourceStack() { self::dropConfigCache(); $stack = new PhabricatorConfigStackSource(); self::$sourceStack = $stack; $default_source = id(new PhabricatorConfigDefaultSource())->setName(pht('Global Default')); $stack->pushSource($default_source); $env = self::getSelectedEnvironmentName(); if ($env) { $stack->pushSource(id(new PhabricatorConfigFileSource($env))->setName(pht("File '%s'", $env))); } $stack->pushSource(id(new PhabricatorConfigLocalSource())->setName(pht('Local Config'))); // If the install overrides the database adapter, we might need to load // the database adapter class before we can push on the database config. // This config is locked and can't be edited from the web UI anyway. foreach (self::getEnvConfig('load-libraries') as $library) { phutil_load_library($library); } // If custom libraries specify config options, they won't get default // values as the Default source has already been loaded, so we get it to // pull in all options from non-phabricator libraries now they are loaded. $default_source->loadExternalOptions(); // If this install has site config sources, load them now. $site_sources = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorConfigSiteSource')->loadObjects(); $site_sources = msort($site_sources, 'getPriority'); foreach ($site_sources as $site_source) { $stack->pushSource($site_source); } try { $stack->pushSource(id(new PhabricatorConfigDatabaseSource('default'))->setName(pht('Database'))); } catch (AphrontQueryException $exception) { // If the database is not available, just skip this configuration // source. This happens during `bin/storage upgrade`, `bin/conf` before // schema setup, etc. } }
function arcanist_load_libraries($load, $must_load, $lib_source, ArcanistWorkingCopyIdentity $working_copy) { if (!$load) { return; } if (!is_array($load)) { $error = "Libraries specified by {$lib_source} are invalid; expected " . "a list. Check your configuration."; $console = PhutilConsole::getConsole(); $console->writeErr("WARNING: %s\n", $error); return; } foreach ($load as $location) { // 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. // // Note that absolute paths will just resolve absolutely through rule (1). $resolved = false; // Check inside the working copy. This also checks absolute paths, since // they'll resolve absolute and just ignore the project root. $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; } } $console = PhutilConsole::getConsole(); $console->writeLog("Loading phutil library from '%s'...\n", $location); $error = null; try { phutil_load_library($location); } catch (PhutilBootloaderException $ex) { $error = "Failed to load phutil library at location '{$location}'. " . "This library is specified by {$lib_source}. Check that the " . "setting is correct and the library is located in the right " . "place."; if ($must_load) { throw new ArcanistUsageException($error); } else { fwrite(STDERR, phutil_console_wrap('WARNING: ' . $error . "\n\n")); } } catch (PhutilLibraryConflictException $ex) { if ($ex->getLibrary() != 'arcanist') { throw $ex; } $arc_dir = dirname(dirname(__FILE__)); $error = "You are trying to run one copy of Arcanist on another copy of " . "Arcanist. This operation is not supported. To execute Arcanist " . "operations against this working copy, run './bin/arc' (from the " . "current working copy) not some other copy of 'arc' (you ran one " . "from '{$arc_dir}')."; throw new ArcanistUsageException($error); } } }
<?php // The include_path should have had libphutil's path appended when this file is // included from the `arc unit` workflow. @(include_once 'libphutil/scripts/__init_script__.php'); if (!@constant('__LIBPHUTIL__')) { echo "ERROR: Unable to load libphutil. Update your PHP 'include_path' to " . "include the parent directory of libphutil/.\n"; exit(1); } phutil_load_library('arcanist/src'); // Fake out the interaction between Composer and libphutil's autoloaders: // Composer always prepends its loader, and libphutil will throw an exception // if a class is not found if there is no loader that runs after its own. This // adds a do-nothing loader after libphutil's to avoid the `throw`. Mostly, // this avoids some bogus `class_exists` failures in PHPUnit itself. spl_autoload_register(function ($class) { });
private function liberateRunVerify($path) { phutil_load_library($path); $paths = $this->liberateGetChangedPaths($path); $results = $this->liberateLintModules($path, $paths); $renderer = new ArcanistLintRenderer(); $unresolved = false; foreach ($results as $result) { foreach ($result->getMessages() as $message) { echo $renderer->renderLintResult($result); $unresolved = true; break; } } return (int) $unresolved; }
private static function buildConfigurationSourceStack($config_optional) { self::dropConfigCache(); $stack = new PhabricatorConfigStackSource(); self::$sourceStack = $stack; $default_source = id(new PhabricatorConfigDefaultSource())->setName(pht('Global Default')); $stack->pushSource($default_source); $env = self::getSelectedEnvironmentName(); if ($env) { $stack->pushSource(id(new PhabricatorConfigFileSource($env))->setName(pht("File '%s'", $env))); } $stack->pushSource(id(new PhabricatorConfigLocalSource())->setName(pht('Local Config'))); // If the install overrides the database adapter, we might need to load // the database adapter class before we can push on the database config. // This config is locked and can't be edited from the web UI anyway. foreach (self::getEnvConfig('load-libraries') as $library) { phutil_load_library($library); } // If custom libraries specify config options, they won't get default // values as the Default source has already been loaded, so we get it to // pull in all options from non-phabricator libraries now they are loaded. $default_source->loadExternalOptions(); // If this install has site config sources, load them now. $site_sources = id(new PhutilClassMapQuery())->setAncestorClass('PhabricatorConfigSiteSource')->setSortMethod('getPriority')->execute(); foreach ($site_sources as $site_source) { $stack->pushSource($site_source); } $master = PhabricatorDatabaseRef::getMasterDatabaseRef(); if (!$master) { self::setReadOnly(true, self::READONLY_MASTERLESS); } else { if ($master->isSevered()) { $master->checkHealth(); if ($master->isSevered()) { self::setReadOnly(true, self::READONLY_SEVERED); } } } try { $stack->pushSource(id(new PhabricatorConfigDatabaseSource('default'))->setName(pht('Database'))); } catch (AphrontSchemaQueryException $exception) { // If the database is not available, just skip this configuration // source. This happens during `bin/storage upgrade`, `bin/conf` before // schema setup, etc. } catch (AphrontConnectionQueryException $ex) { if (!$config_optional) { throw $ex; } } catch (AphrontInvalidCredentialsQueryException $ex) { if (!$config_optional) { throw $ex; } } }
private static function buildConfigurationSourceStack($config_optional) { self::dropConfigCache(); $stack = new PhabricatorConfigStackSource(); self::$sourceStack = $stack; $default_source = id(new PhabricatorConfigDefaultSource())->setName(pht('Global Default')); $stack->pushSource($default_source); $env = self::getSelectedEnvironmentName(); if ($env) { $stack->pushSource(id(new PhabricatorConfigFileSource($env))->setName(pht("File '%s'", $env))); } $stack->pushSource(id(new PhabricatorConfigLocalSource())->setName(pht('Local Config'))); // If the install overrides the database adapter, we might need to load // the database adapter class before we can push on the database config. // This config is locked and can't be edited from the web UI anyway. foreach (self::getEnvConfig('load-libraries') as $library) { phutil_load_library($library); } // Drop any class map caches, since they will have generated without // any classes from libraries. Without this, preflight setup checks can // cause generation of a setup check cache that omits checks defined in // libraries, for example. PhutilClassMapQuery::deleteCaches(); // If custom libraries specify config options, they won't get default // values as the Default source has already been loaded, so we get it to // pull in all options from non-phabricator libraries now they are loaded. $default_source->loadExternalOptions(); // If this install has site config sources, load them now. $site_sources = id(new PhutilClassMapQuery())->setAncestorClass('PhabricatorConfigSiteSource')->setSortMethod('getPriority')->execute(); foreach ($site_sources as $site_source) { $stack->pushSource($site_source); } $masters = PhabricatorDatabaseRef::getMasterDatabaseRefs(); if (!$masters) { self::setReadOnly(true, self::READONLY_MASTERLESS); } else { // If any master is severed, we drop to readonly mode. In theory we // could try to continue if we're only missing some applications, but // this is very complex and we're unlikely to get it right. foreach ($masters as $master) { // Give severed masters one last chance to get healthy. if ($master->isSevered()) { $master->checkHealth(); } if ($master->isSevered()) { self::setReadOnly(true, self::READONLY_SEVERED); break; } } } try { $stack->pushSource(id(new PhabricatorConfigDatabaseSource('default'))->setName(pht('Database'))); } catch (AphrontSchemaQueryException $exception) { // If the database is not available, just skip this configuration // source. This happens during `bin/storage upgrade`, `bin/conf` before // schema setup, etc. } catch (AphrontConnectionQueryException $ex) { if (!$config_optional) { throw $ex; } } catch (AphrontInvalidCredentialsQueryException $ex) { if (!$config_optional) { throw $ex; } } }
$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) { $error_msg = sprintf('Failed to load library "%s" at location "%s". Please check the ' . '"phutil_libraries" setting in your .arcconfig file. Refer to ' . '<http://www.phabricator.com/docs/phabricator/article/' . 'Arcanist_User_Guide_Configuring_a_New_Project.html> ' . 'for more information.', $name, $location); throw new ArcanistUsageException($error_msg); } catch (PhutilLibraryConflictException $ex) { if ($ex->getLibrary() != 'arcanist') { throw $ex; } $arc_dir = dirname(dirname(__FILE__)); $error_msg = "You are trying to run one copy of Arcanist on another copy of " . "Arcanist. This operation is not supported. To execute Arcanist " . "operations against this working copy, run './bin/arc' (from the " . "current working copy) not some other copy of 'arc' (you ran one " . "from '{$arc_dir}')."; throw new ArcanistUsageException($error_msg); } } } $user_config = ArcanistBaseWorkflow::readUserConfigurationFile(); $config = $working_copy->getConfig('arcanist_configuration');