box-project / box

📦🚀 Fast, zero config application bundler with PHARs.
https://box-project.github.io/box
MIT License
1.1k stars 101 forks source link

Add windows compatibility #193

Open theofidry opened 6 years ago

theofidry commented 6 years ago

/cc @c33s

theofidry commented 6 years ago

To whoever is willing to help out with this issue as I can't get my hands on a Windows machine: running bin/phpunit and check out the failures would be the easiest way to find most of the issues IMO.

c33s commented 5 years ago

tried the current version 3.1.2

box --version
Fatal error: Uncaught Error: Call to undefined function _HumbugBox1ee257d4ea88\Symfony\Component\Console\Output\sapi_windows_vt100_support() in phar://C:/bin/box.phar/vendor/symfony/console/Output/StreamOutput.php:55
Stack trace:
#0 phar://C:/bin/box.phar/vendor/symfony/console/Output/StreamOutput.php(28): _HumbugBox1ee257d4ea88\Symfony\Component\Console\Output\StreamOutput->hasColorSupport()
#1 phar://C:/bin/box.phar/vendor/symfony/console/Output/ConsoleOutput.php(20): _HumbugBox1ee257d4ea88\Symfony\Component\Console\Output\StreamOutput->__construct(Resource id #159, 32, NULL, NULL)
#2 phar://C:/bin/box.phar/vendor/symfony/console/Application.php(89): _HumbugBox1ee257d4ea88\Symfony\Component\Console\Output\ConsoleOutput->__construct()
#3 phar://C:/bin/box.phar/bin/box(39): _HumbugBox1ee257d4ea88\Symfony\Component\Console\Application->run()
#4 C:\bin\box.phar(18): require('phar://C:/bin...')
#5 {main}
  thrown in phar://C:/bin/box.phar/vendor/symfony/console/Output/StreamOutput.php on line 55
c33s commented 5 years ago

what about using https://www.appveyor.com/

Free for open-source projects

https://www.appveyor.com/pricing/

example config: https://github.com/puli/cli/blob/master/appveyor.yml

theofidry commented 5 years ago

I'm all up for it, it's just the trouble of setting it up and doing the PR to fix the windows incompatibilities I'm not really willing to do. If a PR provides the fixes with a working AppVeyor config, I'll gladly accept it though

c33s commented 5 years ago

got it up und running on window. i compiled box with itself from master with .\bin\box.bat compile --no-parallel but i had to replace all sapi_windows_vt100_support() calls with \sapi_windows_vt100_support() looks like this is a symfony console error with php7.1 or can it be some of your replace code?

the wrong namespace is used on this function call Call to undefined function _HumbugBoxb3c5af21fff1\Composer\XdebugHandler\sapi_windows_vt100_support() this error is gone if i prefix all the sapi_windows_vt100_support() with \ then i was able to get a self compiled version of box and use it to compile my code.

theofidry commented 5 years ago

Woa nice! I'll check this sapi_windows_vt100_support issue ASAP

c33s commented 5 years ago

hmm, i think i was too fast. the build is created but the build file does not work :(

theofidry commented 5 years ago

This required some tweaking, but done in https://github.com/humbug/php-scoper/pull/269. Will do a release soonish

theofidry commented 5 years ago

Shipped in 3.1.3 :)

c33s commented 5 years ago

finally some time for testing. all in all it works quite well. i compiled https://gitlab.com/c33s-group/yaml-convert and got a working yaml-convert.phar

{
    "directories": ["vendor"],
    "main": "bin/yaml-convert",
    "output": "yaml-convert.phar",
    "compression": "GZ",
    "git-commit": "git_commit",
    "git-version": "git_version",
    "git-tag": "git_tag"
}

stumpled upon some problems:

  1. The filename, directory name, or volume label syntax is incorrect. #353

    λ php box.phar compile
    The filename, directory name, or volume label syntax is incorrect.

    wouldn't it be good to have a windows detection and simply add this flags --no-restart --no-parallel per default (--no-restart was enough for me on win7)?

  2. vendor/composer/installed.json #337 only a warning but still some kind annoying

    A composer.lock file has been found but its related file vendor/composer/installed.json could not. This could be due to either dependencies incorrectly installed or an incorrect Box configuration which is not including the installed.json file. This will not break the build but will likely result in a broken Composer classmap.

    the file exists in vendor/composer but is not added to the resulting phar file, maybe this is the problem. in my box.json i add the whole vendor dir. so it should be there. also tried "force-autodiscovery": true, with the same result.

  3. --debug -> Call to undefined function spl_object_id() as this function was shipped with php7.2 and i run php7.1 some kind of polyfill would be needed for this to work https://github.com/symfony/polyfill-php72

    Fatal error: Uncaught Error: Call to undefined function spl_object_id() in phar://M:/composer-yaml/box.phar/vendor/symfony/var-dumper/Cloner/VarCloner.php:141
    Stack trace:
    #0 phar://M:/composer-yaml/box.phar/vendor/symfony/var-dumper/Cloner/AbstractCloner.php(58): _HumbugBoxfc75abf4ec5a\Symfony\Component\VarDumper\Cloner\VarCloner->doClone(Object(_HumbugBoxfc75abf4ec5a\KevinGH\Box\Configuration))
    #1 phar://M:/composer-yaml/box.phar/src/Console/Command/Compile.php(179): _HumbugBoxfc75abf4ec5a\Symfony\Component\VarDumper\Cloner\AbstractCloner->cloneVar(Object(_HumbugBoxfc75abf4ec5a\KevinGH\Box\Configuration))
    #2 phar://M:/composer-yaml/box.phar/src/Console/Command/Compile.php(131): _HumbugBoxfc75abf4ec5a\KevinGH\Box\Console\Command\Compile->removeExistingArtifacts(Object(_HumbugBoxfc7 in phar://M:/composer-yaml/box.phar/vendor/symfony/var-dumper/Cloner/VarCloner.php on line 141
c33s commented 5 years ago

extra info about polyfill: https://github.com/symfony/polyfill#design

theofidry commented 5 years ago

wouldn't it be good to have a windows detection and simply add this flags --no-restart --no-parallel per default (--no-restart was enough for me on win7)?

Isn't the issue because of your machine setup rather than just because it's the windows platform?

  1. only a warning but still some kind annoying

That's a legit one though: make sure all deps are installed properly before running Box.

the file exists in vendor/composer but is not added to the resulting phar file, maybe this is the problem. in my box.json i add the whole vendor dir. so it should be there. also tried "force-autodiscovery": true, with the same result

The installed.json is important to detect the dependencies, it is however excluded (by default) in the final PHAR. You shouldn't need to include vendor. That's said it's mostly for optimization and removing the dev deps

  1. --debug -> Call to undefined function spl_object_id()

Arg indeed, although I would rather upgrade to 7.2.

c33s commented 5 years ago

Isn't the issue because of your machine setup rather than just because it's the windows platform? thought it hits all/more windows instances because of #353

That's a legit one though: make sure all deps are installed properly before running Box. i don't really understand, i installed everything fresh like this:

  • deleted vendor
  • composer update
  • box compile --no-restart (using the config from above)

this results in the warning A composer.lock file has been found but its related file vendor/composer/installed.json... can it be that the detection for this warning is some kind of buggy or is my config wrong? is it required to remove vendor?

Arg indeed, although I would rather upgrade to 7.2.

sadly it is not possible to upgrade everywhere. sometimes i have situations where people demand php 5.6. so as version 7.1 is still supported until dec 2019 integrating the awesome symfony polyfills would be my suggestion. so it simply work for people who can't update.

theofidry commented 5 years ago

An easy way to check that warning would be to do BOX_ALLOW_XDEBUG box compile --no-restart and put a breakpoint in Configuration::create() to see what's going on

c33s commented 5 years ago

An easy way to check that warning would be to do BOX_ALLOW_XDEBUG box compile --no-restart and put a breakpoint in Configuration::create() to see what's going on

currently no configured xdebug on the windows system :(

another catch:

Output cmder (same for bash.exe): ![2019-02-21 17_14_06-cmder](https://user-images.githubusercontent.com/649209/53184652-b7e8dc00-35fd-11e9-9822-1910313f68d5.png) cmd.exe: ``` Available commands: build Builds a new PHAR (deprecated, use "compile" instead) compile 🔨 Compiles an application into a PHAR diff 🕵 Displays the differences between all of the files in two PHARs docker 🐳 Generates a Dockerfile for the given PHAR help Displays help for a command info 🔍 Displays information about the PHAR extension or file list Lists commands process ⚡ Applies the registered compactors and replacement values on a f ile validate ⚙ Validates the configuration file verify 🔐️ Verifies the PHAR signature ```
theofidry commented 5 years ago

Windows doesn't like emojis?

c33s commented 5 years ago

Windows doesn't like emojis?

at least win7x64 without any special fonts installed.

c33s commented 5 years ago

another one:

cannot run box if files are in the root dir

Output ``` O:\ (master) λ box compile --no-restart running convert with box converting box.yaml to json running convert with box-dist both not existing ____ / __ )____ _ __ / __ / __ \| |/_/ / /_/ / /_/ /> < /_____/\____/_/|_| Box version 3.4.0@4eeb285 2018-12-13 09:51:10 UTC // Loading the configuration file "O:\box.json". [ERROR] The configuration file is invalid. In Assertion.php line 829: "files" must contain a list of existing files. Could not find "O:/O://composer.json". ```
c33s commented 5 years ago

now i tried to compile https://github.com/composer/satis no luck this time.

Output ``` λ box compile --no-restart running convert with box converting box.yaml to json running convert with box-dist both not existing ____ / __ )____ _ __ / __ / __ \| |/_/ / /_/ / /_/ /> < /_____/\____/_/|_| Box version 3.4.0@4eeb285 2018-12-13 09:51:10 UTC // Loading the configuration file "O:\satis\box.json". 🔨 Building the PHAR "O:/satis/satis.phar" ? Removing the existing PHAR "O:/satis/satis.phar" ? Registering compactors + KevinGH\Box\Compactor\Json + KevinGH\Box\Compactor\Php ? Adding main file: O:/satis/bin/satis ? Adding requirements checker ? Adding binary files > No file found ? Auto-discover files? No ? Adding files > 2613 file(s) ? Generating new stub - Using shebang line: #!/usr/bin/env php - Using banner: > Generated by Humbug Box 3.4.0@4eeb285. > > @link https://github.com/humbug/box ? Dumping the Composer autoloader ? Removing the Composer dump artefacts ? Compressing with the algorithm "GZ" > Warning: the extension "zlib" will now be required to execute the PHAR ? Setting file permissions to 0755 * Done. 💡 6 recommendations found: - The "main" setting can be omitted since is set to its default value - The "stub" setting can be omitted since is set to its default value - The compactor "Herrera\Box\Compactor\Json" has been deprecated, use "KevinGH\Box\Compactor\Json" instead. - The compactor "Herrera\Box\Compactor\Php" has been deprecated, use "KevinGH\Box\Compactor\Php" instead. - The "chmod" setting can be omitted since is set to its default value - The "algorithm" setting can be omitted since is set to its default value ⚠️ 1 warning found: - A composer.lock file has been found but its related file vendor/composer/installed.json could not. This could be due to either dependencies incorrectly installed or an incorrect Box configuration which is not including the installed.json file. This will not break the build but will likely result in a broken Composer classmap. // PHAR: 2643 files (1.92MB) // You can inspect the generated PHAR with the "info" command. // Memory usage: 26.73MB (peak: 28.60MB), time: 48.64s O:\satis (master) λ php satis.phar Fatal error: Class 'Symfony\Component\Console\Application' not found in phar://O:/satis/satis.phar/src/Console/Application.php on line 30 ```

resulting phar: satis.zip

c33s commented 5 years ago

the last reported error is not windows specific. i have the same error for the satis.phar created on the debian build server (gitlab).

PHP Fatal error:  Class 'Symfony\Component\Console\Application' not found in phar:///usr/local/bin/satis/src/Console                                                                               /Application.php on line 30

should i open a new ticket for this?

theofidry commented 5 years ago

Oh if it isn’t yes please

On Fri 1 Mar 2019 at 22:29, Julian notifications@github.com wrote:

the last reported error is not windows specific. i have the same error for the satis.phar created on the debian build server (gitlab).

PHP Fatal error: Class 'Symfony\Component\Console\Application' not found in phar:///usr/local/bin/satis/src/Console /Application.php on line 30

should i open a new ticket for this?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/humbug/box/issues/193#issuecomment-468818163, or mute the thread https://github.com/notifications/unsubscribe-auth/AE76gYOBmBA3xMtYu6N9mMySIe5-jM4Fks5vSZvJgaJpZM4Txj8h .

theofidry commented 5 years ago

--debug -> Call to undefined function spl_object_id()

Note that this was an issue from symfony/var-dumper which hopefully has now been solved (it seems to be shipping the polyfill as expected)

c33s commented 5 years ago

--debug -> Call to undefined function spl_object_id()

Note that this was an issue from symfony/var-dumper which hopefully has now been solved (it seems to be shipping the polyfill as expected)

still broken

λ box compile --debug
[debug] Checking BOX_ALLOW_XDEBUG
[debug] The xdebug extension is not loaded

    ____
   / __ )____  _  __
  / __  / __ \| |/_/
 / /_/ / /_/ />  <
/_____/\____/_/|_|

Box version 3.5.0@cfc7c11 2019-03-05 00:51:30 UTC

 // Loading the configuration file
 // "C:\satis\box.json".

🔨  Building the PHAR "C:/satis/satis.phar"

Fatal error: Uncaught Error: Call to undefined function spl_object_id() in phar://C:/bin/box.phar/vendor/symfony/var-dumper/Cloner/VarCloner.php:142
Stack trace:
#0 phar://C:/bin/box.phar/vendor/symfony/var-dumper/Cloner/AbstractCloner.php(58): _HumbugBox9257ad6c1a66\Symfony\Component\VarDumper\Cloner\VarCloner->doClone(Object(_HumbugBox9257ad6c1a66\KevinGH\Box\Configuration))
#1 phar://C:/bin/box.phar/src/Console/Command/Compile.php(179): _HumbugBox9257ad6c1a66\Symfony\Component\VarDumper\Cloner\AbstractCloner->cloneVar(Object(_HumbugBox9257ad6c1a66\KevinGH\Box\Configuration))
#2 phar://C:/bin/box.phar/src/Console/Command/Compile.php(131): _HumbugBox9257ad6c1a66\KevinGH\Box\Console\Command\Compile->removeExistingArtifacts(Object(_HumbugBox9257ad6c1a66\KevinGH\Box\Configuration), Object(_HumbugBox9257ad6c1a66\KevinGH\Box\Console\Logger\CompileLogger), true)
#3 phar://C:/bin/box.phar/vendor/symfony/console/Command/Command.php(127): _HumbugBox9257ad6c1a66\KevinGH\Box\Console\Command\Compil in phar://C:/bin/box.phar/vendor/symfony/var-dumper/Cloner/VarCloner.php on line 142
c33s commented 5 years ago

wouldn't it be better to create an issue for each problem/bug and add a "windows" label to it? this issue is getting bigger and bigger which makes it unclear.

of course you have the tasks in the description but this ticket is quite an epic

c33s commented 5 years ago

by the way why "Check the compatibility with emojis"? it looks like that it is not compatible. simply remove them or add don't show them on windows or add a flag & an environment variable for it.

theofidry commented 5 years ago

appveyor

Added to the top description of this issue.

The filename, directory name, or volume label syntax is incorrect. #353

I'm not sure there is a specific issue there to be honest. I suspect making sure all tests works on Windows would actually solve the problem. If anything though, there was a feature request about including dot files (cf. this comment) but so far no one has been willing to work on it.

vendor/composer/installed.json #337

It is actually not windows specific. Opened https://github.com/humbug/box/issues/368 for it.

--debug -> Call to undefined function spl_object_id()

Actually not windows specific, opened https://github.com/humbug/box/issues/367 for it. It's actually a scoping issue.

emojis

Included in the top list of the issue. "Check the compatibility with emojis" is voluntary vague: if there is possible support it's about checking how feasible it is, otherwise it's about removing them on Windows.

cannot run box if files are in the root dir

What is that?

c33s commented 5 years ago

cannot run box if files are in the root dir

What is that?

https://github.com/humbug/box/issues/193#issuecomment-466803477

theofidry commented 5 years ago

Can you open a new issue for that one with the details about what exists in the root? (e.g. in the current output it complains about /composer.json not being found)

c33s commented 5 years ago

tried to compile a symfony project with box 3.7.0

#!/usr/bin/env php

Fatal error: Uncaught Symfony\Component\Config\Exception\FileLocatorFileNotFoundException: The file "./config" does not exist (in: ). in phar://<redacted>/puppet-enc/build/puppet-enc.phar/vendor/symfony/config/FileLocator.php:71
Stack trace:
#0 phar://<redacted>/puppet-enc/build/puppet-enc.phar/vendor/symfony/http-kernel/Config/FileLocator.php(52): Symfony\Component\Config\FileLocator->locate('./config', NULL, true)
#1 phar://<redacted>/puppet-enc/build/puppet-enc.phar/vendor/symfony/config/Loader/FileLoader.php(110): Symfony\Component\HttpKernel\Config\FileLocator->locate('./config', NULL, true)
#2 phar://<redacted>/puppet-enc/build/puppet-enc.phar/vendor/symfony/dependency-injection/Loader/GlobFileLoader.php(26): Symfony\Component\Config\Loader\FileLoader->glob('/{packages}/*.{...', false, NULL)
#3 phar://<redacted>/pu in phar://<redacted>/puppet-enc/build/puppet-enc.phar/vendor/symfony/config/FileLocator.php on line 71

box.yaml

files:
    - composer.json
directories:
    - bin
    - config
    - src
    - lib
finder:
    -
      name: '*.*'
      in: vendor
      exclude:
        - .gitignore
        - .md
        - phpunit
        - Tester
        - Tests
        - tests
compactors:
    - Herrera\Box\Compactor\Json
    - Herrera\Box\Compactor\Php
compression: GZ
main: bin/puppet-enc
output: build/puppet-enc.phar
stub: true
git-commit: git_commit
git-version: git_version
git-tag: git_tag
chmod: '0755'
theofidry commented 5 years ago

Can you double check the Symfony related doc to make sure there Compiler is properly compiled while building the PHAR?

You also need to ensure the environment is prod and debug disabled at all times within the PHAR (it needs to be seen as a prod ready and prod only app).

On Thu 25 Apr 2019 at 21:17, Julian notifications@github.com wrote:

tried to compile a symfony project with box 3.7.0

!/usr/bin/env php

Fatal error: Uncaught Symfony\Component\Config\Exception\FileLocatorFileNotFoundException: The file "./config" does not exist (in: ). in phar:///puppet-enc/build/puppet-enc.phar/vendor/symfony/config/FileLocator.php:71 Stack trace:

0 phar:///puppet-enc/build/puppet-enc.phar/vendor/symfony/http-kernel/Config/FileLocator.php(52): Symfony\Component\Config\FileLocator->locate('./config', NULL, true)

1 phar:///puppet-enc/build/puppet-enc.phar/vendor/symfony/config/Loader/FileLoader.php(110): Symfony\Component\HttpKernel\Config\FileLocator->locate('./config', NULL, true)

2 phar:///puppet-enc/build/puppet-enc.phar/vendor/symfony/dependency-injection/Loader/GlobFileLoader.php(26): Symfony\Component\Config\Loader\FileLoader->glob('/{packages}/*.{...', false, NULL)

3 phar:///pu in phar:///puppet-enc/build/puppet-enc.phar/vendor/symfony/config/FileLocator.php on line 71

box.yaml

files:

  • composer.json directories:
  • bin
  • config
  • src
  • lib finder:
  • name: '.' in: vendor exclude:

    • .gitignore
    • .md
    • phpunit
    • Tester
    • Tests
    • tests compactors:
  • Herrera\Box\Compactor\Json
  • Herrera\Box\Compactor\Php compression: GZ main: bin/puppet-enc output: build/puppet-enc.phar stub: true git-commit: git_commit git-version: git_version git-tag: git_tag chmod: '0755'

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/humbug/box/issues/193#issuecomment-486648271, or mute the thread https://github.com/notifications/unsubscribe-auth/ABHPVAPJDF6ZJYQFKDJNY2TPSGOPBANCNFSM4E6GH4QQ .