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/config_values_generator.h" 6 7 #include "tools/gn/config_values.h" 8 #include "tools/gn/scope.h" 9 #include "tools/gn/value.h" 10 #include "tools/gn/value_extractors.h" 11 12 namespace { 13 14 void GetStringList( 15 Scope* scope, 16 const char* var_name, 17 ConfigValues* config_values, 18 void (ConfigValues::* swapper_inner)(std::vector<std::string>*), 19 Err* err) { 20 const Value* value = scope->GetValue(var_name, true); 21 if (!value) 22 return; // No value, empty input and succeed. 23 24 std::vector<std::string> result; 25 ExtractListOfStringValues(*value, &result, err); 26 (config_values->*swapper_inner)(&result); 27 } 28 29 } // namespace 30 31 ConfigValuesGenerator::ConfigValuesGenerator(ConfigValues* dest_values, 32 Scope* scope, 33 const Token& function_token, 34 const SourceDir& input_dir, 35 Err* err) 36 : config_values_(dest_values), 37 scope_(scope), 38 function_token_(function_token), 39 input_dir_(input_dir), 40 err_(err) { 41 } 42 43 ConfigValuesGenerator::~ConfigValuesGenerator() { 44 } 45 46 void ConfigValuesGenerator::Run() { 47 FillIncludes(); 48 49 #define FILL_CONFIG_VALUE(name) \ 50 GetStringList(scope_, #name, config_values_, \ 51 &ConfigValues::swap_in_##name, err_); 52 53 FILL_CONFIG_VALUE(defines) 54 FILL_CONFIG_VALUE(cflags) 55 FILL_CONFIG_VALUE(cflags_c) 56 FILL_CONFIG_VALUE(cflags_cc) 57 FILL_CONFIG_VALUE(cflags_objc) 58 FILL_CONFIG_VALUE(cflags_objcc) 59 FILL_CONFIG_VALUE(ldflags) 60 61 #undef FILL_CONFIG_VALUE 62 } 63 64 void ConfigValuesGenerator::FillIncludes() { 65 const Value* value = scope_->GetValue("includes", true); 66 if (!value) 67 return; // No value, empty input and succeed. 68 69 std::vector<SourceDir> includes; 70 if (!ExtractListOfRelativeDirs(*value, input_dir_, &includes, err_)) 71 return; 72 config_values_->swap_in_includes(&includes); 73 } 74