11

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?

David Given
  • 13,277
  • 9
  • 76
  • 123

1 Answers1

2

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.

Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167