2011-01-09 15:22:25 -08:00
|
|
|
<?php
|
|
|
|
|
2011-02-19 11:36:08 -08:00
|
|
|
/**
|
|
|
|
* Interfaces with basic information about the working copy.
|
|
|
|
*
|
Allow global config to load libraries and set test engines
Summary:
Khan Academy is looking into lint configuration, but doesn't use ".arcconfig" because they have a large number of repositories. Making configuration more flexible generally gives us more options for onboarding installs.
- Currently, only project config (".arcconfig") can load libraries. Allow user config ("~/.arcrc") to load libraries as well.
- Currently, only project config can set lint/unit engines. Allow user config to set default lint/unit engines.
- Add some type checking to "arc set-config".
- Add "arc set-config --show".
Test Plan:
- **load**
- Ran `arc set-config load xxx`, got error about format.
- Ran `arc set-config load ["apple"]`, got warning on running 'arc' commands (no such library) but was able to run 'arc set-config' again to clear it.
- Ran `arc set-config load ["/path/to/a/lib/src/"]`, worked.
- Ran `arc list --trace`, verified my library loaded in addition to `.arcconfig` libraries.
- Ran `arc list --load-phutil-library=xxx --trace`, verified only that library loaded.
- Ran `arc list --trace --load-phutil-library=apple --trace`, got hard error about bad library.
- Set `.arcconfig` to point at a bad library, verified hard error.
- **lint.engine** / **unit.engine**
- Removed lint engine from `.arcconfig`, ran "arc lint", got a run with specified engine.
- Removed unit engine from `.arcconfig`, ran "arc unit", got a run with specified engine.
- **--show**
- Ran `arc set-config --show`.
- **misc**
- Ran `arc get-config`.
Reviewers: csilvers, btrahan, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2618
2012-05-31 11:41:39 -07:00
|
|
|
*
|
|
|
|
* @task config
|
|
|
|
*
|
2011-02-19 11:36:08 -08:00
|
|
|
* @group workingcopy
|
|
|
|
*/
|
2012-01-31 12:07:05 -08:00
|
|
|
final class ArcanistWorkingCopyIdentity {
|
2011-01-09 15:22:25 -08:00
|
|
|
|
2012-06-13 16:02:29 -07:00
|
|
|
protected $localConfig;
|
2011-01-09 15:22:25 -08:00
|
|
|
protected $projectConfig;
|
2013-04-01 11:26:17 -07:00
|
|
|
protected $runtimeConfig;
|
2011-01-09 15:22:25 -08:00
|
|
|
protected $projectRoot;
|
|
|
|
|
2013-01-30 16:26:41 -08:00
|
|
|
public static function newDummyWorkingCopy() {
|
|
|
|
return new ArcanistWorkingCopyIdentity('/', array());
|
|
|
|
}
|
|
|
|
|
2011-01-09 15:22:25 -08:00
|
|
|
public static function newFromPath($path) {
|
|
|
|
$project_id = null;
|
|
|
|
$project_root = null;
|
|
|
|
$config = array();
|
|
|
|
foreach (Filesystem::walkToRoot($path) as $dir) {
|
|
|
|
$config_file = $dir.'/.arcconfig';
|
|
|
|
if (!Filesystem::pathExists($config_file)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$proj_raw = Filesystem::readFile($config_file);
|
2011-02-24 16:34:27 -08:00
|
|
|
$config = self::parseRawConfigFile($proj_raw, $config_file);
|
2011-01-09 15:22:25 -08:00
|
|
|
$project_root = $dir;
|
|
|
|
break;
|
|
|
|
}
|
Allow 'arc' to run without '.arcconfig'
Summary:
This is mostly an onboarding thing, but also allows "arc upload", "arc download", and "arc paste" to work anywhere on the system.
- Try to read the Phabricator install URI from arc global config if we can't find ".arcconfig".
- Build a WorkingCopy anyway if we can't find ".arcconfig", as long as we can find ".svn", ".git", or ".hg".
- Make all the workflows handle "no project ID" at least somewhat gracefully.
Test Plan:
- Ran "arc diff" in .arcconfig-less Mercurial, Git, and Subversion working copies.
- Ran "arc upload" and "arc download" from my desktop.
- Ran "arc paste" from somewhere random.
- Cleared my config and hit the error, got useful instructions.
Reviewers: btrahan, csilvers
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2424
2012-05-07 15:24:58 -07:00
|
|
|
|
|
|
|
if (!$project_root) {
|
|
|
|
foreach (Filesystem::walkToRoot($path) as $dir) {
|
|
|
|
$try = array(
|
|
|
|
$dir.'/.svn',
|
|
|
|
$dir.'/.hg',
|
|
|
|
$dir.'/.git',
|
|
|
|
);
|
|
|
|
foreach ($try as $trydir) {
|
|
|
|
if (Filesystem::pathExists($trydir)) {
|
|
|
|
$project_root = $dir;
|
|
|
|
break 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-09 15:22:25 -08:00
|
|
|
return new ArcanistWorkingCopyIdentity($project_root, $config);
|
|
|
|
}
|
|
|
|
|
2011-02-24 16:34:27 -08:00
|
|
|
public static function newFromRootAndConfigFile(
|
|
|
|
$root,
|
|
|
|
$config_raw,
|
|
|
|
$from_where) {
|
|
|
|
|
2013-08-22 16:02:41 -07:00
|
|
|
if ($config_raw === null) {
|
|
|
|
$config = array();
|
|
|
|
} else {
|
|
|
|
$config = self::parseRawConfigFile($config_raw, $from_where);
|
|
|
|
}
|
|
|
|
|
2011-02-15 14:57:24 -08:00
|
|
|
return new ArcanistWorkingCopyIdentity($root, $config);
|
|
|
|
}
|
|
|
|
|
2011-02-24 16:34:27 -08:00
|
|
|
private static function parseRawConfigFile($raw_config, $from_where) {
|
2011-02-15 14:57:24 -08:00
|
|
|
$proj = json_decode($raw_config, true);
|
|
|
|
if (!is_array($proj)) {
|
|
|
|
throw new Exception(
|
2011-02-24 16:34:27 -08:00
|
|
|
"Unable to parse '.arcconfig' file '{$from_where}'. The file contents ".
|
|
|
|
"should be valid JSON.\n\n".
|
|
|
|
"FILE CONTENTS\n".
|
|
|
|
substr($raw_config, 0, 2048));
|
2011-02-15 14:57:24 -08:00
|
|
|
}
|
|
|
|
$required_keys = array(
|
|
|
|
'project_id',
|
|
|
|
);
|
|
|
|
foreach ($required_keys as $key) {
|
|
|
|
if (!array_key_exists($key, $proj)) {
|
|
|
|
throw new Exception(
|
2011-02-24 16:34:27 -08:00
|
|
|
"Required key '{$key}' is missing from '.arcconfig' file ".
|
|
|
|
"'{$from_where}'.");
|
2011-02-15 14:57:24 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $proj;
|
|
|
|
}
|
|
|
|
|
2011-01-09 15:22:25 -08:00
|
|
|
protected function __construct($root, array $config) {
|
|
|
|
$this->projectRoot = $root;
|
|
|
|
$this->projectConfig = $config;
|
2012-06-13 16:02:29 -07:00
|
|
|
$this->localConfig = array();
|
2013-04-01 11:26:17 -07:00
|
|
|
$this->runtimeConfig = array();
|
2012-06-13 16:02:29 -07:00
|
|
|
|
|
|
|
$vc_dirs = array(
|
|
|
|
'.git',
|
|
|
|
'.hg',
|
|
|
|
'.svn',
|
|
|
|
);
|
2012-06-25 17:13:29 -07:00
|
|
|
$found_meta_dir = false;
|
2012-06-13 16:02:29 -07:00
|
|
|
foreach ($vc_dirs as $dir) {
|
2012-06-25 17:13:29 -07:00
|
|
|
$meta_path = Filesystem::resolvePath(
|
|
|
|
$dir,
|
2012-06-13 16:02:29 -07:00
|
|
|
$this->projectRoot);
|
2012-06-25 17:13:29 -07:00
|
|
|
if (Filesystem::pathExists($meta_path)) {
|
|
|
|
$found_meta_dir = true;
|
|
|
|
$local_path = Filesystem::resolvePath(
|
|
|
|
'arc/config',
|
|
|
|
$meta_path);
|
|
|
|
if (Filesystem::pathExists($local_path)) {
|
|
|
|
$file = Filesystem::readFile($local_path);
|
|
|
|
if ($file) {
|
|
|
|
$this->localConfig = json_decode($file, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$found_meta_dir) {
|
|
|
|
// Try for a single higher-level .svn directory as used by svn 1.7+
|
|
|
|
foreach (Filesystem::walkToRoot($this->projectRoot) as $parent_path) {
|
|
|
|
$local_path = Filesystem::resolvePath(
|
|
|
|
'.svn/arc/config',
|
|
|
|
$parent_path);
|
|
|
|
if (Filesystem::pathExists($local_path)) {
|
|
|
|
$file = Filesystem::readFile($local_path);
|
|
|
|
if ($file) {
|
|
|
|
$this->localConfig = json_decode($file, true);
|
|
|
|
}
|
2012-06-13 16:02:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-09 15:22:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getProjectID() {
|
|
|
|
return $this->getConfig('project_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getProjectRoot() {
|
|
|
|
return $this->projectRoot;
|
|
|
|
}
|
|
|
|
|
Lay groundwork for configuration-driven linters
Summary:
Ref T2039. That task has a bunch of discussion, but basically we do a poor job of serving the midrange of lint configuration right now.
If you have something simple, the default linters work.
If you have something complex, building your own engine lets you do whatever you want.
But many users want something in between, which isn't really well accommodated. The idea is to let you write a `.arclint` file, which looks something like this:
{
"linters" : {
"css" : {
"type" : "csslint",
"include" : "(\.css$)",
"exclude" : "(^externals/)",
"bin" : "/usr/local/bin/csslint"
},
"js" : {
"type" : "jshint",
"include" : "(\.js$)",
"exclude" : "(^externals/)",
"bin" : "support/bin/jshint",
"interpreter" : "/usr/local/bin/node"
}
}
}
...which will provide a bunch of common options around lint severity, interpreter and binary locaitons, included and excluded files, etc.
This implements some basics, and very rough support in the Filename linter.
Test Plan:
Generated a `.arclint` file and saw it apply filename lint correctly. Used `debug` mode and tried invalid regexps.
{
"debug" : true,
"linters" : {
"filename" : {
"type" : "filename",
"exclude" : ["@^externals/@"]
}
}
}
Next steps include:
- Provide an external linter archetype (T3186) and expose a common set of configuration here ("bin", "interpreter", "flags", "severity").
- Provide a `.arcunit` file which works similarly (it can probably be simpler).
Reviewers: btrahan, Firehed
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T2039
Differential Revision: https://secure.phabricator.com/D6797
2013-08-22 16:02:16 -07:00
|
|
|
public function getProjectPath($to_file) {
|
|
|
|
return $this->projectRoot.'/'.$to_file;
|
|
|
|
}
|
|
|
|
|
2011-01-09 15:22:25 -08:00
|
|
|
public function getConduitURI() {
|
|
|
|
return $this->getConfig('conduit_uri');
|
|
|
|
}
|
|
|
|
|
Allow global config to load libraries and set test engines
Summary:
Khan Academy is looking into lint configuration, but doesn't use ".arcconfig" because they have a large number of repositories. Making configuration more flexible generally gives us more options for onboarding installs.
- Currently, only project config (".arcconfig") can load libraries. Allow user config ("~/.arcrc") to load libraries as well.
- Currently, only project config can set lint/unit engines. Allow user config to set default lint/unit engines.
- Add some type checking to "arc set-config".
- Add "arc set-config --show".
Test Plan:
- **load**
- Ran `arc set-config load xxx`, got error about format.
- Ran `arc set-config load ["apple"]`, got warning on running 'arc' commands (no such library) but was able to run 'arc set-config' again to clear it.
- Ran `arc set-config load ["/path/to/a/lib/src/"]`, worked.
- Ran `arc list --trace`, verified my library loaded in addition to `.arcconfig` libraries.
- Ran `arc list --load-phutil-library=xxx --trace`, verified only that library loaded.
- Ran `arc list --trace --load-phutil-library=apple --trace`, got hard error about bad library.
- Set `.arcconfig` to point at a bad library, verified hard error.
- **lint.engine** / **unit.engine**
- Removed lint engine from `.arcconfig`, ran "arc lint", got a run with specified engine.
- Removed unit engine from `.arcconfig`, ran "arc unit", got a run with specified engine.
- **--show**
- Ran `arc set-config --show`.
- **misc**
- Ran `arc get-config`.
Reviewers: csilvers, btrahan, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2618
2012-05-31 11:41:39 -07:00
|
|
|
|
|
|
|
/* -( Config )------------------------------------------------------------- */
|
|
|
|
|
Enrich arc configuration and add stronger typing
Summary:
See <https://github.com/facebook/arcanist/issues/45>
Currently, when the user types `arc set-config x false`, we set it as the string "false", which is usually not desirable. We have some steps toward typed config already, but expand on what we have and move as much stuff as possible into it, including all the config settings that aren't currently documented (there are still some lint-specific and project-specific settings not present here, but this is most of it).
Also make the `phutil_libraries` key a legacy name for `load`, and `immutable_history` a legacy name for `history.immutable`. Generally the goal here is to make config simpler and bring it more in-line with Git/Mercurial, which use dotted hierarchies.
I'll add some documentation here but I think most of the changes should be fairly straightforward.
Test Plan:
- `arc set-config history.immutable on` (And similar -- sets to boolean true.)
- `arc set-config history.immutable off` (And similar -- sets to boolean false.)
- `arc set-config history.immutable derp` (And similar -- raises exception.)
- `arc set-config history.immutable ''` (And similar -- removes setting value.)
- `arc set-config --show`
- `arc get-config`
- `arc get-config base`
Reviewers: dschleimer, bos, btrahan, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1546
Differential Revision: https://secure.phabricator.com/D3045
2012-07-25 18:37:09 -07:00
|
|
|
public function getProjectConfig() {
|
|
|
|
return $this->projectConfig;
|
|
|
|
}
|
Allow global config to load libraries and set test engines
Summary:
Khan Academy is looking into lint configuration, but doesn't use ".arcconfig" because they have a large number of repositories. Making configuration more flexible generally gives us more options for onboarding installs.
- Currently, only project config (".arcconfig") can load libraries. Allow user config ("~/.arcrc") to load libraries as well.
- Currently, only project config can set lint/unit engines. Allow user config to set default lint/unit engines.
- Add some type checking to "arc set-config".
- Add "arc set-config --show".
Test Plan:
- **load**
- Ran `arc set-config load xxx`, got error about format.
- Ran `arc set-config load ["apple"]`, got warning on running 'arc' commands (no such library) but was able to run 'arc set-config' again to clear it.
- Ran `arc set-config load ["/path/to/a/lib/src/"]`, worked.
- Ran `arc list --trace`, verified my library loaded in addition to `.arcconfig` libraries.
- Ran `arc list --load-phutil-library=xxx --trace`, verified only that library loaded.
- Ran `arc list --trace --load-phutil-library=apple --trace`, got hard error about bad library.
- Set `.arcconfig` to point at a bad library, verified hard error.
- **lint.engine** / **unit.engine**
- Removed lint engine from `.arcconfig`, ran "arc lint", got a run with specified engine.
- Removed unit engine from `.arcconfig`, ran "arc unit", got a run with specified engine.
- **--show**
- Ran `arc set-config --show`.
- **misc**
- Ran `arc get-config`.
Reviewers: csilvers, btrahan, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2618
2012-05-31 11:41:39 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Read a configuration directive from project configuration. This reads ONLY
|
|
|
|
* permanent project configuration (i.e., ".arcconfig"), not other
|
|
|
|
* configuration sources. See @{method:getConfigFromAnySource} to read from
|
|
|
|
* user configuration.
|
|
|
|
*
|
|
|
|
* @param key Key to read.
|
|
|
|
* @param wild Default value if key is not found.
|
|
|
|
* @return wild Value, or default value if not found.
|
|
|
|
*
|
|
|
|
* @task config
|
|
|
|
*/
|
|
|
|
public function getConfig($key, $default = null) {
|
Enrich arc configuration and add stronger typing
Summary:
See <https://github.com/facebook/arcanist/issues/45>
Currently, when the user types `arc set-config x false`, we set it as the string "false", which is usually not desirable. We have some steps toward typed config already, but expand on what we have and move as much stuff as possible into it, including all the config settings that aren't currently documented (there are still some lint-specific and project-specific settings not present here, but this is most of it).
Also make the `phutil_libraries` key a legacy name for `load`, and `immutable_history` a legacy name for `history.immutable`. Generally the goal here is to make config simpler and bring it more in-line with Git/Mercurial, which use dotted hierarchies.
I'll add some documentation here but I think most of the changes should be fairly straightforward.
Test Plan:
- `arc set-config history.immutable on` (And similar -- sets to boolean true.)
- `arc set-config history.immutable off` (And similar -- sets to boolean false.)
- `arc set-config history.immutable derp` (And similar -- raises exception.)
- `arc set-config history.immutable ''` (And similar -- removes setting value.)
- `arc set-config --show`
- `arc get-config`
- `arc get-config base`
Reviewers: dschleimer, bos, btrahan, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1546
Differential Revision: https://secure.phabricator.com/D3045
2012-07-25 18:37:09 -07:00
|
|
|
$settings = new ArcanistSettings();
|
|
|
|
|
|
|
|
$pval = idx($this->projectConfig, $key);
|
|
|
|
|
|
|
|
// Test for older names in the per-project config only, since
|
|
|
|
// they've only been used there.
|
|
|
|
if ($pval === null) {
|
|
|
|
$legacy = $settings->getLegacyName($key);
|
|
|
|
if ($legacy) {
|
|
|
|
$pval = $this->getConfig($legacy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($pval === null) {
|
|
|
|
$pval = $default;
|
|
|
|
} else {
|
|
|
|
$pval = $settings->willReadValue($key, $pval);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $pval;
|
Allow global config to load libraries and set test engines
Summary:
Khan Academy is looking into lint configuration, but doesn't use ".arcconfig" because they have a large number of repositories. Making configuration more flexible generally gives us more options for onboarding installs.
- Currently, only project config (".arcconfig") can load libraries. Allow user config ("~/.arcrc") to load libraries as well.
- Currently, only project config can set lint/unit engines. Allow user config to set default lint/unit engines.
- Add some type checking to "arc set-config".
- Add "arc set-config --show".
Test Plan:
- **load**
- Ran `arc set-config load xxx`, got error about format.
- Ran `arc set-config load ["apple"]`, got warning on running 'arc' commands (no such library) but was able to run 'arc set-config' again to clear it.
- Ran `arc set-config load ["/path/to/a/lib/src/"]`, worked.
- Ran `arc list --trace`, verified my library loaded in addition to `.arcconfig` libraries.
- Ran `arc list --load-phutil-library=xxx --trace`, verified only that library loaded.
- Ran `arc list --trace --load-phutil-library=apple --trace`, got hard error about bad library.
- Set `.arcconfig` to point at a bad library, verified hard error.
- **lint.engine** / **unit.engine**
- Removed lint engine from `.arcconfig`, ran "arc lint", got a run with specified engine.
- Removed unit engine from `.arcconfig`, ran "arc unit", got a run with specified engine.
- **--show**
- Ran `arc set-config --show`.
- **misc**
- Ran `arc get-config`.
Reviewers: csilvers, btrahan, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2618
2012-05-31 11:41:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-13 16:02:29 -07:00
|
|
|
/**
|
|
|
|
* Read a configuration directive from local configuration. This
|
|
|
|
* reads ONLY the per-working copy configuration,
|
|
|
|
* i.e. .(git|hg|svn)/arc/config, and not other configuration
|
|
|
|
* sources. See @{method:getConfigFromAnySource} to read from any
|
|
|
|
* config source or @{method:getConfig} to read permanent
|
|
|
|
* project-level config.
|
|
|
|
*
|
|
|
|
* @task config
|
|
|
|
*/
|
|
|
|
public function getLocalConfig($key, $default=null) {
|
|
|
|
return idx($this->localConfig, $key, $default);
|
|
|
|
}
|
|
|
|
|
Allow global config to load libraries and set test engines
Summary:
Khan Academy is looking into lint configuration, but doesn't use ".arcconfig" because they have a large number of repositories. Making configuration more flexible generally gives us more options for onboarding installs.
- Currently, only project config (".arcconfig") can load libraries. Allow user config ("~/.arcrc") to load libraries as well.
- Currently, only project config can set lint/unit engines. Allow user config to set default lint/unit engines.
- Add some type checking to "arc set-config".
- Add "arc set-config --show".
Test Plan:
- **load**
- Ran `arc set-config load xxx`, got error about format.
- Ran `arc set-config load ["apple"]`, got warning on running 'arc' commands (no such library) but was able to run 'arc set-config' again to clear it.
- Ran `arc set-config load ["/path/to/a/lib/src/"]`, worked.
- Ran `arc list --trace`, verified my library loaded in addition to `.arcconfig` libraries.
- Ran `arc list --load-phutil-library=xxx --trace`, verified only that library loaded.
- Ran `arc list --trace --load-phutil-library=apple --trace`, got hard error about bad library.
- Set `.arcconfig` to point at a bad library, verified hard error.
- **lint.engine** / **unit.engine**
- Removed lint engine from `.arcconfig`, ran "arc lint", got a run with specified engine.
- Removed unit engine from `.arcconfig`, ran "arc unit", got a run with specified engine.
- **--show**
- Ran `arc set-config --show`.
- **misc**
- Ran `arc get-config`.
Reviewers: csilvers, btrahan, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2618
2012-05-31 11:41:39 -07:00
|
|
|
/**
|
|
|
|
* Read a configuration directive from any available configuration source.
|
|
|
|
* In contrast to @{method:getConfig}, this will look for the directive in
|
2012-06-13 16:02:29 -07:00
|
|
|
* local and user configuration in addition to project configuration.
|
|
|
|
* The precedence is local > project > user
|
Allow global config to load libraries and set test engines
Summary:
Khan Academy is looking into lint configuration, but doesn't use ".arcconfig" because they have a large number of repositories. Making configuration more flexible generally gives us more options for onboarding installs.
- Currently, only project config (".arcconfig") can load libraries. Allow user config ("~/.arcrc") to load libraries as well.
- Currently, only project config can set lint/unit engines. Allow user config to set default lint/unit engines.
- Add some type checking to "arc set-config".
- Add "arc set-config --show".
Test Plan:
- **load**
- Ran `arc set-config load xxx`, got error about format.
- Ran `arc set-config load ["apple"]`, got warning on running 'arc' commands (no such library) but was able to run 'arc set-config' again to clear it.
- Ran `arc set-config load ["/path/to/a/lib/src/"]`, worked.
- Ran `arc list --trace`, verified my library loaded in addition to `.arcconfig` libraries.
- Ran `arc list --load-phutil-library=xxx --trace`, verified only that library loaded.
- Ran `arc list --trace --load-phutil-library=apple --trace`, got hard error about bad library.
- Set `.arcconfig` to point at a bad library, verified hard error.
- **lint.engine** / **unit.engine**
- Removed lint engine from `.arcconfig`, ran "arc lint", got a run with specified engine.
- Removed unit engine from `.arcconfig`, ran "arc unit", got a run with specified engine.
- **--show**
- Ran `arc set-config --show`.
- **misc**
- Ran `arc get-config`.
Reviewers: csilvers, btrahan, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2618
2012-05-31 11:41:39 -07:00
|
|
|
*
|
|
|
|
* @param key Key to read.
|
|
|
|
* @param wild Default value if key is not found.
|
|
|
|
* @return wild Value, or default value if not found.
|
|
|
|
*
|
|
|
|
* @task config
|
|
|
|
*/
|
|
|
|
public function getConfigFromAnySource($key, $default = null) {
|
Enrich arc configuration and add stronger typing
Summary:
See <https://github.com/facebook/arcanist/issues/45>
Currently, when the user types `arc set-config x false`, we set it as the string "false", which is usually not desirable. We have some steps toward typed config already, but expand on what we have and move as much stuff as possible into it, including all the config settings that aren't currently documented (there are still some lint-specific and project-specific settings not present here, but this is most of it).
Also make the `phutil_libraries` key a legacy name for `load`, and `immutable_history` a legacy name for `history.immutable`. Generally the goal here is to make config simpler and bring it more in-line with Git/Mercurial, which use dotted hierarchies.
I'll add some documentation here but I think most of the changes should be fairly straightforward.
Test Plan:
- `arc set-config history.immutable on` (And similar -- sets to boolean true.)
- `arc set-config history.immutable off` (And similar -- sets to boolean false.)
- `arc set-config history.immutable derp` (And similar -- raises exception.)
- `arc set-config history.immutable ''` (And similar -- removes setting value.)
- `arc set-config --show`
- `arc get-config`
- `arc get-config base`
Reviewers: dschleimer, bos, btrahan, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1546
Differential Revision: https://secure.phabricator.com/D3045
2012-07-25 18:37:09 -07:00
|
|
|
$settings = new ArcanistSettings();
|
Allow global config to load libraries and set test engines
Summary:
Khan Academy is looking into lint configuration, but doesn't use ".arcconfig" because they have a large number of repositories. Making configuration more flexible generally gives us more options for onboarding installs.
- Currently, only project config (".arcconfig") can load libraries. Allow user config ("~/.arcrc") to load libraries as well.
- Currently, only project config can set lint/unit engines. Allow user config to set default lint/unit engines.
- Add some type checking to "arc set-config".
- Add "arc set-config --show".
Test Plan:
- **load**
- Ran `arc set-config load xxx`, got error about format.
- Ran `arc set-config load ["apple"]`, got warning on running 'arc' commands (no such library) but was able to run 'arc set-config' again to clear it.
- Ran `arc set-config load ["/path/to/a/lib/src/"]`, worked.
- Ran `arc list --trace`, verified my library loaded in addition to `.arcconfig` libraries.
- Ran `arc list --load-phutil-library=xxx --trace`, verified only that library loaded.
- Ran `arc list --trace --load-phutil-library=apple --trace`, got hard error about bad library.
- Set `.arcconfig` to point at a bad library, verified hard error.
- **lint.engine** / **unit.engine**
- Removed lint engine from `.arcconfig`, ran "arc lint", got a run with specified engine.
- Removed unit engine from `.arcconfig`, ran "arc unit", got a run with specified engine.
- **--show**
- Ran `arc set-config --show`.
- **misc**
- Ran `arc get-config`.
Reviewers: csilvers, btrahan, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2618
2012-05-31 11:41:39 -07:00
|
|
|
|
2013-04-01 11:26:17 -07:00
|
|
|
// try runtime config first
|
|
|
|
$pval = idx($this->runtimeConfig, $key);
|
|
|
|
|
|
|
|
// try local config
|
|
|
|
if ($pval === null) {
|
|
|
|
$pval = $this->getLocalConfig($key);
|
|
|
|
}
|
2012-06-13 16:02:29 -07:00
|
|
|
|
|
|
|
// then per-project config
|
|
|
|
if ($pval === null) {
|
|
|
|
$pval = $this->getConfig($key);
|
|
|
|
}
|
Allow global config to load libraries and set test engines
Summary:
Khan Academy is looking into lint configuration, but doesn't use ".arcconfig" because they have a large number of repositories. Making configuration more flexible generally gives us more options for onboarding installs.
- Currently, only project config (".arcconfig") can load libraries. Allow user config ("~/.arcrc") to load libraries as well.
- Currently, only project config can set lint/unit engines. Allow user config to set default lint/unit engines.
- Add some type checking to "arc set-config".
- Add "arc set-config --show".
Test Plan:
- **load**
- Ran `arc set-config load xxx`, got error about format.
- Ran `arc set-config load ["apple"]`, got warning on running 'arc' commands (no such library) but was able to run 'arc set-config' again to clear it.
- Ran `arc set-config load ["/path/to/a/lib/src/"]`, worked.
- Ran `arc list --trace`, verified my library loaded in addition to `.arcconfig` libraries.
- Ran `arc list --load-phutil-library=xxx --trace`, verified only that library loaded.
- Ran `arc list --trace --load-phutil-library=apple --trace`, got hard error about bad library.
- Set `.arcconfig` to point at a bad library, verified hard error.
- **lint.engine** / **unit.engine**
- Removed lint engine from `.arcconfig`, ran "arc lint", got a run with specified engine.
- Removed unit engine from `.arcconfig`, ran "arc unit", got a run with specified engine.
- **--show**
- Ran `arc set-config --show`.
- **misc**
- Ran `arc get-config`.
Reviewers: csilvers, btrahan, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2618
2012-05-31 11:41:39 -07:00
|
|
|
|
Enrich arc configuration and add stronger typing
Summary:
See <https://github.com/facebook/arcanist/issues/45>
Currently, when the user types `arc set-config x false`, we set it as the string "false", which is usually not desirable. We have some steps toward typed config already, but expand on what we have and move as much stuff as possible into it, including all the config settings that aren't currently documented (there are still some lint-specific and project-specific settings not present here, but this is most of it).
Also make the `phutil_libraries` key a legacy name for `load`, and `immutable_history` a legacy name for `history.immutable`. Generally the goal here is to make config simpler and bring it more in-line with Git/Mercurial, which use dotted hierarchies.
I'll add some documentation here but I think most of the changes should be fairly straightforward.
Test Plan:
- `arc set-config history.immutable on` (And similar -- sets to boolean true.)
- `arc set-config history.immutable off` (And similar -- sets to boolean false.)
- `arc set-config history.immutable derp` (And similar -- raises exception.)
- `arc set-config history.immutable ''` (And similar -- removes setting value.)
- `arc set-config --show`
- `arc get-config`
- `arc get-config base`
Reviewers: dschleimer, bos, btrahan, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1546
Differential Revision: https://secure.phabricator.com/D3045
2012-07-25 18:37:09 -07:00
|
|
|
// now try global (i.e. user-level) config
|
2012-06-13 16:02:29 -07:00
|
|
|
if ($pval === null) {
|
|
|
|
$global_config = ArcanistBaseWorkflow::readGlobalArcConfig();
|
2012-06-25 15:14:11 -07:00
|
|
|
$pval = idx($global_config, $key);
|
|
|
|
}
|
|
|
|
|
Enrich arc configuration and add stronger typing
Summary:
See <https://github.com/facebook/arcanist/issues/45>
Currently, when the user types `arc set-config x false`, we set it as the string "false", which is usually not desirable. We have some steps toward typed config already, but expand on what we have and move as much stuff as possible into it, including all the config settings that aren't currently documented (there are still some lint-specific and project-specific settings not present here, but this is most of it).
Also make the `phutil_libraries` key a legacy name for `load`, and `immutable_history` a legacy name for `history.immutable`. Generally the goal here is to make config simpler and bring it more in-line with Git/Mercurial, which use dotted hierarchies.
I'll add some documentation here but I think most of the changes should be fairly straightforward.
Test Plan:
- `arc set-config history.immutable on` (And similar -- sets to boolean true.)
- `arc set-config history.immutable off` (And similar -- sets to boolean false.)
- `arc set-config history.immutable derp` (And similar -- raises exception.)
- `arc set-config history.immutable ''` (And similar -- removes setting value.)
- `arc set-config --show`
- `arc get-config`
- `arc get-config base`
Reviewers: dschleimer, bos, btrahan, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1546
Differential Revision: https://secure.phabricator.com/D3045
2012-07-25 18:37:09 -07:00
|
|
|
// Finally, try system-level config.
|
2012-06-25 15:14:11 -07:00
|
|
|
if ($pval === null) {
|
|
|
|
$system_config = ArcanistBaseWorkflow::readSystemArcConfig();
|
|
|
|
$pval = idx($system_config, $key);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($pval === null) {
|
|
|
|
$pval = $default;
|
Enrich arc configuration and add stronger typing
Summary:
See <https://github.com/facebook/arcanist/issues/45>
Currently, when the user types `arc set-config x false`, we set it as the string "false", which is usually not desirable. We have some steps toward typed config already, but expand on what we have and move as much stuff as possible into it, including all the config settings that aren't currently documented (there are still some lint-specific and project-specific settings not present here, but this is most of it).
Also make the `phutil_libraries` key a legacy name for `load`, and `immutable_history` a legacy name for `history.immutable`. Generally the goal here is to make config simpler and bring it more in-line with Git/Mercurial, which use dotted hierarchies.
I'll add some documentation here but I think most of the changes should be fairly straightforward.
Test Plan:
- `arc set-config history.immutable on` (And similar -- sets to boolean true.)
- `arc set-config history.immutable off` (And similar -- sets to boolean false.)
- `arc set-config history.immutable derp` (And similar -- raises exception.)
- `arc set-config history.immutable ''` (And similar -- removes setting value.)
- `arc set-config --show`
- `arc get-config`
- `arc get-config base`
Reviewers: dschleimer, bos, btrahan, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1546
Differential Revision: https://secure.phabricator.com/D3045
2012-07-25 18:37:09 -07:00
|
|
|
} else {
|
|
|
|
$pval = $settings->willReadValue($key, $pval);
|
2012-06-13 16:02:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return $pval;
|
|
|
|
|
2011-01-09 15:22:25 -08:00
|
|
|
}
|
|
|
|
|
2013-04-01 11:26:17 -07:00
|
|
|
/**
|
|
|
|
* Sets a runtime config value that takes precedence over any static
|
|
|
|
* config values.
|
|
|
|
*
|
|
|
|
* @param key Key to set.
|
|
|
|
* @param value The value of the key.
|
|
|
|
*
|
|
|
|
* @task config
|
|
|
|
*/
|
|
|
|
public function setRuntimeConfig($key, $value) {
|
|
|
|
$this->runtimeConfig[$key] = $value;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-01-09 15:22:25 -08:00
|
|
|
}
|