I have a program which needs to be built for multiple platforms. Right now I'm doing something like:
matrix:
include:
env: PLATFORM=foo
env: PLATFORM=bar
env: PLATFORM=baz
before_install:
- install foo toolchain
- install bar toolchain
- install baz toolchain
script:
- make PLATFORM=$PLATFORM
I'd rather not install all three toolchains given that I'm only going to be using one; it's wasteful of resources and also breaks all the builds when upstream's terrible toolchain distribution site goes down.
However, I can't figure out a way to get a before_install in the build matrix --- the documentation is desperately unclear as to the precise syntax. Is this possible, and if so, how?
A build matrix is made up by several multiple jobs that run in parallel. This can be useful in many cases, but the two primary reasons to use a build matrix are: Reducing the overall build execution time. Running tests against different versions of runtimes or dependencies.
In this particular example, you could simply leverage the environment variable you've already created to dynamically expand the install command.
matrix:
include:
env: PLATFORM=foo
env: PLATFORM=bar
env: PLATFORM=baz
before_install:
- install $PLATFORM toolchain
script:
- make PLATFORM=$PLATFORM
For others that may find this question searching for a more complicated scenario, such as supporting ancient platforms inconsistent with modern travis environments, I manage matrix differential installs with dedicated scripts.
.
├── src
│ └── Foo.php
├── tests
│ ├── FooTest.php
│ └── travis
│ ├── install.bash
│ ├── install.legacy.bash
│ ├── script.bash
│ └── script.legacy.bash
└── .travis.yml
Then source the respective scripts for the environment.
language: php
matrix:
include:
- php: "nightly"
env: LEGACY=false
- php: "7.0"
env: LEGACY=false
- php: "5.3.3"
env: LEGACY=true
install:
- if $LEGACY; then source ./tests/travis/install.legacy.bash;
else source ./tests/travis/install.bash; fi
script:
- if $LEGACY; then source ./tests/travis/script.legacy.bash;
else source ./tests/travis/script.bash; fi
Pretty ugly, so I hope travis provides an official solution sometime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With