Apply PIE to nghttpx
[platform/upstream/nghttp2.git] / third-party / mruby / tasks / gitlab.rake
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|
66       ['', 'MRB_INT16', 'MRB_INT64'].each do |int_conf|
67         ['', 'MRB_NAN_BOXING', 'MRB_WORD_BOXING'].each do |boxing_conf|
68           ['', 'MRB_UTF8_STRING'].each do |utf8_conf|
69             next if (float_conf == 'MRB_USE_FLOAT') && (boxing_conf == 'MRB_NAN_BOXING')
70             next if (int_conf == 'MRB_INT64') && (boxing_conf == 'MRB_NAN_BOXING')
71             next if (int_conf == 'MRB_INT16') && (boxing_conf == 'MRB_WORD_BOXING')
72             next if (int_conf == 'MRB_INT64') && (boxing_conf == 'MRB_WORD_BOXING') && mode_32
73             env = [float_conf, int_conf, boxing_conf, utf8_conf].map do |conf|
74               conf == '' ? nil : "-D#{conf}=1"
75             end.compact.join(' ')
76             bit = mode_32 ? '-m32 ' : ''
77             _info = ''
78             _info += mode_32 ? '32bit ' : '64bit '
79             _info += float_conf['USE'] ? 'float ' : ''
80             _info += int_conf['16'] ? 'int16 ' : ''
81             _info += int_conf['64'] ? 'int64 ' : ''
82             _info += boxing_conf['NAN'] ? 'nan ' : ''
83             _info += boxing_conf['word'] ? 'word ' : ''
84             _info += utf8_conf['UTF8'] ? 'utf8 ' : ''
85             _info = _info.gsub(/ +/, ' ').strip.tr(' ', '_')
86             configs << { '_info' => _info, 'CFLAGS' => "#{bit}#{env}", 'LDFLAGS' => bit.strip.to_s }
87           end
88         end
89       end
90     end
91   end
92   path = './.gitlab-ci.yml'
93   data = YAML.load_file(path)
94   data.keys.select do |key|
95     key.start_with? 'Test'
96   end.each do |key|
97     data.delete(key)
98   end
99   CI_COMPILERS.each do |compiler|
100     configs.each do |config|
101       name = "Test #{compiler} #{config['_info']}"
102       hash = {
103         'CC' => compiler,
104         'CXX' => compiler.gsub('gcc', 'g++').gsub('clang', 'clang++'),
105         'LD' => compiler
106       }
107       hash = hash.merge(config)
108       hash.delete('_info')
109       data[name] = {
110         'stage' => 'test',
111         'image' => ci_docker_tag(compiler),
112         'variables' => hash,
113         'script' => 'env; ./minirake --verbose all test'
114       }
115     end
116   end
117   File.open(path, 'w') { |f| YAML.dump(data, f) }
118 end