Can I multiply options in matrix.include[] with the env option?

Viewed 367

Given a fairly heterogenous matrix that looks like this:

matrix:
  include:
  - os: linux
    compiler: gcc
    env: PLATFORM=android ARCH=arm64-v8a
  - os: linux
    compiler: gcc
    env: PLATFORM=linux ARCH=aarch64
  - os: osx
    compiler: clang
    env: PLATFORM=darwin ARCH=x86_64 TEST=unit
  - os: osx
    compiler: clang
    env: PLATFORM=ios ARCH=arm64

This would result in four builds. I'd like to multiply it by two with an additional environment variable TYPE=Debug/Release. What's the best way to achieve this effect? Consider that I've only shown four configurations but the real number of configurations is 15. I'm hoping I won't have to duplicate everything twice.

I've tried the following but it merely adds two more builds, it doesn't combine with the matrix:

env:
    matrix:
        - TYPE=Debug
        - TYE=Release

Same with this:

env:
    - TYPE=Debug
    - TYE=Release
2 Answers

I am afraid you cannot.

There is no matrix expansion that you might expect on the top level does not happen in matrix.include.

The env key forms just one axis of the build matrix, and it is not possible to use different env values to construct a build matrix.

The only way to achieve what you need is adding four more jobs:

matrix:
  include:
  - os: linux
    compiler: gcc
    env: PLATFORM=android ARCH=arm64-v8a TYPE=Debug
  - os: linux
    compiler: gcc
    env: PLATFORM=linux ARCH=aarch64 TYPE=Debug
  - os: osx
    compiler: clang
    env: PLATFORM=darwin ARCH=x86_64 TEST=unit TYPE=Debug
  - os: osx
    compiler: clang
    env: PLATFORM=ios ARCH=arm64 TYPE=Debug
  - os: linux
    compiler: gcc
    env: PLATFORM=android ARCH=arm64-v8a TYPE=Release
  - os: linux
    compiler: gcc
    env: PLATFORM=linux ARCH=aarch64 TYPE=Release
  - os: osx
    compiler: clang
    env: PLATFORM=darwin ARCH=x86_64 TEST=unit TYPE=Release
  - os: osx
    compiler: clang
    env: PLATFORM=ios ARCH=arm64 TYPE=Release

(Incidentally, where are you getting the number 15?)

I usually use a small python script with a (jinja) template included to generate my travis config.

#!/usr/bin/env python3

tpl = '''
script:
    - some_stuff.bash

matrix:
  include:
{%- for letter, number in vars %}
    - env: TESTS={{number}} CONFIG={{letter}}
{%- endfor %}

'''

import os
import jinja2
from itertools import product

tpl = jinja2.Template(tpl)
ymlfn = os.path.join(os.path.dirname(__file__), '.travis.yml')
with open(ymlfn, 'wt') as yml:
    yml.write(tpl.render(vars=product(['a', 'b'], range(5))))

extend example

Related