Home | History | Annotate | Download | only in gn
      1 // Copyright (c) 2013 The Chromium Authors. 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 #include "tools/gn/variables.h"
      6 
      7 namespace variables {
      8 
      9 // Built-in variables ----------------------------------------------------------
     10 
     11 const char kComponentMode[] = "component_mode";
     12 const char kComponentMode_HelpShort[] =
     13     "component_mode: [string] Specifies the meaning of the component() call.";
     14 const char kComponentMode_Help[] =
     15     "component_mode: Specifies the meaning of the component() call.\n"
     16     "\n"
     17     "  This value is looked up whenever a \"component\" target type is\n"
     18     "  encountered. The value controls whether the given target is a shared\n"
     19     "  or a static library.\n"
     20     "\n"
     21     "  The initial value will be empty, which will cause a call to\n"
     22     "  component() to throw an error. Typically this value will be set in the\n"
     23     "  build config script.\n"
     24     "\n"
     25     "Possible values:\n"
     26     "  - \"shared_library\"\n"
     27     "  - \"source_set\"\n"
     28     "  - \"static_library\"\n";
     29 
     30 const char kCpuArch[] = "cpu_arch";
     31 const char kCpuArch_HelpShort[] =
     32     "cpu_arch: [string] Current processor architecture.";
     33 const char kCpuArch_Help[] =
     34     "cpu_arch: Current processor architecture.\n"
     35     "\n"
     36     "  The initial value is based on the current architecture of the host\n"
     37     "  system. However, the build configuration can set this to any value.\n"
     38     "\n"
     39     "  This value is not used internally by GN for any purpose, so you can\n"
     40     "  set it to whatever value is relevant to your build.\n"
     41     "\n"
     42     "Possible initial values set by GN:\n"
     43     "  - \"x86\"\n"
     44     "  - \"x64\"\n"
     45     "  - \"arm\"\n"
     46     "  - \"mipsel\"\n";
     47 
     48 const char kCurrentToolchain[] = "current_toolchain";
     49 const char kCurrentToolchain_HelpShort[] =
     50     "current_toolchain: [string] Label of the current toolchain.";
     51 const char kCurrentToolchain_Help[] =
     52     "current_toolchain: Label of the current toolchain.\n"
     53     "\n"
     54     "  A fully-qualified label representing the current toolchain. You can\n"
     55     "  use this to make toolchain-related decisions in the build. See also\n"
     56     "  \"default_toolchain\".\n"
     57     "\n"
     58     "Example:\n"
     59     "\n"
     60     "  if (current_toolchain == \"//build:64_bit_toolchain\") {\n"
     61     "    executable(\"output_thats_64_bit_only\") {\n"
     62     "      ...\n";
     63 
     64 const char kBuildCpuArch[] = "build_cpu_arch";
     65 const char kBuildCpuArch_HelpShort[] =
     66     "build_cpu_arch: [string] The default value for the \"cpu_arch\" "
     67     "variable.";
     68 const char kBuildCpuArch_Help[] =
     69     "build_cpu_arch: The default value for the \"cpu_arch\" variable.\n"
     70     "\n"
     71     "  This value has the same definition as \"cpu_arch\" (see\n"
     72     "  \"gn help cpu_arch\") but should be treated as read-only. This is so\n"
     73     "  the build can override the \"cpu_arch\" variable for doing\n"
     74     "  cross-compiles, but can still access the host build system's CPU\n"
     75     "  architecture.\n";
     76 
     77 const char kBuildOs[] = "build_os";
     78 const char kBuildOs_HelpShort[] =
     79     "build_os: [string] The default value for the \"os\" variable.";
     80 const char kBuildOs_Help[] =
     81     "build_os: [string] The default value for the \"os\" variable.\n"
     82     "\n"
     83     "  This value has the same definition as \"os\" (see \"gn help os\") but\n"
     84     "  should be treated as read-only. This is so the build can override\n"
     85     "  the \"os\" variable for doing cross-compiles, but can still access\n"
     86     "  the host build system's operating system type.\n";
     87 
     88 const char kDefaultToolchain[] = "default_toolchain";
     89 const char kDefaultToolchain_HelpShort[] =
     90     "default_toolchain: [string] Label of the default toolchain.";
     91 const char kDefaultToolchain_Help[] =
     92     "default_toolchain: [string] Label of the default toolchain.\n"
     93     "\n"
     94     "  A fully-qualified label representing the default toolchain, which may\n"
     95     "  not necessarily be the current one (see \"current_toolchain\").\n";
     96 
     97 const char kOs[] = "os";
     98 const char kOs_HelpShort[] =
     99     "os: [string] Indicates the operating system of the current build.";
    100 const char kOs_Help[] =
    101     "os: Indicates the operating system of the current build."
    102     "\n"
    103     "  This value is set by default based on the current host operating\n"
    104     "  system. The build configuration can override the value to anything\n"
    105     "  it wants, or it can be set via the build arguments on the command\n"
    106     "  line.\n"
    107     "\n"
    108     "  If you want to know the default value without any overrides, you can\n"
    109     "  use \"default_os\" (see \"gn help default_os\").\n"
    110     "\n"
    111     "  Note that this returns the most specific value. So even though\n"
    112     "  Android and ChromeOS are both Linux, the more specific value will\n"
    113     "  be returned.\n"
    114     "\n"
    115     "Some possible values:\n"
    116     "  - \"amiga\"\n"
    117     "  - \"android\"\n"
    118     "  - \"chromeos\"\n"
    119     "  - \"ios\"\n"
    120     "  - \"linux\"\n"
    121     "  - \"mac\"\n"
    122     "  - \"win\"\n";
    123 
    124 const char kPythonPath[] = "python_path";
    125 const char kPythonPath_HelpShort[] =
    126     "python_path: [string] Absolute path of Python.";
    127 const char kPythonPath_Help[] =
    128     "python_path: Absolute path of Python.\n"
    129     "\n"
    130     "  Normally used in toolchain definitions if running some command\n"
    131     "  requires Python. You will normally not need this when invoking scripts\n"
    132     "  since GN automatically finds it for you.\n";
    133 
    134 const char kRootBuildDir[] = "root_build_dir";
    135 const char kRootBuildDir_HelpShort[] =
    136   "root_build_dir: [string] Directory where build commands are run.";
    137 const char kRootBuildDir_Help[] =
    138   "root_build_dir: [string] Directory where build commands are run.\n"
    139   "\n"
    140   "  This is the root build output directory which will be the current\n"
    141   "  directory when executing all compilers and scripts.\n"
    142   "\n"
    143   "  Most often this is used with rebase_path (see \"gn help rebase_path\")\n"
    144   "  to convert arguments to be relative to a script's current directory.\n";
    145 
    146 const char kRootGenDir[] = "root_gen_dir";
    147 const char kRootGenDir_HelpShort[] =
    148     "root_gen_dir: [string] Directory for the toolchain's generated files.";
    149 const char kRootGenDir_Help[] =
    150     "root_gen_dir: Directory for the toolchain's generated files.\n"
    151     "\n"
    152     "  Absolute path to the root of the generated output directory tree for\n"
    153     "  the current toolchain. An example value might be \"//out/Debug/gen\".\n"
    154     "  It will not have a trailing slash.\n"
    155     "\n"
    156     "  This is primarily useful for setting up include paths for generated\n"
    157     "  files. If you are passing this to a script, you will want to pass it\n"
    158     "  through rebase_path() (see \"gn help rebase_path\") to convert it\n"
    159     "  to be relative to the build directory.\n"
    160     "\n"
    161     "  See also \"target_gen_dir\" which is usually a better location for\n"
    162     "  generated files. It will be inside the root generated dir.\n";
    163 
    164 const char kRootOutDir[] = "root_out_dir";
    165 const char kRootOutDir_HelpShort[] =
    166     "root_out_dir: [string] Root directory for toolchain output files.";
    167 const char kRootOutDir_Help[] =
    168     "root_out_dir: [string] Root directory for toolchain output files.\n"
    169     "\n"
    170     "  Absolute path to the root of the output directory tree for the current\n"
    171     "  toolchain. An example value might be \"//out/Debug/gen\". It will not\n"
    172     "  have a trailing slash.\n"
    173     "\n"
    174     "  This is primarily useful for setting up script calls. If you are\n"
    175     "  passing this to a script, you will want to pass it through\n"
    176     "  rebase_path() (see \"gn help rebase_path\") to convert it\n"
    177     "  to be relative to the build directory.\n"
    178     "\n"
    179     "  See also \"target_out_dir\" which is usually a better location for\n"
    180     "  output files. It will be inside the root output dir.\n"
    181     "\n"
    182     "Example:\n"
    183     "\n"
    184     "  action(\"myscript\") {\n"
    185     "    # Pass the output dir to the script.\n"
    186     "    args = [ \"-o\", rebase_path(root_out_dir, root_build_dir) ]\n"
    187     "  }\n";
    188 
    189 const char kTargetGenDir[] = "target_gen_dir";
    190 const char kTargetGenDir_HelpShort[] =
    191     "target_gen_dir: [string] Directory for a target's generated files.";
    192 const char kTargetGenDir_Help[] =
    193     "target_gen_dir: Directory for a target's generated files.\n"
    194     "\n"
    195     "  Absolute path to the target's generated file directory. If your\n"
    196     "  current target is in \"//tools/doom_melon\" then this value might be\n"
    197     "  \"//out/Debug/gen/tools/doom_melon\". It will not have a trailing\n"
    198     "  slash.\n"
    199     "\n"
    200     "  This is primarily useful for setting up include paths for generated\n"
    201     "  files. If you are passing this to a script, you will want to pass it\n"
    202     "  through rebase_path() (see \"gn help rebase_path\") to convert it\n"
    203     "  to be relative to the build directory.\n"
    204     "\n"
    205     "  See also \"gn help root_gen_dir\".\n"
    206     "\n"
    207     "Example:\n"
    208     "\n"
    209     "  action(\"myscript\") {\n"
    210     "    # Pass the generated output dir to the script.\n"
    211     "    args = [ \"-o\", rebase_path(target_gen_dir, root_build_dir) ]"
    212     "\n"
    213     "  }\n";
    214 
    215 const char kTargetOutDir[] = "target_out_dir";
    216 const char kTargetOutDir_HelpShort[] =
    217     "target_out_dir: [string] Directory for target output files.";
    218 const char kTargetOutDir_Help[] =
    219     "target_out_dir: [string] Directory for target output files."
    220     "\n"
    221     "  Absolute path to the target's generated file directory. If your\n"
    222     "  current target is in \"//tools/doom_melon\" then this value might be\n"
    223     "  \"//out/Debug/obj/tools/doom_melon\". It will not have a trailing\n"
    224     "  slash.\n"
    225     "\n"
    226     "  This is primarily useful for setting up arguments for calling\n"
    227     "  scripts. If you are passing this to a script, you will want to pass it\n"
    228     "  through rebase_path() (see \"gn help rebase_path\") to convert it\n"
    229     "  to be relative to the build directory.\n"
    230     "\n"
    231     "  See also \"gn help root_out_dir\".\n"
    232     "\n"
    233     "Example:\n"
    234     "\n"
    235     "  action(\"myscript\") {\n"
    236     "    # Pass the output dir to the script.\n"
    237     "    args = [ \"-o\", rebase_path(target_out_dir, root_build_dir) ]"
    238     "\n"
    239     "  }\n";
    240 
    241 // Target variables ------------------------------------------------------------
    242 
    243 #define COMMON_ORDERING_HELP \
    244     "\n" \
    245     "Ordering of flags and values:\n" \
    246     "\n" \
    247     "  1. Those set on the current target (not in a config).\n" \
    248     "  2. Those set on the \"configs\" on the target in order that the\n" \
    249     "     configs appear in the list.\n" \
    250     "  3. Those set on the \"all_dependent_configs\" on the target in order\n" \
    251     "     that the configs appear in the list.\n" \
    252     "  4. Those set on the \"direct_dependent_configs\" on the target in\n" \
    253     "     order that those configs appear in the list.\n" \
    254     "  5. all_dependent_configs pulled from dependencies, in the order of\n" \
    255     "     the \"deps\" list. This is done recursively. If a config appears\n" \
    256     "     more than once, only the first occurance will be used.\n" \
    257     "  6. direct_dependent_configs pulled from dependencies, in the order\n" \
    258     "     of the \"deps\" list. If a dependency has\n" \
    259     "     \"forward_dependent_configs_from\", they will be applied\n" \
    260     "     recursively.\n"
    261 
    262 const char kAllDependentConfigs[] = "all_dependent_configs";
    263 const char kAllDependentConfigs_HelpShort[] =
    264     "all_dependent_configs: [label list] Configs to be forced on dependents.";
    265 const char kAllDependentConfigs_Help[] =
    266     "all_dependent_configs: Configs to be forced on dependents.\n"
    267     "\n"
    268     "  A list of config labels.\n"
    269     "\n"
    270     "  All targets depending on this one, and recursively, all targets\n"
    271     "  depending on those, will have the configs listed in this variable\n"
    272     "  added to them. These configs will also apply to the current target.\n"
    273     "\n"
    274     "  This addition happens in a second phase once a target and all of its\n"
    275     "  dependencies have been resolved. Therefore, a target will not see\n"
    276     "  these force-added configs in their \"configs\" variable while the\n"
    277     "  script is running, and then can not be removed. As a result, this\n"
    278     "  capability should generally only be used to add defines and include\n"
    279     "  directories necessary to compile a target's headers.\n"
    280     "\n"
    281     "  See also \"direct_dependent_configs\".\n"
    282     COMMON_ORDERING_HELP;
    283 
    284 const char kArgs[] = "args";
    285 const char kArgs_HelpShort[] =
    286     "args: [string list] Arguments passed to an action.";
    287 const char kArgs_Help[] =
    288     "args: Arguments passed to an action.\n"
    289     "\n"
    290     "  For action and action_foreach targets, args is the list of arguments\n"
    291     "  to pass to the script. Typically you would use source expansion (see\n"
    292     "  \"gn help source_expansion\") to insert the source file names.\n"
    293     "\n"
    294     "  See also \"gn help action\" and \"gn help action_foreach\".\n";
    295 
    296 const char kCflags[] = "cflags";
    297 const char kCflags_HelpShort[] =
    298     "cflags: [string list] Flags passed to all C compiler variants.";
    299 const char kCommonCflagsHelp[] =
    300     "cflags*: Flags passed to the C compiler.\n"
    301     "\n"
    302     "  A list of strings.\n"
    303     "\n"
    304     "  \"cflags\" are passed to all invocations of the C, C++, Objective C,\n"
    305     "  and Objective C++ compilers.\n"
    306     "\n"
    307     "  To target one of these variants individually, use \"cflags_c\",\n"
    308     "  \"cflags_cc\", \"cflags_objc\", and \"cflags_objcc\", respectively.\n"
    309     "  These variant-specific versions will be appended to the \"cflags\".\n"
    310     COMMON_ORDERING_HELP;
    311 const char* kCflags_Help = kCommonCflagsHelp;
    312 
    313 const char kCflagsC[] = "cflags_c";
    314 const char kCflagsC_HelpShort[] =
    315     "cflags_c: [string list] Flags passed to the C compiler.";
    316 const char* kCflagsC_Help = kCommonCflagsHelp;
    317 
    318 const char kCflagsCC[] = "cflags_cc";
    319 const char kCflagsCC_HelpShort[] =
    320     "cflags_cc: [string list] Flags passed to the C++ compiler.";
    321 const char* kCflagsCC_Help = kCommonCflagsHelp;
    322 
    323 const char kCflagsObjC[] = "cflags_objc";
    324 const char kCflagsObjC_HelpShort[] =
    325     "cflags_objc: [string list] Flags passed to the Objective C compiler.";
    326 const char* kCflagsObjC_Help = kCommonCflagsHelp;
    327 
    328 const char kCflagsObjCC[] = "cflags_objcc";
    329 const char kCflagsObjCC_HelpShort[] =
    330     "cflags_objcc: [string list] Flags passed to the Objective C++ compiler.";
    331 const char* kCflagsObjCC_Help = kCommonCflagsHelp;
    332 
    333 const char kConfigs[] = "configs";
    334 const char kConfigs_HelpShort[] =
    335     "configs: [label list] Configs applying to this target.";
    336 const char kConfigs_Help[] =
    337     "configs: Configs applying to this target.\n"
    338     "\n"
    339     "  A list of config labels.\n"
    340     "\n"
    341     "  The include_dirs, defines, etc. in each config are appended in the\n"
    342     "  order they appear to the compile command for each file in the target.\n"
    343     "  They will appear after the include_dirs, defines, etc. that the target\n"
    344     "  sets directly.\n"
    345     "\n"
    346     "  The build configuration script will generally set up the default\n"
    347     "  configs applying to a given target type (see \"set_defaults\").\n"
    348     "  When a target is being defined, it can add to or remove from this\n"
    349     "  list.\n"
    350     COMMON_ORDERING_HELP
    351     "\n"
    352     "Example:\n"
    353     "  static_library(\"foo\") {\n"
    354     "    configs -= \"//build:no_rtti\"  # Don't use the default RTTI config.\n"
    355     "    configs += \":mysettings\"      # Add some of our own settings.\n"
    356     "  }\n";
    357 
    358 const char kData[] = "data";
    359 const char kData_HelpShort[] =
    360     "data: [file list] Runtime data file dependencies.";
    361 const char kData_Help[] =
    362     "data: Runtime data file dependencies.\n"
    363     "\n"
    364     "  Lists files required to run the given target. These are typically\n"
    365     "  data files.\n"
    366     "\n"
    367     "  Appearing in the \"data\" section does not imply any special handling\n"
    368     "  such as copying them to the output directory. This is just used for\n"
    369     "  declaring runtime dependencies. There currently isn't a good use for\n"
    370     "  these but it is envisioned that test data can be listed here for use\n"
    371     "  running automated tests.\n"
    372     "\n"
    373     "  See also \"gn help inputs\" and \"gn help datadeps\", both of\n"
    374     "  which actually affect the build in concrete ways.\n";
    375 
    376 const char kDatadeps[] = "datadeps";
    377 const char kDatadeps_HelpShort[] =
    378     "datadeps: [label list] Non-linked dependencies.";
    379 const char kDatadeps_Help[] =
    380     "datadeps: Non-linked dependencies.\n"
    381     "\n"
    382     "  A list of target labels.\n"
    383     "\n"
    384     "  Specifies dependencies of a target that are not actually linked into\n"
    385     "  the current target. Such dependencies will built and will be available\n"
    386     "  at runtime.\n"
    387     "\n"
    388     "  This is normally used for things like plugins or helper programs that\n"
    389     "  a target needs at runtime.\n"
    390     "\n"
    391     "  See also \"gn help deps\" and \"gn help data\".\n"
    392     "\n"
    393     "Example:\n"
    394     "  executable(\"foo\") {\n"
    395     "    deps = [ \"//base\" ]\n"
    396     "    datadeps = [ \"//plugins:my_runtime_plugin\" ]\n"
    397     "  }\n";
    398 
    399 const char kDefines[] = "defines";
    400 const char kDefines_HelpShort[] =
    401     "defines: [string list] C preprocessor defines.";
    402 const char kDefines_Help[] =
    403     "defines: C preprocessor defines.\n"
    404     "\n"
    405     "  A list of strings\n"
    406     "\n"
    407     "  These strings will be passed to the C/C++ compiler as #defines. The\n"
    408     "  strings may or may not include an \"=\" to assign a value.\n"
    409     COMMON_ORDERING_HELP
    410     "\n"
    411     "Example:\n"
    412     "  defines = [ \"AWESOME_FEATURE\", \"LOG_LEVEL=3\" ]\n";
    413 
    414 const char kDepfile[] = "depfile";
    415 const char kDepfile_HelpShort[] =
    416     "depfile: [string] File name for input dependencies for actions.";
    417 const char kDepfile_Help[] =
    418     "depfile: [string] File name for input dependencies for actions.\n"
    419     "\n"
    420     "  If nonempty, this string specifies that the current action or\n"
    421     "  action_foreach target will generate the given \".d\" file containing\n"
    422     "  the dependencies of the input. Empty or unset means that the script\n"
    423     "  doesn't generate the files.\n"
    424     "\n"
    425     "  The .d file should go in the target output directory. If you have more\n"
    426     "  than one source file that the script is being run over, you can use\n"
    427     "  the output file expansions described in \"gn help action_foreach\" to\n"
    428     "  name the .d file according to the input."
    429     "\n"
    430     "  The format is that of a Makefile, and all of the paths should be\n"
    431     "  relative to the root build directory.\n"
    432     "\n"
    433     "Example:\n"
    434     "  action_foreach(\"myscript_target\") {\n"
    435     "    script = \"myscript.py\"\n"
    436     "    sources = [ ... ]\n"
    437     "\n"
    438     "    # Locate the depfile in the output directory named like the\n"
    439     "    # inputs but with a \".d\" appended.\n"
    440     "    depfile = \"$relative_target_output_dir/{{source_name}}.d\"\n"
    441     "\n"
    442     "    # Say our script uses \"-o <d file>\" to indicate the depfile.\n"
    443     "    args = [ \"{{source}}\", \"-o\", depfile ]\n"
    444     "  }\n";
    445 
    446 const char kDeps[] = "deps";
    447 const char kDeps_HelpShort[] =
    448     "deps: [label list] Linked dependencies.";
    449 const char kDeps_Help[] =
    450     "deps: Linked dependencies.\n"
    451     "\n"
    452     "  A list of target labels.\n"
    453     "\n"
    454     "  Specifies dependencies of a target. Shared and dynamic libraries will\n"
    455     "  be linked into the current target. Other target types that can't be\n"
    456     "  linked (like actions and groups) listed in \"deps\" will be treated\n"
    457     "  as \"datadeps\". Likewise, if the current target isn't linkable, then\n"
    458     "  all deps will be treated as \"datadeps\".\n"
    459     "\n"
    460     "  See also \"datadeps\".\n";
    461 
    462 const char kDirectDependentConfigs[] = "direct_dependent_configs";
    463 const char kDirectDependentConfigs_HelpShort[] =
    464     "direct_dependent_configs: [label list] Configs to be forced on "
    465     "dependents.";
    466 const char kDirectDependentConfigs_Help[] =
    467     "direct_dependent_configs: Configs to be forced on dependents.\n"
    468     "\n"
    469     "  A list of config labels.\n"
    470     "\n"
    471     "  Targets directly referencing this one will have the configs listed in\n"
    472     "  this variable added to them. These configs will also apply to the\n"
    473     "  current target.\n"
    474     "\n"
    475     "  This addition happens in a second phase once a target and all of its\n"
    476     "  dependencies have been resolved. Therefore, a target will not see\n"
    477     "  these force-added configs in their \"configs\" variable while the\n"
    478     "  script is running, and then can not be removed. As a result, this\n"
    479     "  capability should generally only be used to add defines and include\n"
    480     "  directories necessary to compile a target's headers.\n"
    481     "\n"
    482     "  See also \"all_dependent_configs\".\n"
    483     COMMON_ORDERING_HELP;
    484 
    485 const char kForwardDependentConfigsFrom[] = "forward_dependent_configs_from";
    486 const char kForwardDependentConfigsFrom_HelpShort[] =
    487     "forward_dependent_configs_from: [label list] Forward dependent's configs.";
    488 const char kForwardDependentConfigsFrom_Help[] =
    489     "forward_dependent_configs_from\n"
    490     "\n"
    491     "  A list of target labels.\n"
    492     "\n"
    493     "  Exposes the direct_dependent_configs from a dependent target as\n"
    494     "  direct_dependent_configs of the current one. Each label in this list\n"
    495     "  must also be in the deps.\n"
    496     "\n"
    497     "  Sometimes you depend on a child library that exports some necessary\n"
    498     "  configuration via direct_dependent_configs. If your target in turn\n"
    499     "  exposes the child library's headers in its public headers, it might\n"
    500     "  mean that targets that depend on you won't work: they'll be seeing the\n"
    501     "  child library's code but not the necessary configuration. This list\n"
    502     "  specifies which of your deps' direct dependent configs to expose as\n"
    503     "  your own.\n"
    504     "\n"
    505     "Examples:\n"
    506     "\n"
    507     "  If we use a given library \"a\" from our public headers:\n"
    508     "\n"
    509     "    deps = [ \":a\", \":b\", ... ]\n"
    510     "    forward_dependent_configs_from = [ \":a\" ]\n"
    511     "\n"
    512     "  This example makes a \"transparent\" target that forwards a dependency\n"
    513     "  to another:\n"
    514     "\n"
    515     "    group(\"frob\") {\n"
    516     "      if (use_system_frob) {\n"
    517     "        deps = \":system_frob\"\n"
    518     "      } else {\n"
    519     "        deps = \"//third_party/fallback_frob\"\n"
    520     "      }\n"
    521     "      forward_dependent_configs_from = deps\n"
    522     "    }\n";
    523 
    524 const char kIncludeDirs[] = "include_dirs";
    525 const char kIncludeDirs_HelpShort[] =
    526     "include_dirs: [directory list] Additional include directories.";
    527 const char kIncludeDirs_Help[] =
    528     "include_dirs: Additional include directories.\n"
    529     "\n"
    530     "  A list of source directories.\n"
    531     "\n"
    532     "  The directories in this list will be added to the include path for\n"
    533     "  the files in the affected target.\n"
    534     COMMON_ORDERING_HELP
    535     "\n"
    536     "Example:\n"
    537     "  include_dirs = [ \"src/include\", \"//third_party/foo\" ]\n";
    538 
    539 const char kInputs[] = "inputs";
    540 const char kInputs_HelpShort[] =
    541     "inputs: [file list] Additional compile-time dependencies.";
    542 const char kInputs_Help[] =
    543     "inputs: Additional compile-time dependencies.\n"
    544     "\n"
    545     "  Inputs are compile-time dependencies of the current target. This means\n"
    546     "  that all inputs must be available before compiling any of the sources\n"
    547     "  or executing any actions.\n"
    548     "\n"
    549     "  Inputs are typically only used for action and action_foreach targets.\n"
    550     "\n"
    551     "Inputs for actions\n"
    552     "\n"
    553     "  For action and action_foreach targets, inputs should be the inputs to\n"
    554     "  script that don't vary. These should be all .py files that the script\n"
    555     "  uses via imports (the main script itself will be an implcit dependency\n"
    556     "  of the action so need not be listed).\n"
    557     "\n"
    558     "  For action targets, inputs should be the entire set of inputs the\n"
    559     "  script needs. For action_foreach targets, inputs should be the set of\n"
    560     "  dependencies that don't change. These will be applied to each script\n"
    561     "  invocation over the sources.\n"
    562     "\n"
    563     "  Note that another way to declare input dependencies from an action\n"
    564     "  is to have the action write a depfile (see \"gn help depfile\"). This\n"
    565     "  allows the script to dynamically write input dependencies, that might\n"
    566     "  not be known until actually executing the script. This is more\n"
    567     "  efficient than doing processing while running GN to determine the\n"
    568     "  inputs, and is easier to keep in-sync than hardcoding the list.\n"
    569     "\n"
    570     "Inputs for binary targets\n"
    571     "\n"
    572     "  Any input dependencies will be resolved before compiling any sources.\n"
    573     "  Normally, all actions that a target depends on will be run before any\n"
    574     "  files in a target are compiled. So if you depend on generated headers,\n"
    575     "  you do not typically need to list them in the inputs section.\n"
    576     "\n"
    577     "Example\n"
    578     "\n"
    579     "  action(\"myscript\") {\n"
    580     "    script = \"domything.py\"\n"
    581     "    inputs = [ \"input.data\" ]\n"
    582     "  }\n";
    583 
    584 const char kLdflags[] = "ldflags";
    585 const char kLdflags_HelpShort[] =
    586     "ldflags: [string list] Flags passed to the linker.";
    587 const char kLdflags_Help[] =
    588     "ldflags: Flags passed to the linker.\n"
    589     "\n"
    590     "  A list of strings.\n"
    591     "\n"
    592     "  These flags are passed on the command-line to the linker and generally\n"
    593     "  specify various linking options. Most targets will not need these and\n"
    594     "  will use \"libs\" and \"lib_dirs\" instead.\n"
    595     "\n"
    596     "  ldflags are NOT pushed to dependents, so applying ldflags to source\n"
    597     "  sets or static libraries will be a no-op. If you want to apply ldflags\n"
    598     "  to dependent targets, put them in a config and set it in the\n"
    599     "  all_dependent_configs or direct_dependent_configs.\n";
    600 
    601 #define COMMON_LIB_INHERITANCE_HELP \
    602     "\n" \
    603     "  libs and lib_dirs work differently than other flags in two respects.\n" \
    604     "  First, then are inherited across static library boundaries until a\n" \
    605     "  shared library or executable target is reached. Second, they are\n" \
    606     "  uniquified so each one is only passed once (the first instance of it\n" \
    607     "  will be the one used).\n"
    608 
    609 const char kLibDirs[] = "lib_dirs";
    610 const char kLibDirs_HelpShort[] =
    611     "lib_dirs: [directory list] Additional library directories.";
    612 const char kLibDirs_Help[] =
    613     "lib_dirs: Additional library directories.\n"
    614     "\n"
    615     "  A list of directories.\n"
    616     "\n"
    617     "  Specifies additional directories passed to the linker for searching\n"
    618     "  for the required libraries. If an item is not an absolute path, it\n"
    619     "  will be treated as being relative to the current build file.\n"
    620     COMMON_LIB_INHERITANCE_HELP
    621     COMMON_ORDERING_HELP
    622     "\n"
    623     "Example:\n"
    624     "  lib_dirs = [ \"/usr/lib/foo\", \"lib/doom_melon\" ]\n";
    625 
    626 const char kLibs[] = "libs";
    627 const char kLibs_HelpShort[] =
    628     "libs: [string list] Additional libraries to link.";
    629 const char kLibs_Help[] =
    630     "libs: Additional libraries to link.\n"
    631     "\n"
    632     "  A list of strings.\n"
    633     "\n"
    634     "  These files will be passed to the linker, which will generally search\n"
    635     "  the library include path. Unlike a normal list of files, they will be\n"
    636     "  passed to the linker unmodified rather than being treated as file\n"
    637     "  names relative to the current build file. Generally you would set\n"
    638     "  the \"lib_dirs\" so your library is found. If you need to specify\n"
    639     "  a path, you can use \"rebase_path\" to convert a path to be relative\n"
    640     "  to the build directory.\n"
    641     "\n"
    642     "  When constructing the linker command, the \"lib_prefix\" attribute of\n"
    643     "  the linker tool in the current toolchain will be prepended to each\n"
    644     "  library. So your BUILD file should not specify the switch prefix\n"
    645     "  (like \"-l\"). On Mac, libraries ending in \".framework\" will be\n"
    646     "  special-cased: the switch \"-framework\" will be prepended instead of\n"
    647     "  the lib_prefix, and the \".framework\" suffix will be trimmed.\n"
    648     COMMON_LIB_INHERITANCE_HELP
    649     COMMON_ORDERING_HELP
    650     "\n"
    651     "Examples:\n"
    652     "  On Windows:\n"
    653     "    libs = [ \"ctl3d.lib\" ]\n"
    654     "  On Linux:\n"
    655     "    libs = [ \"ld\" ]\n";
    656 
    657 const char kOutputExtension[] = "output_extension";
    658 const char kOutputExtension_HelpShort[] =
    659     "output_extension: [string] Value to use for the output's file extension.";
    660 const char kOutputExtension_Help[] =
    661     "output_extension: Value to use for the output's file extension.\n"
    662     "\n"
    663     "  Normally the file extension for a target is based on the target\n"
    664     "  type and the operating system, but in rare cases you will need to\n"
    665     "  override the name (for example to use \"libfreetype.so.6\" instead\n"
    666     "  of libfreetype.so on Linux).";
    667 
    668 const char kOutputName[] = "output_name";
    669 const char kOutputName_HelpShort[] =
    670     "output_name: [string] Name for the output file other than the default.";
    671 const char kOutputName_Help[] =
    672     "output_name: Define a name for the output file other than the default.\n"
    673     "\n"
    674     "  Normally the output name of a target will be based on the target name,\n"
    675     "  so the target \"//foo/bar:bar_unittests\" will generate an output\n"
    676     "  file such as \"bar_unittests.exe\" (using Windows as an example).\n"
    677     "\n"
    678     "  Sometimes you will want an alternate name to avoid collisions or\n"
    679     "  if the internal name isn't appropriate for public distribution.\n"
    680     "\n"
    681     "  The output name should have no extension or prefixes, these will be\n"
    682     "  added using the default system rules. For example, on Linux an output\n"
    683     "  name of \"foo\" will produce a shared library \"libfoo.so\".\n"
    684     "\n"
    685     "  This variable is valid for all binary output target types.\n"
    686     "\n"
    687     "Example:\n"
    688     "  static_library(\"doom_melon\") {\n"
    689     "    output_name = \"fluffy_bunny\"\n"
    690     "  }\n";
    691 
    692 const char kOutputs[] = "outputs";
    693 const char kOutputs_HelpShort[] =
    694     "outputs: [file list] Output files for actions and copy targets.";
    695 const char kOutputs_Help[] =
    696     "outputs: Output files for actions and copy targets.\n"
    697     "\n"
    698     "  Outputs is valid for \"copy\", \"action\", and \"action_foreach\"\n"
    699     "  target types and indicates the resulting files. The values may contain\n"
    700     "  source expansions to generate the output names from the sources (see\n"
    701     "  \"gn help source_expansion\").\n"
    702     "\n"
    703     "  For copy targets, the outputs is the destination for the copied\n"
    704     "  file(s). For actions, the outputs should be the list of files\n"
    705     "  generated by the script.\n";
    706 
    707 const char kPublic[] = "public";
    708 const char kPublic_HelpShort[] =
    709     "public: [file list] Declare public header files for a target.";
    710 const char kPublic_Help[] =
    711     "public: Declare public header files for a target.\n"
    712     "\n"
    713     "  A list of files that other targets can include. These permissions are\n"
    714     "  checked via the \"check\" command (see \"gn help check\").\n"
    715     "\n"
    716     "  If no public files are declared, other targets (assuming they have\n"
    717     "  visibility to depend on this target can include any file in the\n"
    718     "  sources list. If this variable is defined on a target, dependent\n"
    719     "  targets may only include files on this whitelist.\n"
    720     "\n"
    721     "  Header file permissions are also subject to visibility. A target\n"
    722     "  must be visible to another target to include any files from it at all\n"
    723     "  and the public headers indicate which subset of those files are\n"
    724     "  permitted. See \"gn help visibility\" for more.\n"
    725     "\n"
    726     "  Public files are inherited through the dependency tree. So if there is\n"
    727     "  a dependency A -> B -> C, then A can include C's public headers.\n"
    728     "  However, the same is NOT true of visibility, so unless A is in C's\n"
    729     "  visibility list, the include will be rejected.\n"
    730     "\n"
    731     "  GN only knows about files declared in the \"sources\" and \"public\"\n"
    732     "  sections of targets. If a file is included that is not known to the\n"
    733     "  build, it will be allowed.\n"
    734     "\n"
    735     "Examples:\n"
    736     "  These exact files are public:\n"
    737     "    public = [ \"foo.h\", \"bar.h\" ]\n"
    738     "\n"
    739     "  No files are public (no targets may include headers from this one):\n"
    740     "    public = []\n";
    741 
    742 const char kScript[] = "script";
    743 const char kScript_HelpShort[] =
    744     "script: [file name] Script file for actions.";
    745 const char kScript_Help[] =
    746     "script: Script file for actions.\n"
    747     "\n"
    748     "  An absolute or buildfile-relative file name of a Python script to run\n"
    749     "  for a action and action_foreach targets (see \"gn help action\" and\n"
    750     "  \"gn help action_foreach\").\n";
    751 
    752 const char kSources[] = "sources";
    753 const char kSources_HelpShort[] =
    754     "sources: [file list] Source files for a target.";
    755 const char kSources_Help[] =
    756     "sources: Source files for a target\n"
    757     "\n"
    758     "  A list of files relative to the current buildfile.\n";
    759 
    760 const char kVisibility[] = "visibility";
    761 const char kVisibility_HelpShort[] =
    762     "visibility: [label list] A list of labels that can depend on a target.";
    763 const char kVisibility_Help[] =
    764     "visibility: A list of labels that can depend on a target.\n"
    765     "\n"
    766     "  A label or a list of labels and label patterns that define which\n"
    767     "  targets can depend on the current one. These permissions are checked\n"
    768     "  via then \"check\" command (see \"gn help check\").\n"
    769     "\n"
    770     "  If visibility is not defined, it defaults to public (\"*\").\n"
    771     "\n"
    772     "  If visibility is defined, only the targets with labels that match it\n"
    773     "  can depend on the current target. The empty list means no targets\n"
    774     "  can depend on the current target.\n"
    775     "\n"
    776     "  Tip: Often you will want the same visibility for all targets in a\n"
    777     "  BUILD file. In this case you can just put the definition at the top,\n"
    778     "  outside of any target, and the targets will inherit that scope and see\n"
    779     "  the definition.\n"
    780     "\n"
    781     "Matching:\n"
    782     "\n"
    783     "  You can specify \"*\" but the inputs aren't general patterns. The\n"
    784     "  following classes of patterns are supported:\n"
    785     "\n"
    786     "   - Explicit (no wildcard):\n"
    787     "       \"//foo/bar:baz\"\n"
    788     "       \":baz\"\n"
    789     "   - Wildcard target names:\n"
    790     "       \"//foo/bar:*\" (any target in the //foo/bar/BUILD.gn file)\n"
    791     "       \":*\"  (any target in the current build file)\n"
    792     "   - Wildcard directory names (\"*\" is only supported at the end)\n"
    793     "       \"*\"  (any target anywhere)\n"
    794     "       \"//foo/bar/*\"  (any target in any subdir of //foo/bar)\n"
    795     "       \"./*\"  (any target in the current build file or sub dirs)\n"
    796     "\n"
    797     "  The toolchain (normally an implicit part of a label) is ignored when\n"
    798     "  checking visibility.\n"
    799     "\n"
    800     "Examples:\n"
    801     "\n"
    802     "  Only targets in the current buildfile (\"private\", the default):\n"
    803     "    visibility = \":*\"\n"
    804     "\n"
    805     "  No targets (used for targets that should be leaf nodes):\n"
    806     "    visibility = []\n"
    807     "\n"
    808     "  Any target (\"public\"):\n"
    809     "    visibility = \"*\"\n"
    810     "\n"
    811     "  All targets in the current directory and any subdirectory:\n"
    812     "    visibility = \"./*\"\n"
    813     "\n"
    814     "  Any target in \"//bar/BUILD.gn\":\n"
    815     "    visibility = \"//bar:*\"\n"
    816     "\n"
    817     "  Any target in \"//bar/\" or any subdirectory thereof:\n"
    818     "    visibility = \"//bar/*\"\n"
    819     "\n"
    820     "  Just these specific targets:\n"
    821     "    visibility = [ \":mything\", \"//foo:something_else\" ]\n"
    822     "\n"
    823     "  Any target in the current directory and any subdirectory thereof, plus\n"
    824     "  any targets in \"//bar/\" and any subdirectory thereof.\n"
    825     "    visibility = [ \"./*\", \"//bar/*\" ]\n";
    826 
    827 // -----------------------------------------------------------------------------
    828 
    829 VariableInfo::VariableInfo()
    830     : help_short(NULL),
    831       help(NULL) {
    832 }
    833 
    834 VariableInfo::VariableInfo(const char* in_help_short, const char* in_help)
    835     : help_short(in_help_short),
    836       help(in_help) {
    837 }
    838 
    839 #define INSERT_VARIABLE(var) \
    840     info_map[k##var] = VariableInfo(k##var##_HelpShort, k##var##_Help);
    841 
    842 const VariableInfoMap& GetBuiltinVariables() {
    843   static VariableInfoMap info_map;
    844   if (info_map.empty()) {
    845     INSERT_VARIABLE(BuildCpuArch)
    846     INSERT_VARIABLE(BuildOs)
    847     INSERT_VARIABLE(CpuArch)
    848     INSERT_VARIABLE(ComponentMode)
    849     INSERT_VARIABLE(CurrentToolchain)
    850     INSERT_VARIABLE(DefaultToolchain)
    851     INSERT_VARIABLE(Os)
    852     INSERT_VARIABLE(PythonPath)
    853     INSERT_VARIABLE(RootBuildDir)
    854     INSERT_VARIABLE(RootGenDir)
    855     INSERT_VARIABLE(RootOutDir)
    856     INSERT_VARIABLE(TargetGenDir)
    857     INSERT_VARIABLE(TargetOutDir)
    858   }
    859   return info_map;
    860 }
    861 
    862 const VariableInfoMap& GetTargetVariables() {
    863   static VariableInfoMap info_map;
    864   if (info_map.empty()) {
    865     INSERT_VARIABLE(AllDependentConfigs)
    866     INSERT_VARIABLE(Args)
    867     INSERT_VARIABLE(Cflags)
    868     INSERT_VARIABLE(CflagsC)
    869     INSERT_VARIABLE(CflagsCC)
    870     INSERT_VARIABLE(CflagsObjC)
    871     INSERT_VARIABLE(CflagsObjCC)
    872     INSERT_VARIABLE(Configs)
    873     INSERT_VARIABLE(Data)
    874     INSERT_VARIABLE(Datadeps)
    875     INSERT_VARIABLE(Depfile)
    876     INSERT_VARIABLE(Deps)
    877     INSERT_VARIABLE(DirectDependentConfigs)
    878     INSERT_VARIABLE(ForwardDependentConfigsFrom)
    879     INSERT_VARIABLE(IncludeDirs)
    880     INSERT_VARIABLE(Inputs)
    881     INSERT_VARIABLE(Ldflags)
    882     INSERT_VARIABLE(Libs)
    883     INSERT_VARIABLE(LibDirs)
    884     INSERT_VARIABLE(OutputExtension)
    885     INSERT_VARIABLE(OutputName)
    886     INSERT_VARIABLE(Outputs)
    887     INSERT_VARIABLE(Public)
    888     INSERT_VARIABLE(Script)
    889     INSERT_VARIABLE(Sources)
    890     INSERT_VARIABLE(Visibility)
    891   }
    892   return info_map;
    893 }
    894 
    895 #undef INSERT_VARIABLE
    896 
    897 }  // namespace variables
    898