Landing Recent QUIC changes until 8/19/2015 17:00 UTC.
[chromium-blink-merge.git] / tools / gn / config_values_generator.cc
blob7eb7bc5cd9b0b213bd89d53556dc7b92e35f12ab
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.
5 #include "tools/gn/config_values_generator.h"
7 #include "base/strings/string_util.h"
8 #include "tools/gn/config_values.h"
9 #include "tools/gn/scope.h"
10 #include "tools/gn/settings.h"
11 #include "tools/gn/value.h"
12 #include "tools/gn/value_extractors.h"
13 #include "tools/gn/variables.h"
15 namespace {
17 void GetStringList(
18 Scope* scope,
19 const char* var_name,
20 ConfigValues* config_values,
21 std::vector<std::string>& (ConfigValues::* accessor)(),
22 Err* err) {
23 const Value* value = scope->GetValue(var_name, true);
24 if (!value)
25 return; // No value, empty input and succeed.
27 std::vector<std::string> result;
28 ExtractListOfStringValues(*value, &result, err);
29 (config_values->*accessor)().swap(result);
32 void GetDirList(
33 Scope* scope,
34 const char* var_name,
35 ConfigValues* config_values,
36 const SourceDir input_dir,
37 std::vector<SourceDir>& (ConfigValues::* accessor)(),
38 Err* err) {
39 const Value* value = scope->GetValue(var_name, true);
40 if (!value)
41 return; // No value, empty input and succeed.
43 std::vector<SourceDir> result;
44 ExtractListOfRelativeDirs(scope->settings()->build_settings(),
45 *value, input_dir, &result, err);
46 (config_values->*accessor)().swap(result);
49 } // namespace
51 ConfigValuesGenerator::ConfigValuesGenerator(
52 ConfigValues* dest_values,
53 Scope* scope,
54 const SourceDir& input_dir,
55 Err* err)
56 : config_values_(dest_values),
57 scope_(scope),
58 input_dir_(input_dir),
59 err_(err) {
62 ConfigValuesGenerator::~ConfigValuesGenerator() {
65 void ConfigValuesGenerator::Run() {
66 #define FILL_STRING_CONFIG_VALUE(name) \
67 GetStringList(scope_, #name, config_values_, &ConfigValues::name, err_);
68 #define FILL_DIR_CONFIG_VALUE(name) \
69 GetDirList(scope_, #name, config_values_, input_dir_, \
70 &ConfigValues::name, err_);
72 FILL_STRING_CONFIG_VALUE(cflags)
73 FILL_STRING_CONFIG_VALUE(cflags_c)
74 FILL_STRING_CONFIG_VALUE(cflags_cc)
75 FILL_STRING_CONFIG_VALUE(cflags_objc)
76 FILL_STRING_CONFIG_VALUE(cflags_objcc)
77 FILL_STRING_CONFIG_VALUE(defines)
78 FILL_DIR_CONFIG_VALUE( include_dirs)
79 FILL_STRING_CONFIG_VALUE(ldflags)
80 FILL_DIR_CONFIG_VALUE( lib_dirs)
81 FILL_STRING_CONFIG_VALUE(libs)
83 #undef FILL_STRING_CONFIG_VALUE
84 #undef FILL_DIR_CONFIG_VALUE
86 // Precompiled headers.
87 const Value* precompiled_header_value =
88 scope_->GetValue(variables::kPrecompiledHeader, true);
89 if (precompiled_header_value) {
90 if (!precompiled_header_value->VerifyTypeIs(Value::STRING, err_))
91 return;
93 // Check for common errors. This is a string and not a file.
94 const std::string& pch_string = precompiled_header_value->string_value();
95 if (base::StartsWith(pch_string, "//", base::CompareCase::SENSITIVE)) {
96 *err_ = Err(*precompiled_header_value,
97 "This precompiled_header value is wrong.",
98 "You need to specify a string that the compiler will match against\n"
99 "the #include lines rather than a GN-style file name.\n");
100 return;
102 config_values_->set_precompiled_header(pch_string);
105 const Value* precompiled_source_value =
106 scope_->GetValue(variables::kPrecompiledSource, true);
107 if (precompiled_source_value) {
108 config_values_->set_precompiled_source(
109 input_dir_.ResolveRelativeFile(
110 *precompiled_source_value, err_,
111 scope_->settings()->build_settings()->root_path_utf8()));
112 if (err_->has_error())
113 return;