| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import default_flavor | 5 import default_flavor |
| 6 | 6 |
| 7 """GN flavor utils, used for building Skia with GN.""" | 7 """GN flavor utils, used for building Skia with GN.""" |
| 8 class GNFlavorUtils(default_flavor.DefaultFlavorUtils): | 8 class GNFlavorUtils(default_flavor.DefaultFlavorUtils): |
| 9 def supported(self): | 9 def supported(self): |
| 10 extra_config = self.m.vars.builder_cfg.get('extra_config', '') | 10 extra_config = self.m.vars.builder_cfg.get('extra_config', '') |
| 11 | 11 |
| 12 return any([ | 12 return any([ |
| 13 extra_config == 'GN', | 13 extra_config == 'GN', |
| 14 extra_config == 'Fast', | 14 extra_config == 'Fast', |
| 15 extra_config.startswith('SK') | 15 extra_config.startswith('SK') |
| 16 ]) | 16 ]) |
| 17 | 17 |
| 18 def compile(self, unused_target, **kwargs): | 18 def compile(self, unused_target, **kwargs): |
| 19 """Build Skia with GN.""" | 19 """Build Skia with GN.""" |
| 20 compiler = self.m.vars.builder_cfg.get('compiler', '') | 20 compiler = self.m.vars.builder_cfg.get('compiler', '') |
| 21 configuration = self.m.vars.builder_cfg.get('configuration', '') | 21 configuration = self.m.vars.builder_cfg.get('configuration', '') |
| 22 extra_config = self.m.vars.builder_cfg.get('extra_config', '') | 22 extra_config = self.m.vars.builder_cfg.get('extra_config', '') |
| 23 | 23 |
| 24 gn_args = [] | |
| 25 if configuration != 'Debug': | |
| 26 gn_args.append('is_debug=false') | |
| 27 | |
| 28 cc, cxx = 'cc', 'c++' | 24 cc, cxx = 'cc', 'c++' |
| 29 cflags = [] | 25 extra_cflags = [] |
| 30 | 26 |
| 31 if compiler == 'Clang': | 27 if compiler == 'Clang': |
| 32 cc, cxx = 'clang', 'clang++' | 28 cc, cxx = 'clang', 'clang++' |
| 33 elif compiler == 'GCC': | 29 elif compiler == 'GCC': |
| 34 cc, cxx = 'gcc', 'g++' | 30 cc, cxx = 'gcc', 'g++' |
| 35 | 31 |
| 36 ccache = self.m.run.ccache() | 32 ccache = self.m.run.ccache() |
| 37 if ccache: | 33 if ccache: |
| 38 cc, cxx = '%s %s' % (ccache, cc), '%s %s' % (ccache, cxx) | 34 cc, cxx = '%s %s' % (ccache, cc), '%s %s' % (ccache, cxx) |
| 39 if compiler == 'Clang': | 35 if compiler == 'Clang': |
| 40 # Stifle "argument unused during compilation: ..." warnings. | 36 # Stifle "argument unused during compilation: ..." warnings. |
| 41 cflags.append('-Qunused-arguments') | 37 extra_cflags.append('-Qunused-arguments') |
| 42 | 38 |
| 43 if extra_config == 'Fast': | 39 if extra_config == 'Fast': |
| 44 cflags.extend(['-march=native', '-fomit-frame-pointer']) | 40 extra_cflags.extend(['-march=native', '-fomit-frame-pointer', '-O3']) |
| 45 if extra_config.startswith('SK'): | 41 if extra_config.startswith('SK'): |
| 46 cflags.append('-D' + extra_config) | 42 extra_cflags.append('-D' + extra_config) |
| 47 | 43 |
| 48 cflags = ' '.join(cflags) | 44 quote = lambda x: '"%s"' % x |
| 49 gn_args += [ 'cc="%s %s"' % (cc, cflags), 'cxx="%s %s"' % (cxx, cflags) ] | 45 gn_args = ' '.join('%s=%s' % (k,v) for (k,v) in { |
| 46 'cc': quote(cc), |
| 47 'cxx': quote(cxx), |
| 48 'extra_cflags': quote(' '.join(extra_cflags)), |
| 49 'is_debug': 'true' if configuration == 'Debug' else 'false', |
| 50 }.iteritems()) |
| 50 | 51 |
| 51 run = lambda title, cmd: self.m.run(self.m.step, title, cmd=cmd, | 52 run = lambda title, cmd: self.m.run(self.m.step, title, cmd=cmd, |
| 52 cwd=self.m.vars.skia_dir, **kwargs) | 53 cwd=self.m.vars.skia_dir, **kwargs) |
| 53 | 54 |
| 54 run('fetch-gn', [self.m.vars.skia_dir.join('bin', 'fetch-gn')]) | 55 run('fetch-gn', [self.m.vars.skia_dir.join('bin', 'fetch-gn')]) |
| 55 run('gn gen', ['gn', 'gen', self.out_dir, '--args=%s' % ' '.join(gn_args)]) | 56 run('gn gen', ['gn', 'gen', self.out_dir, '--args=' + gn_args]) |
| 56 run('ninja', ['ninja', '-C', self.out_dir]) | 57 run('ninja', ['ninja', '-C', self.out_dir]) |
| OLD | NEW |