1# Copyright (c) 2011 Google Inc. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""gypsh output module
6
7gypsh is a GYP shell.  It's not really a generator per se.  All it does is
8fire up an interactive Python session with a few local variables set to the
9variables passed to the generator.  Like gypd, it's intended as a debugging
10aid, to facilitate the exploration of .gyp structures after being processed
11by the input module.
12
13The expected usage is "gyp -f gypsh -D OS=desired_os".
14"""
15
16
17import code
18import sys
19
20
21# All of this stuff about generator variables was lovingly ripped from gypd.py.
22# That module has a much better description of what's going on and why.
23_generator_identity_variables = [
24  'EXECUTABLE_PREFIX',
25  'EXECUTABLE_SUFFIX',
26  'INTERMEDIATE_DIR',
27  'PRODUCT_DIR',
28  'RULE_INPUT_ROOT',
29  'RULE_INPUT_DIRNAME',
30  'RULE_INPUT_EXT',
31  'RULE_INPUT_NAME',
32  'RULE_INPUT_PATH',
33  'SHARED_INTERMEDIATE_DIR',
34]
35
36generator_default_variables = {
37}
38
39for v in _generator_identity_variables:
40  generator_default_variables[v] = '<(%s)' % v
41
42
43def GenerateOutput(target_list, target_dicts, data, params):
44  locals = {
45        'target_list':  target_list,
46        'target_dicts': target_dicts,
47        'data':         data,
48      }
49
50  # Use a banner that looks like the stock Python one and like what
51  # code.interact uses by default, but tack on something to indicate what
52  # locals are available, and identify gypsh.
53  banner='Python %s on %s\nlocals.keys() = %s\ngypsh' % \
54         (sys.version, sys.platform, repr(sorted(locals.keys())))
55
56  code.interact(banner, local=locals)
57