From af27365b6bf1a3800020783f24108a091bce5eb1 Mon Sep 17 00:00:00 2001 From: Fred Emmott Date: Tue, 26 Sep 2017 10:28:49 -0700 Subject: [PATCH] Search recursively upwards for an autoloader --- bin/hhast-lint | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/bin/hhast-lint b/bin/hhast-lint index d6f744958..0dc1cabf8 100755 --- a/bin/hhast-lint +++ b/bin/hhast-lint @@ -13,6 +13,26 @@ namespace Facebook\HHAST\__Private; -require_once(__DIR__.'/../vendor/hh_autoload.php'); +$root = realpath(__DIR__.'/..'); +$found_autoloader = false; +while (true) { + $autoloader = $root.'/vendor/hh_autoload.php'; + if (file_exists($autoloader)) { + $found_autoloader = true; + require_once($autoloader); + break; + } + if ($root === '') { + break; + } + $parts = explode('/', $root); + array_pop($parts); + $root = implode('/', $parts); +} + +if (!$found_autoloader) { + fprintf(STDERR, "Failed to find autoloader.\n"); + exit(1); +} exit(\HH\Asio\join((new LinterCLI(vec($argv)))->mainAsync()));