1# Copyright (c) 2013 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{
6  'variables': {
7    'pgd_basename': 'test_pgo',
8  },
9  'targets': [
10    # In the PGO (Profile-Guided Optimization) build flow, we need to build the
11    # target binary multiple times. To implement this flow with gyp, here we
12    # define multiple 'executable' targets, each of which represents one build
13    # particular build/profile stage. On tricky part to do this is that these
14    # 'executable' targets should share the code itself so that profile data
15    # can be reused among these 'executable' files. In other words, the only
16    # differences among below 'executable' targets are:
17    #   1) PGO (Profile-Guided Optimization) database, and
18    #   2) linker options.
19    # The following static library contains all the logic including entry point.
20    # Basically we don't need to rebuild this target once we enter profiling
21    # phase of PGO.
22    {
23      'target_name': 'test_pgo_main',
24      'type': 'static_library',
25      'msvs_settings': {
26        'VCCLCompilerTool': {
27          'WholeProgramOptimization': 'true',  # /GL
28        },
29        'VCLibrarianTool': {
30          'LinkTimeCodeGeneration': 'true',
31        },
32      },
33      'link_settings': {
34        'msvs_settings': {
35          'VCLinkerTool': {
36            'ProfileGuidedDatabase': '$(OutDir)\\<(pgd_basename).pgd',
37            'TargetMachine': '1',  # x86 - 32
38            'SubSystem': '1',      # /SUBSYSTEM:CONSOLE
39            # Tell ninja generator not to pass /ManifestFile:<filename> option
40            # to the linker, because it causes LNK1268 error in PGO biuld.
41            'GenerateManifest': 'false',
42            # We need to specify 'libcmt.lib' here so that the linker can pick
43            # up a valid entry point.
44            'AdditionalDependencies': [
45              'libcmt.lib',
46            ],
47          },
48        },
49      },
50      'sources': [
51        'inline_test.h',
52        'inline_test.cc',
53        'inline_test_main.cc',
54      ],
55    },
56    {
57      'target_name': 'test_pgo_instrument',
58      'type': 'executable',
59      'msvs_settings': {
60        'VCLinkerTool': {
61          'LinkTimeCodeGeneration': '2',
62        },
63      },
64      'dependencies': [
65        'test_pgo_main',
66      ],
67    },
68    {
69      'target_name': 'gen_profile_guided_database',
70      'type': 'none',
71      'msvs_cygwin_shell': 0,
72      'actions': [
73        {
74          'action_name': 'action_main',
75          'inputs': [],
76          'outputs': [
77            '$(OutDir)\\<(pgd_basename).pgd',
78          ],
79          'action': [
80            'python', 'update_pgd.py',
81            '--vcbindir', '$(VCInstallDir)bin',
82            '--exe', '$(OutDir)\\test_pgo_instrument.exe',
83            '--pgd', '$(OutDir)\\<(pgd_basename).pgd',
84          ],
85        },
86      ],
87      'dependencies': [
88        'test_pgo_instrument',
89      ],
90    },
91    {
92      'target_name': 'test_pgo_optimize',
93      'type': 'executable',
94      'msvs_settings': {
95        'VCLinkerTool': {
96          'LinkTimeCodeGeneration': '3',
97        },
98      },
99      'sources': [
100        '$(OutDir)\\<(pgd_basename).pgd',
101      ],
102      'dependencies': [
103        'test_pgo_main',
104        'gen_profile_guided_database',
105      ],
106    },
107    {
108      'target_name': 'test_pgo_update',
109      'type': 'executable',
110      'msvs_settings': {
111        'VCLinkerTool': {
112          'LinkTimeCodeGeneration': '4',
113        },
114      },
115      'sources': [
116        '$(OutDir)\\<(pgd_basename).pgd',
117      ],
118      'dependencies': [
119        'test_pgo_main',
120      ],
121    },
122    # A helper target to dump link.exe's command line options. We can use the
123    # output to determine if PGO (Profile-Guided Optimization) is available on
124    # the test environment.
125    {
126      'target_name': 'gen_linker_option',
127      'type': 'none',
128      'msvs_cygwin_shell': 0,
129      'actions': [
130        {
131          'action_name': 'action_main',
132          'inputs': [],
133          'outputs': [
134            '$(OutDir)\\linker_options.txt',
135          ],
136          'action': [
137            'cmd.exe', '/c link.exe > $(OutDir)\\linker_options.txt & exit 0',
138          ],
139        },
140      ],
141    },
142  ]
143}
144