Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Unified Diff: tools/cr/cr/actions/gn.py

Issue 1095613002: cr: Add support for GN build file generation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits addressed. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/cr/cr/actions/gyp.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/cr/cr/actions/gn.py
diff --git a/tools/cr/cr/actions/gn.py b/tools/cr/cr/actions/gn.py
new file mode 100644
index 0000000000000000000000000000000000000000..516537cecc152daac433fba67283f4b8fc97f849
--- /dev/null
+++ b/tools/cr/cr/actions/gn.py
@@ -0,0 +1,72 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""A module to add gn support to cr."""
+
+import cr
+import shlex
+import os
+
+GN_ARG_PREFIX = 'GN_ARG_'
+
+
+class GnPrepareOut(cr.PrepareOut):
+ """A prepare action that runs gn whenever you select an output directory."""
+
+ ACTIVE = cr.Config.From(
+ GN_ARG_is_component_build='true',
+ )
+
+ @property
+ def enabled(self):
+ # Disabled on Android for now.
+ return not cr.AndroidPlatform.GetInstance().is_active
+
+ def UpdateContext(self):
+ # Collapse GN_ARGS from all GN_ARG prefixes
+ gn_args = cr.context.Find('GN_ARGS') or ''
+ for key, value in cr.context.exported.items():
+ if key.startswith(GN_ARG_PREFIX):
+ gn_args += ' %s=%s' % (key[len(GN_ARG_PREFIX):], value)
+
+ gn_args += (' is_debug=%s' %
+ 'true' if cr.context['CR_BUILDTYPE'] == 'Debug' else 'false')
+
+ cr.context['GN_ARGS'] = gn_args.strip()
+ if cr.context.verbose >= 1:
+ print cr.context.Substitute('GN_ARGS = {GN_ARGS}')
+
+ def Prepare(self):
+ if cr.context.verbose >= 1:
+ print cr.context.Substitute('Invoking gn with {GN_ARGS}')
+
+ args_file = os.path.join(cr.context['CR_SRC'],
+ cr.context['CR_OUT_FULL'],
+ 'args.gn')
+ args = {}
+ for arg in shlex.split(cr.context['GN_ARGS']):
+ key, value = arg.split('=', 1)
+ args[key] = value
+
+ # Override any existing settings.
+ arg_lines = []
+ if os.path.exists(args_file):
+ with open(args_file) as f:
+ for line in f:
+ key = line.split('=', 1)[0].strip()
+ if key not in args:
+ arg_lines.append(line.strip())
+
+ # Append new settings.
+ for key, value in args.items():
+ arg_lines.append('%s = %s' % (key, value))
+
+ with open(args_file, 'w') as f:
+ f.write('\n'.join(arg_lines) + '\n')
+
+ cr.Host.Execute(
+ 'gn',
+ 'gen',
+ '{CR_OUT_FULL}',
+ )
« no previous file with comments | « no previous file | tools/cr/cr/actions/gyp.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698