|
| 1 | +# Contributing |
| 2 | + |
| 3 | +This guide is meant to help you start contributing to the Symfony CLI by |
| 4 | +providing some key hints and explaining specifics related to this project. |
| 5 | + |
| 6 | +## Language choice |
| 7 | + |
| 8 | +First-time contributors could be surprised by the fact that this project is |
| 9 | +written in Go whereas it is highly related to the Symfony Framework which is |
| 10 | +written in PHP. |
| 11 | + |
| 12 | +Go has been picked because it is well suited for system development and has |
| 13 | +close-to-zero runtime dependencies which make releasing quite easy. This is |
| 14 | +ideal for a tool that is used on a wide range of platforms and potentially on |
| 15 | +systems where the requirements to run Symfony are not met. Go is also usually |
| 16 | +quite easy to apprehend for PHP developers having some similarities in their |
| 17 | +approach. |
| 18 | + |
| 19 | +## Setup Go |
| 20 | + |
| 21 | +Contributing to the CLI, implies that one must first setup Go locally on their |
| 22 | +machine. Instructions are available on the official |
| 23 | +[Go website](https://golang.org/dl). Just pick the latest version available: Go |
| 24 | +will automatically download the version currently in use in the project and |
| 25 | +dependencies as required. |
| 26 | + |
| 27 | +## Local setup |
| 28 | + |
| 29 | +First fork this repository and clone it in some location of your liking. Next, |
| 30 | +try to build and run the project: |
| 31 | + |
| 32 | +```bash |
| 33 | +$ go build . |
| 34 | +``` |
| 35 | + |
| 36 | +If any error happen you must fix them before going on. If no error happen, this |
| 37 | +should produce a binary in the project directory. By default, this binary is |
| 38 | +named `symfony-cli` and suffixed with `.exe` on Windows. |
| 39 | + |
| 40 | +You should be able to run it right away: |
| 41 | + |
| 42 | +```bash |
| 43 | +$ ./symfony-cli version |
| 44 | +``` |
| 45 | + |
| 46 | +The binary is self-contained: you can copy it as-is to another system and/or |
| 47 | +execute it without any installation process. |
| 48 | + |
| 49 | +> *Tip:* This binary can be executed from anywhere by using it's absolute path. |
| 50 | +> This is handy during development when you need to run it in a project |
| 51 | +> directory and you don't want to overwrite your system-wide Symfony CLI. |
| 52 | +
|
| 53 | +Finally, before and after changing code you should ensure tests are passing: |
| 54 | + |
| 55 | +```bash |
| 56 | +$ go test ./... |
| 57 | +``` |
| 58 | + |
| 59 | +## Coding style |
| 60 | + |
| 61 | +The CLI follows the Go standard code formatting. To fix the code formatting one |
| 62 | +can use the following command: |
| 63 | + |
| 64 | +```bash |
| 65 | +$ go fmt ./... |
| 66 | +``` |
| 67 | + |
| 68 | +One can also uses the `go vet` command in order to fix common mistakes: |
| 69 | + |
| 70 | +```bash |
| 71 | +$ go vet ./... |
| 72 | +``` |
| 73 | + |
| 74 | +## Cross compilation |
| 75 | + |
| 76 | +By definition, the CLI has to support multiple platforms which means that at |
| 77 | +some point you might need to compile the code for another platform than the one |
| 78 | +your are using to develop. |
| 79 | + |
| 80 | +This can be done using Go cross-platform compiling capabilities. For example |
| 81 | +the following command will compile the CLI for Windows: |
| 82 | + |
| 83 | +```bash |
| 84 | +$ GOOS=windows go build . |
| 85 | +``` |
| 86 | + |
| 87 | +`GOOS` and `GOARCH` environment variables are used to target another OS or CPU |
| 88 | +architecture, respectively. |
| 89 | + |
| 90 | +During development, please take into consideration (in particular in the |
| 91 | +process and file management sections) that we currently support the following |
| 92 | +platforms matrix: |
| 93 | + |
| 94 | +- Linux / 386 |
| 95 | +- Linux / amd64 |
| 96 | +- Linux / arm |
| 97 | +- Linux / arm64 |
| 98 | +- Darwin / amd64 |
| 99 | +- Darwin / arm64 |
| 100 | +- Windows / 386 |
| 101 | +- Windows / amd64 |
| 102 | + |
| 103 | +## Code generation |
| 104 | + |
| 105 | +Part of the code is generated automatically. One should not need to regenerate |
| 106 | +the code themselves because a GitHub Action is in-charge of it. In the |
| 107 | +eventuality one would need to debug it, code generation can be run as follows: |
| 108 | + |
| 109 | +```bash |
| 110 | +$ go generate ./... |
| 111 | +``` |
| 112 | + |
| 113 | +If you add a new code generation command, please also update the GitHub |
| 114 | +workflow in `.github/workflows/go_generate_update.yml`. |
| 115 | + |
| 116 | +## Additional repositories |
| 117 | + |
| 118 | +Contrary to the Symfony PHP Framework which is a mono-repository, the CLI |
| 119 | +tool is developed in multiple repositories. `symfony-cli/symfony-cli` is the |
| 120 | +main repository where lies most of the logic and is the only repository |
| 121 | +producing a binary. |
| 122 | + |
| 123 | +Every other repository is mostly independent and it is highly unlikely that |
| 124 | +you would need to have a look at them. However, in the eventuality where you |
| 125 | +would have to, here is the description of each repository scope: |
| 126 | +- `symfony-cli/phpstore` is a independent library in charge of the PHP |
| 127 | + installations discovery and the logic to match a specific version to a given |
| 128 | + version constraint. |
| 129 | +- `symfony-cli/console` is a independent library created to ease the process |
| 130 | + of Go command-line application. This library has been created with the goal |
| 131 | + of mimicking the look and feel of the Symfony Console for the end-user. |
| 132 | +- `symfony-cli/terminal` is a wrapper around the Input and Output in a command |
| 133 | + line context. It provides helpers around styling (output formatters and |
| 134 | + styling - à la Symfony) and interactivity (spinners and questions helpers) |
| 135 | +- `symfony-cli/dumper` is a library similar to Symfony's VarDumper component |
| 136 | + providing a `Dump` function useful to introspect variables content and |
| 137 | + particularly useful in the strictly typed context of Go. |
| 138 | + |
| 139 | +If you ever have to work on those package, you can setup your local working |
| 140 | +copy of the CLI to work with a local copy of one of those package by using |
| 141 | +`go work`: |
| 142 | + |
| 143 | +```bash |
| 144 | +$ go work init |
| 145 | +$ go work use . |
| 146 | +$ go work use /path/to/package/fork |
| 147 | +# repeat last command for each package you want to work with |
| 148 | +``` |
0 commit comments