This source file includes following definitions.
- RunSetDefaults
#include "tools/gn/err.h"
#include "tools/gn/functions.h"
#include "tools/gn/parse_tree.h"
#include "tools/gn/scope.h"
namespace functions {
const char kSetDefaults[] = "set_defaults";
const char kSetDefaults_HelpShort[] =
"set_defaults: Set default values for a target type.";
const char kSetDefaults_Help[] =
"set_defaults: Set default values for a target type.\n"
"\n"
" set_defaults(<target_type_name>) { <values...> }\n"
"\n"
" Sets the default values for a given target type. Whenever\n"
" target_type_name is seen in the future, the values specified in\n"
" set_default's block will be copied into the current scope.\n"
"\n"
" When the target type is used, the variable copying is very strict.\n"
" If a variable with that name is already in scope, the build will fail\n"
" with an error.\n"
"\n"
" set_defaults can be used for built-in target types (\"executable\",\n"
" \"shared_library\", etc.) and custom ones defined via the \"template\"\n"
" command.\n"
"\n"
"Example:\n"
" set_defaults(\"static_library\") {\n"
" configs = [ \"//tools/mything:settings\" ]\n"
" }\n"
"\n"
" static_library(\"mylib\")\n"
" # The configs will be auto-populated as above. You can remove it if\n"
" # you don't want the default for a particular default:\n"
" configs -= \"//tools/mything:settings\"\n"
" }\n";
Value RunSetDefaults(Scope* scope,
const FunctionCallNode* function,
const std::vector<Value>& args,
BlockNode* block,
Err* err) {
if (!EnsureSingleStringArg(function, args, err))
return Value();
const std::string& target_type(args[0].string_value());
if (scope->GetTargetDefaults(target_type)) {
*err = Err(function->function(),
"This target type defaults were already set.");
return Value();
}
if (!block) {
FillNeedsBlockError(function, err);
return Value();
}
Scope block_scope(scope);
block->ExecuteBlockInScope(&block_scope, err);
if (err->has_error())
return Value();
Scope* dest = scope->MakeTargetDefaults(target_type);
block_scope.NonRecursiveMergeTo(dest, false, function,
"<SHOULD NOT FAIL>", err);
return Value();
}
}