Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

composer itself is managed by composer?

Maybe just a stupid question. After I download/clone composer source code from github.com, how can I run it or compile it into a phar file?

When running "php bin/composer -v", it shows such errors:

php bin/composer -v
You must set up the project dependencies using `composer install`
See https://getcomposer.org/download/ for instructions on installing Composer

Is it said that I must download another composer.phar file and run "php composer.phar install" first?

I think it is a recursive way, "composer" itself is managed by composer :(

like image 751
bgwan Avatar asked May 03 '18 06:05

bgwan


2 Answers

At first: if someone wants just to use composer, they must not install it from GitHub, just follow the installation guide: https://getcomposer.org/download/

OK, back to the question.

"composer" itself is managed by composer

Yes, and why do you think it is bad?

See the official documentation for contributors. It encourages exactly that way:

  1. Run git clone https://github.com/composer/composer.git
  2. Download the composer.phar executable
  3. Run Composer to get the dependencies: cd composer && php ../composer.phar install

Then you can actually use composer by launching bin/composer, or you can compile it into phar by bin/compile.

If you wonder how are composer binaries actually built, you can see it in their Travis config. They just grab previous composer release provided by Travis, and build new composer release with it.

like image 57
Andrii Maletskyi Avatar answered Nov 08 '22 15:11

Andrii Maletskyi


Composer's job is to locate and install dependencies for a particular project. Everything it does could be done by hand, mostly simply by placing files in the right location, and referencing a series of autoloaders.

In order to build Composer from scratch, you need certain code that is outside of the main Composer repository, such as command-line and logging helpers. You could download all of these manually, but the natural way is to use an existing install of Composer to fetch them.

This is only necessary if you are working on Composer itself, because once you have a successful build, you can produce a PHAR file, which contains all the required code including those third-party dependencies. These are the files distributed as official releases, and are all most people need; the tool even has a self-update command which downloads a new PHAR file and overwrites the one you ran.

This kind of bootstrapping - using an existing build of a tool as part of its own build process - is actually quite common. There are some parts of PHP itself which are generated using a PHP script, and I believe the first feature-complete C++ compiler was written in C++.

like image 29
IMSoP Avatar answered Nov 08 '22 17:11

IMSoP