summaryrefslogtreecommitdiffstats
path: root/build/buildflag_header.gypi
blob: 83b505a4f3e6a3ed96fcb4436df40149f38fc630 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# 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.

# Generates a header with preprocessor defines specified by the build file.
#
# The canonical documentation is in build/buildflag_header.gni. You should
# write the GN build, get it working, and then transform it into GYP.
#
# In every target that uses your generated header you must include a dependency
# on the GYP target that generates the header (this is implicit in GN).
# Otherwise, clean builds may not necessarily create the header before the
# source code is compiled.
#
# Assuming your GN code looks like this:
#
#   buildflag_header("foo_features") {
#     header = "foo_features.h"
#     flags = [
#       "ENABLE_DOOM_MELON=$enable_doom_melon",
#       "ENABLE_SPACE_LASER=true",
#       "SPAM_SERVER_URL=\"http://www.example.com/\"",
#     ]
#   }
#
# Write a GYP target like this:
#
#  {
#    # GN version: //foo:foo_features
#    'target_name': 'foo_foo_features',
#    'includes': [ '../build/buildflag_header.gypi' ],
#    'variables': {
#       'buildflag_header_path': 'foo/foo_features.h',
#       'buildflag_flags': [
#         'ENABLE_DOOM_MELON=<(enable_doom_melon)',
#         'ENABLE_SPACE_LASER=true',
#         'SPAM_SERVER_URL="http://www.example.com/"',
#       ],
#     },
#   }
#
# Variables
#
#   target_name
#       Base this on the GN label, replacing / and : with _ to make it globally
#       unique.
#
#   buildflag_header_path
#       This must be the full path to the header from the source root. In GN
#       you only say "features.h" and it uses the BUILD file's path implicitly.
#       Use the path to BUILD.gn followed by your header name to produce the
#       same output file.
#
#   buildflag_flags (optional)
#       List of the same format as GN's "flags". To expand variables, use
#       "<(foo)" where GN would have used "$foo".
#
#   includes
#       List the relative path to build/buildflag_header.gypi from the .gyp
#       file including this code, Note: If your code is in a .gypi file in a
#       different directory, this must be relative to the .gyp including your
#       file.
#
#
# Grit defines
#
# Follow the same advice as in the buildflag_header.gni, except on the grit
# action use the variable name 'grit_additional_defines' and explicitly add a
# '-D' in front:
#
#   'grit_grd_file': 'foo.grd',
#   'grit_additional_defines': [
#     '-D', 'enable_doom_melon=<(enable_doom_melon)',
#    ],
#
# Put shared lists of defines in a .gypi.

{
  'type': 'none',
  'hard_dependency': 1,

  'actions': [
    {
      'action_name': 'buildflag_header',
      'variables': {
        # Default these values to empty if they're not defined.
        'variables': {
          'buildflag_flags%': [],
        },

        # Writes the flags to a response file with a name based on the name of
        # this target.
        'response_file_name': '<|(<(_target_name)_buildflag_header.rsp --flags <@(buildflag_flags))',

        'build_header_script': '<(DEPTH)/build/write_buildflag_header.py',
      },

      'message': 'Generating build header.',

      'inputs': [
        '<(build_header_script)',
        '<(response_file_name)',
      ],

      'outputs': [
        '<(SHARED_INTERMEDIATE_DIR)/<(buildflag_header_path)',
      ],

      'action': [
        'python', '<(build_header_script)',
        '--output', '<(buildflag_header_path)',
        '--rulename', '<(_target_name)',
        '--gen-dir', '<(SHARED_INTERMEDIATE_DIR)',
        '--definitions', '<(response_file_name)',
      ],
    }
  ],

  # Allow the file to be included based on the given buildflag_header_path.
  'direct_dependent_settings': {
    'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)' ],
  },
}