Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14424223
D9824.id23575.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
9 KB
Referenced Files
None
Subscribers
None
D9824.id23575.diff
View Options
diff --git a/scripts/phutil_rebuild_map.php b/scripts/phutil_rebuild_map.php
--- a/scripts/phutil_rebuild_map.php
+++ b/scripts/phutil_rebuild_map.php
@@ -44,7 +44,7 @@
array(
'name' => 'root',
'wildcard' => true,
- )
+ ),
));
$root = $args->getArg('root');
@@ -62,9 +62,18 @@
}
if ($args->getArg('show')) {
- $builder->setShowMap(true);
- $builder->setUgly($args->getArg('ugly'));
+ $builder->setDryRun(true);
+}
+
+$library_map = $builder->buildMap();
+
+if ($args->getArg('show')) {
+ if ($args->getArg('ugly')) {
+ echo json_encode($library_map);
+ } else {
+ $json = new PhutilJSON();
+ echo $json->encodeFormatted($library_map);
+ }
}
-$builder->buildMap();
exit(0);
diff --git a/src/__tests__/PhutilInfrastructureTestCase.php b/src/__tests__/PhutilInfrastructureTestCase.php
--- a/src/__tests__/PhutilInfrastructureTestCase.php
+++ b/src/__tests__/PhutilInfrastructureTestCase.php
@@ -6,8 +6,18 @@
* that all symbols can be loaded correctly. It can catch problems like
* missing methods in descendants of abstract base classes.
*/
- public function testEverythingImplemented() {
- id(new PhutilSymbolLoader())->selectAndLoadSymbols();
- $this->assertTrue(true);
+ public function testLibraryMap() {
+ $root = phutil_get_library_root('phutil');
+
+ $new_library_map = id(new PhutilLibraryMapBuilder($root))
+ ->setQuiet(true)
+ ->setDryRun(true)
+ ->buildMap();
+
+ $bootloader = PhutilBootloader::getInstance();
+ $old_library_map = $bootloader->getLibraryMap('phutil');
+ unset($old_library_map[PhutilLibraryMapBuilder::LIBRARY_MAP_VERSION_KEY]);
+
+ $this->assertEqual($new_library_map, $old_library_map);
}
}
diff --git a/src/moduleutils/PhutilLibraryMapBuilder.php b/src/moduleutils/PhutilLibraryMapBuilder.php
--- a/src/moduleutils/PhutilLibraryMapBuilder.php
+++ b/src/moduleutils/PhutilLibraryMapBuilder.php
@@ -14,8 +14,7 @@
private $root;
private $quiet;
private $subprocessLimit = 8;
- private $ugly;
- private $showMap;
+ private $dryRun = false;
const LIBRARY_MAP_VERSION_KEY = '__library_version__';
const LIBRARY_MAP_VERSION = 2;
@@ -26,7 +25,6 @@
/* -( Mapping libphutil Libraries )---------------------------------------- */
-
/**
* Create a new map builder for a library.
*
@@ -38,12 +36,11 @@
$this->root = $root;
}
-
/**
- * Control status output. Use --quiet to set this.
+ * Control status output. Use `--quiet` to set this.
*
- * @param bool If true, don't show status output.
- * @return this
+ * @param bool If true, don't show status output.
+ * @return this
*
* @task map
*/
@@ -52,12 +49,11 @@
return $this;
}
-
/**
- * Control subprocess parallelism limit. Use --limit to set this.
+ * Control subprocess parallelism limit. Use `--limit` to set this.
*
- * @param int Maximum number of subprocesses to run in parallel.
- * @return this
+ * @param int Maximum number of subprocesses to run in parallel.
+ * @return this
*
* @task map
*/
@@ -66,52 +62,33 @@
return $this;
}
-
- /**
- * Control whether the ugly (but fast) or pretty (but slower) JSON formatter
- * is used.
- *
- * @param bool If true, use the fastest formatter.
- * @return this
- *
- * @task map
- */
- public function setUgly($ugly) {
- $this->ugly = $ugly;
- return $this;
- }
-
-
/**
* Control whether the map should be rebuilt, or just shown (printed to
* stdout in JSON).
*
- * @param bool If true, show map instead of updating.
+ * @param bool If true, show map instead of updating.
* @return this
*
* @task map
*/
- public function setShowMap($show_map) {
- $this->showMap = $show_map;
+ public function setDryRun($dry_run) {
+ $this->dryRun = $dry_run;
return $this;
}
-
/**
* Build or rebuild the library map.
*
- * @return this
+ * @return dict
*
* @task map
*/
public function buildMap() {
-
// Identify all the ".php" source files in the library.
$this->log("Finding source files...\n");
$source_map = $this->loadSourceFileMap();
$this->log("Found ".number_format(count($source_map))." files.\n");
-
// Load the symbol cache with existing parsed symbols. This allows us
// to remap libraries quickly by analyzing only changed files.
$this->log("Loading symbol cache...\n");
@@ -132,7 +109,6 @@
}
$this->log("Found ".number_format(count($symbol_map))." files in cache.\n");
-
// Run the analyzer on any files which need analysis.
if ($futures) {
$limit = $this->subprocessLimit;
@@ -165,43 +141,29 @@
$this->log("\nDone.\n");
}
-
// We're done building the cache, so write it out immediately. Note that
// we've only retained entries for files we found, so this implicitly cleans
// out old cache entries.
$this->writeSymbolCache($symbol_map, $source_map);
-
// Our map is up to date, so either show it on stdout or write it to disk.
+ $this->log("Building library map...\n");
+ $library_map = $this->buildLibraryMap($symbol_map);
- if ($this->showMap) {
- $this->log("Showing map...\n");
-
- if ($this->ugly) {
- echo json_encode($symbol_map);
- } else {
- $json = new PhutilJSON();
- echo $json->encodeFormatted($symbol_map);
- }
- } else {
- $this->log("Building library map...\n");
- $library_map = $this->buildLibraryMap($symbol_map);
-
+ if (!$this->dryRun) {
$this->log("Writing map...\n");
$this->writeLibraryMap($library_map);
}
$this->log("Done.\n");
-
- return $this;
+ return $library_map;
}
-
/**
* Write a status message to the user, if not running in quiet mode.
*
- * @param string Message to write.
- * @return this
+ * @param string Message to write.
+ * @return this
*
* @task map
*/
@@ -215,13 +177,12 @@
/* -( Path Management )---------------------------------------------------- */
-
/**
* Get the path to some file in the library.
*
- * @param string A library-relative path. If omitted, returns the library
- * root path.
- * @return string An absolute path.
+ * @param string A library-relative path. If omitted, returns the library
+ * root path.
+ * @return string An absolute path.
*
* @task path
*/
@@ -229,7 +190,6 @@
return $this->root.'/'.$path;
}
-
/**
* Get the path to the symbol cache file.
*
@@ -241,7 +201,6 @@
return $this->getPath('.phutil_module_cache');
}
-
/**
* Get the path to the map file.
*
@@ -253,7 +212,6 @@
return $this->getPath('__phutil_library_map__.php');
}
-
/**
* Get the path to the library init file.
*
@@ -268,12 +226,11 @@
/* -( Symbol Analysis and Caching )---------------------------------------- */
-
/**
* Load the library symbol cache, if it exists and is readable and valid.
*
- * @return dict Map of content hashes to cache of output from
- * `phutil_symbols.php`.
+ * @return dict Map of content hashes to cache of output from
+ * `phutil_symbols.php`.
*
* @task symbol
*/
@@ -304,12 +261,11 @@
return $symbol_cache;
}
-
/**
* Write a symbol map to disk cache.
*
- * @param dict Symbol map of relative paths to symbols.
- * @param dict Source map (like @{method:loadSourceFileMap}).
+ * @param dict Symbol map of relative paths to symbols.
+ * @param dict Source map (like @{method:loadSourceFileMap}).
* @return void
*
* @task symbol
@@ -333,7 +289,6 @@
}
}
-
/**
* Drop the symbol cache, forcing a clean rebuild.
*
@@ -346,13 +301,12 @@
Filesystem::remove($this->getPathForSymbolCache());
}
-
/**
* Build a future which returns a `phutil_symbols.php` analysis of a source
* file.
*
- * @param string Relative path to the source file to analyze.
- * @return Future Analysis future.
+ * @param string Relative path to the source file to analyze.
+ * @return Future Analysis future.
*
* @task symbol
*/
@@ -366,7 +320,6 @@
/* -( Source Management )-------------------------------------------------- */
-
/**
* Build a map of all source files in a library to hashes of their content.
* Returns an array like this:
@@ -376,7 +329,7 @@
* // ...
* );
*
- * @return dict Map of library-relative paths to content hashes.
+ * @return dict Map of library-relative paths to content hashes.
* @task source
*/
private function loadSourceFileMap() {
@@ -418,7 +371,6 @@
return $map;
}
-
/**
* Convert the symbol analysis of all the source files in the library into
* a library map.
@@ -470,7 +422,6 @@
return $library_map;
}
-
/**
* Write a finalized library map.
*
@@ -487,7 +438,7 @@
self::LIBRARY_MAP_VERSION_KEY => $version,
) + $library_map;
- $library_map = var_export($library_map, $return_string = true);
+ $library_map = var_export($library_map, true);
$library_map = preg_replace('/\s+$/m', '', $library_map);
$library_map = preg_replace('/array \(/', 'array(', $library_map);
$at = '@';
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 26, 9:42 AM (10 h, 59 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6929002
Default Alt Text
D9824.id23575.diff (9 KB)
Attached To
Mode
D9824: Improve the `PhutilInfrastructureTestCase` unit tests
Attached
Detach File
Event Timeline
Log In to Comment