Git Product home page Git Product logo

hhvm-autoload's People

Contributors

alexeyt avatar aloiret avatar atry avatar azjezz avatar fredemmott avatar grahamcampbell avatar groovycarrot avatar hrmsimon avatar jesseschalken avatar jjergus avatar karoun avatar kmeht avatar lexidor avatar simonwelsh avatar ssandler avatar tj09 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hhvm-autoload's Issues

Make compatible with composer 2.0

- hhvm/hhvm-autoload[v2.0.4, ..., v2.0.13, v3.0.0, ..., v3.1.4] require composer-plugin-api ^1.0 -> found composer-plugin-api[2.0.0] but it does not match the constraint.

PSR filters don't like paths without an ending /

PSR0Filter and PSR4Filter have issues when a psr autoload declaration doesn't end with a / (e.g. php-resque's)

My fix for this is to add:

    $this->root = rtrim($this->root, '/').'/';

to the BasePSRFilter constructor.

Support providing a custom root

We tend to run composer from outside of our VMs, while run HHVM from inside. This means that the paths don't match so the autoloader can't find any of the files.

Being able to specific the root would solve this.

Do horrible undocumented things to support larger autoload maps

diff --git a/src/Writer.hack b/src/Writer.hack
index 06244e2..1c2a41a 100644
--- a/src/Writer.hack
+++ b/src/Writer.hack
@@ -178,9 +178,7 @@ final class Writer {
       true,
     );

-    $map = \var_export($map, true)
-      |> \str_replace('array (', 'darray[', $$)
-      |> \str_replace(')', ']', $$);
+    $map = \serialize($map);

     if ($this->relativeAutoloadRoot) {
       try {
@@ -212,7 +210,13 @@ function is_dev(): bool {

 function map(): \Facebook\AutoloadMap\AutoloadMap {
   /* HH_IGNORE_ERROR[4110] invalid return type */
-  return $map;
+  /* HH_IGNORE_ERROR[2049] undefined magic intrinsic */
+  /* HH_IGNORE_ERROR[4107] undefined magic intrinsic */
+  return __hhas_adata(
+    <<<'HHAS_ADATA'
+$map
+HHAS_ADATA
+  );
 }

 } // Generated\

Support providing a custom root

Our project stores PHP dependencies in vendor/composer (since we share vendor/ between JavaScript and PHP). Better handling for custom roots was introduced because of #10, but doubly-nested vendor directories still aren't supported because the root is assumed to be the parent directory of vendor-dir:

$vendor = $composer->getConfig()->get('vendor-dir', '/');
$this->vendor = $vendor;
$this->root = dirname($vendor);

Should a config key be introduced to fix this, or would re-purposing relativeAutoloadRoot be sufficient?

extraFiles not using relative path

Related to #10, I missed extraFiles. Relative paths have the current root prepended.

This is also an issue if setting autoloadFilesBehavior to 'exec'.

Getting error on trivial project after setup

I'm getting the following with a simple almost empty file after installing autoload via composer:

File

namespace mine;

function main(): void {
}

Command:

vendor/bin/hh-autoload

Output:


Fatal error: Uncaught exception 'HH\InvariantException' with message 'FactParse typesshould be an array<shape('name' => string)>' in /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/src/TypeAssert.hack:80
Stack trace:
#0 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/src/TypeAssert.hack(80): HH\invariant_violation()
#1 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/src/builders/FactParseScanner.hack(37): Facebook\AutoloadMap\__Private\TypeAssert\is_array_of_shapes_with_name_field()
#2 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/src/builders/FactParseScanner.hack(116): Facebook\AutoloadMap\FactParseScanner::untypedToShape()
#3 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/src/builders/HHImporter.hack(83): Facebook\AutoloadMap\FactParseScanner->getAutoloadMap()
#4 (): Closure$Facebook\AutoloadMap\HHImporter::getAutoloadMap()
#5 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/src/builders/HHImporter.hack(83): HH\Vector->map()
#6 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/src/builders/RootImporter.hack(53): Facebook\AutoloadMap\HHImporter->getAutoloadMap()
#7 (): Closure$Facebook\AutoloadMap\RootImporter::getAutoloadMap()
#8 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/src/builders/RootImporter.hack(53): HH\Vector->map()
#9 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/src/Writer.hack(65): Facebook\AutoloadMap\RootImporter->getAutoloadMap()
#10 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/bin/hh-autoload.hack(141): Facebook\AutoloadMap\Writer->setBuilder()
#11 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/bin/hh-autoload.hack(91): Facebook\AutoloadMap\GenerateScript::generateAutoloader()
#12 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/bin/hh-autoload.hack(184): Facebook\AutoloadMap\GenerateScript::main()
#13 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/bin/hh-autoload(19): Facebook\AutoloadMap\cli_main()
#14 (): Facebook\AutoloadMap\cli_main_UNSAFE()
#15 {main}

Next exception 'Exception' with message 'Failed to parse '/Users/xixixao/hack-hello/./vendor/composer/ClassLoader.php"' in /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/src/builders/FactParseScanner.hack:58
Stack trace:
#0 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/src/builders/FactParseScanner.hack(116): Facebook\AutoloadMap\FactParseScanner::untypedToShape()
#1 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/src/builders/HHImporter.hack(83): Facebook\AutoloadMap\FactParseScanner->getAutoloadMap()
#2 (): Closure$Facebook\AutoloadMap\HHImporter::getAutoloadMap()
#3 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/src/builders/HHImporter.hack(83): HH\Vector->map()
#4 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/src/builders/RootImporter.hack(53): Facebook\AutoloadMap\HHImporter->getAutoloadMap()
#5 (): Closure$Facebook\AutoloadMap\RootImporter::getAutoloadMap()
#6 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/src/builders/RootImporter.hack(53): HH\Vector->map()
#7 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/src/Writer.hack(65): Facebook\AutoloadMap\RootImporter->getAutoloadMap()
#8 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/bin/hh-autoload.hack(141): Facebook\AutoloadMap\Writer->setBuilder()
#9 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/bin/hh-autoload.hack(91): Facebook\AutoloadMap\GenerateScript::generateAutoloader()
#10 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/bin/hh-autoload.hack(184): Facebook\AutoloadMap\GenerateScript::main()
#11 /Users/xixixao/hack-hello/vendor/hhvm/hhvm-autoload/bin/hh-autoload(19): Facebook\AutoloadMap\cli_main()
#12 (): Facebook\AutoloadMap\cli_main_UNSAFE()
#13 {main}

error Uncaught exception 'OutOfBoundsException' with message 'Lval on missing array element'

cli /vendor/bin/hh-autoload.hack,
getting errors

Fatal error: Uncaught exception 'OutOfBoundsException' with message 'Lval on missing array element' in /path/to/project/vendor/hhvm/hhvm-autoload/src/builders/ComposerImporter.hack:152
Stack trace:
#0 /path/to/project/vendor/hhvm/hhvm-autoload/src/builders/ComposerImporter.hack(101): Facebook\AutoloadMap\ComposerImporter::normalizePSRRoots()
#1 /path/to/project/vendor/hhvm/hhvm-autoload/src/builders/ComposerImporter.hack(41): Facebook\AutoloadMap\ComposerImporter->importPSR4()
#2 /path/to/project/vendor/hhvm/hhvm-autoload/src/builders/RootImporter.hack(45): Facebook\AutoloadMap\ComposerImporter->__construct()
#3 /path/to/project/vendor/hhvm/hhvm-autoload/bin/hh-autoload.hack(134): Facebook\AutoloadMap\RootImporter->__construct()
#4 /path/to/project/vendor/hhvm/hhvm-autoload/bin/hh-autoload.hack(91): Facebook\AutoloadMap\GenerateScript::generateAutoloader()
#5 /path/to/project/vendor/hhvm/hhvm-autoload/bin/hh-autoload.hack(184): Facebook\AutoloadMap\GenerateScript::main()
#6 (): Facebook\AutoloadMap\cli_main()
#7 {main}

HHVM version

HipHop VM 4.43.0 (rel)
Compiler: 1580770874_N
Repo schema: da39a3ee5e6b4b0d3255bfef95601890afd80709

OS
MacOS, Ubuntu18.04.2(
container (hhvm/hhvm)

Absolute path leads to errors in certain environments

Hi

Since 2e8b1ec, vendor/hh_autoload.hh contains a require_once containing an absolute path which leads to <...>/vendor/hhvm/hhvm-autoload/src/AutoloadMap.php

This is causing errors in certain environment, e.g. using external volumes in docker containers, shipping prepared code to other machines...

@fredemmott mentioned

It probably shouldn’t be an absolute path

If so, I'd be happy to provide a quick PR...

Userland autoloading is going away

See: facebook/hhvm@d419828

NF FTW (Native Facts For The Win).

It might be nice to keep this project around for the pseudo-reflection "where's this symbol defined" api. If this is the direction the Meta team wants to pursue, the following steps would have to be taken.

  • Release a new version of hhvm-autoload with a minimum hhvm version where autoload_set_paths() stopped working.
  • Make initialize() a noop.

The hack Oss world should update their bin/ scripts to stop looking for the autoloader.

Support running with zero-configuration

We expect this project to be replaced by a future zero-configuration built-in autoloader; to prepare for that, we should work on making this work with zero configuration to uncover any issues that will need to be addressed by the future built-in one.

Port to hhvm/actions

This currently has a custom github action that predates hhvm/actions; this means things need fixing twice.

Class undefined error whenever a class is a child of an abstract class

I have setup hhvm-autoload in my project.

I have an index.php file to route web requests to the right controller. index.php does require_once(__DIR__.'/vendor/hh_autoload.php');

I have two controller classes: Foo and Bar.

Foo does not extend any other class and has a single static method bar() which returns a string.

Bar extends BaseController and overrides some methods. BaseController is defined as abstract.

index.php can call Foo:bar() with no issue, however when hhvm hits the line with the Bar class, it throws a Class Undefined error.

I checked and Bar is properly listed in the generated hh_autoload.php file.

Neither Foo, Bar or BaseController are in a namespace. The project also includes XHP and a few other libs via composer.

Any idea what could be causing this?

If I comment out the extends BaseController statement from the Bar definition, it loads the class properly and runs it fine.

HHVM data:
HipHop VM 3.18.3 (rel)
Compiler: tags/HHVM-3.18.3-0-g1ddd4af7b1342c20635afbdc67701fbcbdf97bfa
Repo schema: 61b13efcfd4e2fabea72495f96208746a568a688

I should also add that hh_client returns no errors.

Provide a way to specify a failure callback

Approaches include:

  • allowing a classname in the json file
  • providing an API to override it (problem here is that potentially makes hhvm-autoload a run-time dependency, not just dev)

Callbacks may want to:

  • have differing behavior in dev and prod (which is application-defined, and hhvm-autoload itself probably shouldn't be aware of)
  • automatically rebuild
  • follow PSR-4 or similar to autoload based on convention
  • log an error in a custom way
  • use hh_client --json --search-TYPE_GOES_HERE to automatically find it

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.