[331] | 1 | CI_VERSION = '0.7'.freeze
|
---|
| 2 | CI_BASE = 'ubuntu:16.10'.freeze
|
---|
| 3 | CI_COMPILERS = ['gcc-4.7',
|
---|
| 4 | 'gcc-4.8',
|
---|
| 5 | 'gcc-4.9',
|
---|
| 6 | 'gcc-5',
|
---|
| 7 | 'gcc-6',
|
---|
| 8 | 'clang-3.5',
|
---|
| 9 | 'clang-3.6',
|
---|
| 10 | 'clang-3.7',
|
---|
| 11 | 'clang-3.8',
|
---|
| 12 | 'clang-3.9'].freeze
|
---|
| 13 |
|
---|
| 14 | def ci_image_tag(compiler)
|
---|
| 15 | compiler.tr('+', 'c').delete('-').delete('.')
|
---|
| 16 | end
|
---|
| 17 |
|
---|
| 18 | def ci_docker_tag(compiler)
|
---|
| 19 | tag = ci_image_tag(compiler)
|
---|
| 20 | "registry.gitlab.com/dabroz/mruby:#{tag}_#{CI_VERSION}"
|
---|
| 21 | end
|
---|
| 22 |
|
---|
| 23 | def run_cmd(cmd)
|
---|
| 24 | puts cmd
|
---|
| 25 | raise 'error' unless system cmd
|
---|
| 26 | end
|
---|
| 27 |
|
---|
| 28 | desc 'recreate docker images for GitLab builds'
|
---|
| 29 | task :gitlab_dockers do
|
---|
| 30 | CI_COMPILERS.each do |compiler|
|
---|
| 31 | tag = ci_image_tag(compiler)
|
---|
| 32 | filename = "Dockerfile.#{tag}"
|
---|
| 33 | File.open(filename, 'wb') do |f|
|
---|
| 34 | f << "# #{compiler} - #{tag}\n"
|
---|
| 35 | f << "FROM #{CI_BASE}\n"
|
---|
| 36 | f << "RUN apt-get update && apt-get install -y git ruby2.3 ruby2.3-dev bison\n"
|
---|
| 37 | f << "RUN apt-get update && apt-get install -y binutils manpages\n"
|
---|
| 38 | f << "RUN apt-get update && apt-get install -y #{compiler}\n"
|
---|
| 39 | if compiler['gcc']
|
---|
| 40 | f << "RUN apt-get update && apt-get install -y libx32#{compiler}-dev\n"
|
---|
| 41 | f << "RUN apt-get update && apt-get install --no-install-recommends -y #{compiler}-multilib\n"
|
---|
| 42 | end
|
---|
| 43 | f << "RUN dpkg --add-architecture i386\n"
|
---|
| 44 | f << "RUN apt-get update && apt-get install -y linux-libc-dev:i386\n"
|
---|
| 45 | if compiler['clang']
|
---|
| 46 | f << "RUN apt-get update && apt-get install --no-install-recommends -y libc6-dev-i386\n"
|
---|
| 47 | f << "RUN apt-get update && apt-get install -y gcc gcc-multilib\n"
|
---|
| 48 | end
|
---|
| 49 | end
|
---|
| 50 | docker_tag = ci_docker_tag(compiler)
|
---|
| 51 | cmd1 = "docker build -t #{docker_tag} -f #{filename} ."
|
---|
| 52 | cmd2 = "docker push #{docker_tag}"
|
---|
| 53 | run_cmd cmd1
|
---|
| 54 | run_cmd cmd2
|
---|
| 55 | File.delete(filename)
|
---|
| 56 | end
|
---|
| 57 | end
|
---|
| 58 |
|
---|
| 59 | desc 'create build configurations and update .gitlab-ci.yml'
|
---|
| 60 | task :gitlab_config do
|
---|
| 61 | require 'yaml'
|
---|
| 62 |
|
---|
| 63 | configs = []
|
---|
| 64 | [true, false].each do |mode_32|
|
---|
| 65 | ['', 'MRB_USE_FLOAT'].each do |float_conf|
|
---|
[439] | 66 | ['', 'MRB_NAN_BOXING', 'MRB_WORD_BOXING'].each do |boxing_conf|
|
---|
| 67 | ['', 'MRB_UTF8_STRING'].each do |utf8_conf|
|
---|
| 68 | next if (float_conf == 'MRB_USE_FLOAT') && (boxing_conf == 'MRB_NAN_BOXING')
|
---|
| 69 | next if (int_conf == 'MRB_INT64') && (boxing_conf == 'MRB_NAN_BOXING')
|
---|
| 70 | next if (int_conf == 'MRB_INT64') && (boxing_conf == 'MRB_WORD_BOXING') && mode_32
|
---|
| 71 | env = [float_conf, int_conf, boxing_conf, utf8_conf].map do |conf|
|
---|
| 72 | conf == '' ? nil : "-D#{conf}=1"
|
---|
| 73 | end.compact.join(' ')
|
---|
| 74 | bit = mode_32 ? '-m32 ' : ''
|
---|
| 75 | _info = ''
|
---|
| 76 | _info += mode_32 ? '32bit ' : '64bit '
|
---|
| 77 | _info += float_conf['USE'] ? 'float ' : ''
|
---|
| 78 | _info += int_conf['16'] ? 'int16 ' : ''
|
---|
| 79 | _info += int_conf['64'] ? 'int64 ' : ''
|
---|
| 80 | _info += boxing_conf['NAN'] ? 'nan ' : ''
|
---|
| 81 | _info += boxing_conf['WORD'] ? 'word ' : ''
|
---|
| 82 | _info += utf8_conf['UTF8'] ? 'utf8 ' : ''
|
---|
| 83 | _info = _info.gsub(/ +/, ' ').strip.tr(' ', '_')
|
---|
| 84 | configs << { '_info' => _info, 'CFLAGS' => "#{bit}#{env}", 'LDFLAGS' => bit.strip.to_s }
|
---|
[331] | 85 | end
|
---|
| 86 | end
|
---|
| 87 | end
|
---|
| 88 | end
|
---|
| 89 | path = './.gitlab-ci.yml'
|
---|
| 90 | data = YAML.load_file(path)
|
---|
| 91 | data.keys.select do |key|
|
---|
| 92 | key.start_with? 'Test'
|
---|
| 93 | end.each do |key|
|
---|
| 94 | data.delete(key)
|
---|
| 95 | end
|
---|
| 96 | CI_COMPILERS.each do |compiler|
|
---|
| 97 | configs.each do |config|
|
---|
| 98 | name = "Test #{compiler} #{config['_info']}"
|
---|
| 99 | hash = {
|
---|
| 100 | 'CC' => compiler,
|
---|
| 101 | 'CXX' => compiler.gsub('gcc', 'g++').gsub('clang', 'clang++'),
|
---|
| 102 | 'LD' => compiler
|
---|
| 103 | }
|
---|
| 104 | hash = hash.merge(config)
|
---|
| 105 | hash.delete('_info')
|
---|
| 106 | data[name] = {
|
---|
| 107 | 'stage' => 'test',
|
---|
| 108 | 'image' => ci_docker_tag(compiler),
|
---|
| 109 | 'variables' => hash,
|
---|
[439] | 110 | 'script' => 'env; rake --verbose all test'
|
---|
[331] | 111 | }
|
---|
| 112 | end
|
---|
| 113 | end
|
---|
| 114 | File.open(path, 'w') { |f| YAML.dump(data, f) }
|
---|
| 115 | end
|
---|