| 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 compile(self, target, **kwargs): |   9   def supported(self): | 
 |  10     extra_config = self.m.vars.builder_cfg.get('extra_config', '') | 
 |  11  | 
 |  12     return any([ | 
 |  13       extra_config == 'GN', | 
 |  14       extra_config == 'Fast', | 
 |  15       extra_config.startswith('SK') | 
 |  16     ]) | 
 |  17  | 
 |  18   def compile(self, unused_target, **kwargs): | 
|  10     """Build Skia with GN.""" |  19     """Build Skia with GN.""" | 
|  11     # Get the gn executable. |  20     compiler      = self.m.vars.builder_cfg.get('compiler',      '') | 
|  12     fetch_gn = self.m.vars.skia_dir.join('bin', 'fetch-gn') |  21     configuration = self.m.vars.builder_cfg.get('configuration', '') | 
|  13     self.m.run(self.m.step, 'fetch-gn', |  22     extra_config  = self.m.vars.builder_cfg.get('extra_config',  '') | 
|  14                cmd=[fetch_gn], |  | 
|  15                cwd=self.m.vars.skia_dir, |  | 
|  16                **kwargs) |  | 
|  17  |  23  | 
|  18     is_debug = 'is_debug=true' |  24     gn_args = [] | 
|  19     if self.m.vars.configuration != 'Debug': |  25     if configuration != 'Debug': | 
|  20       is_debug = 'is_debug=false' |  26       gn_args.append('is_debug=false') | 
|  21     gn_args = [is_debug] |  | 
|  22  |  | 
|  23     is_clang = 'Clang' in self.m.vars.builder_name |  | 
|  24     is_gcc   = 'GCC'   in self.m.vars.builder_name |  | 
|  25  |  27  | 
|  26     cc, cxx = 'cc', 'c++' |  28     cc, cxx = 'cc', 'c++' | 
|  27     if is_clang: |  29     cflags = [] | 
 |  30  | 
 |  31     if compiler == 'Clang': | 
|  28       cc, cxx = 'clang', 'clang++' |  32       cc, cxx = 'clang', 'clang++' | 
|  29     elif is_gcc: |  33     elif compiler == 'GCC': | 
|  30       cc, cxx = 'gcc', 'g++' |  34       cc, cxx = 'gcc', 'g++' | 
|  31  |  35  | 
|  32     ccache = self.m.run.ccache() |  36     ccache = self.m.run.ccache() | 
|  33     if ccache: |  37     if ccache: | 
|  34       cc, cxx = '%s %s' % (ccache, cc), '%s %s' % (ccache, cxx) |  38       cc, cxx = '%s %s' % (ccache, cc), '%s %s' % (ccache, cxx) | 
|  35       if is_clang: |  39       if compiler == 'Clang': | 
|  36         # Stifle "argument unused during compilation: ..." warnings. |  40         # Stifle "argument unused during compilation: ..." warnings. | 
|  37         stifle = '-Qunused-arguments' |  41         cflags.append('-Qunused-arguments') | 
|  38         cc, cxx = '%s %s' % (cc, stifle), '%s %s' % (cxx, stifle) |  | 
|  39  |  42  | 
|  40     gn_args += [ 'cc="%s"' % cc, 'cxx="%s"' % cxx ] |  43     if extra_config == 'Fast': | 
 |  44       cflags.extend(['-march=native', '-fomit-frame-pointer']) | 
 |  45     if extra_config.startswith('SK'): | 
 |  46       cflags.append('-D' + extra_config) | 
|  41  |  47  | 
|  42     # Run gn gen. |  48     cflags = ' '.join(cflags) | 
|  43     gn_exe = 'gn' |  49     gn_args += [ 'cc="%s %s"' % (cc, cflags), 'cxx="%s %s"' % (cxx, cflags) ] | 
|  44     if self.m.platform.is_win: |  | 
|  45       gn_exe = 'gn.exe' |  | 
|  46     gn_gen = [gn_exe, 'gen', self.out_dir, '--args=%s' % ' '.join(gn_args)] |  | 
|  47     self.m.run(self.m.step, 'gn_gen', cmd=gn_gen, |  | 
|  48                cwd=self.m.vars.skia_dir, **kwargs) |  | 
|  49  |  50  | 
|  50     # Run ninja. |  51     run = lambda title, cmd: self.m.run(self.m.step, title, cmd=cmd, | 
|  51     ninja_cmd = ['ninja', '-C', self.out_dir] |  52                                         cwd=self.m.vars.skia_dir, **kwargs) | 
|  52     self.m.run(self.m.step, 'compile %s' % target, |  53  | 
|  53                cmd=ninja_cmd, |  54     run('fetch-gn', [self.m.vars.skia_dir.join('bin', 'fetch-gn')]) | 
|  54                cwd=self.m.vars.skia_dir, |  55     run('gn gen', ['gn', 'gen', self.out_dir, '--args=%s' % ' '.join(gn_args)]) | 
|  55                **kwargs) |  56     run('ninja', ['ninja', '-C', self.out_dir]) | 
| OLD | NEW |