From 42e0f5b13bd68be5151c40f33fd072dfdf01af06 Mon Sep 17 00:00:00 2001 From: Fred Emmott Date: Sat, 24 Sep 2016 12:08:50 -0700 Subject: [PATCH] Better HackCodegenConfig::getRootDir() This should usually be used via composer, so it will end up in PROJECTROOT/vendor/facebook/hack-codegen/ If this is the case, go for that, rather than PROJECTROOT/vendor/facebook/hack-codegen/src/ Tested with `codegen_generated_from_script()` with no args; generated file now contains: ``` * To re-generate this file run vendor/phpunit/phpunit/phpunit ``` Previously it had the *full* path to the script - /Users/fred/..... --- src/HackCodegenConfig.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/HackCodegenConfig.php b/src/HackCodegenConfig.php index 9a40fd59..a4a56150 100644 --- a/src/HackCodegenConfig.php +++ b/src/HackCodegenConfig.php @@ -37,7 +37,14 @@ public function getMaxLineLength(): int { return 80; } + <<__Memoize>> public function getRootDir(): string { - return __DIR__; + $dir = __DIR__; + $root_pos = strpos($dir, '/vendor/facebook/hack-codegen/'); + if ($root_pos === false) { + return $dir; + } + $root = Str::substr($dir, 0, $root_pos); + return $root; } }