| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/files/file_util.h" | 5 #include "base/files/file_util.h" |
| 6 #include "tools/gn/err.h" | 6 #include "tools/gn/err.h" |
| 7 #include "tools/gn/filesystem_utils.h" | 7 #include "tools/gn/filesystem_utils.h" |
| 8 #include "tools/gn/functions.h" | 8 #include "tools/gn/functions.h" |
| 9 #include "tools/gn/input_conversion.h" | 9 #include "tools/gn/input_conversion.h" |
| 10 #include "tools/gn/input_file.h" | 10 #include "tools/gn/input_file.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 if (args.size() != 2) { | 46 if (args.size() != 2) { |
| 47 *err = Err(function->function(), "Wrong number of arguments to read_file", | 47 *err = Err(function->function(), "Wrong number of arguments to read_file", |
| 48 "I expected two arguments."); | 48 "I expected two arguments."); |
| 49 return Value(); | 49 return Value(); |
| 50 } | 50 } |
| 51 if (!args[0].VerifyTypeIs(Value::STRING, err)) | 51 if (!args[0].VerifyTypeIs(Value::STRING, err)) |
| 52 return Value(); | 52 return Value(); |
| 53 | 53 |
| 54 // Compute the file name. | 54 // Compute the file name. |
| 55 const SourceDir& cur_dir = scope->GetSourceDir(); | 55 const SourceDir& cur_dir = scope->GetSourceDir(); |
| 56 SourceFile source_file = cur_dir.ResolveRelativeFile(args[0].string_value(), | 56 SourceFile source_file = cur_dir.ResolveRelativeFile(args[0], err, |
| 57 scope->settings()->build_settings()->root_path_utf8()); | 57 scope->settings()->build_settings()->root_path_utf8()); |
| 58 if (err->has_error()) |
| 59 return Value(); |
| 58 base::FilePath file_path = | 60 base::FilePath file_path = |
| 59 scope->settings()->build_settings()->GetFullPath(source_file); | 61 scope->settings()->build_settings()->GetFullPath(source_file); |
| 60 | 62 |
| 61 // Ensure that everything is recomputed if the read file changes. | 63 // Ensure that everything is recomputed if the read file changes. |
| 62 g_scheduler->AddGenDependency(file_path); | 64 g_scheduler->AddGenDependency(file_path); |
| 63 | 65 |
| 64 // Read contents. | 66 // Read contents. |
| 65 std::string file_contents; | 67 std::string file_contents; |
| 66 if (!base::ReadFileToString(file_path, &file_contents)) { | 68 if (!base::ReadFileToString(file_path, &file_contents)) { |
| 67 *err = Err(args[0], "Could not read file.", | 69 *err = Err(args[0], "Could not read file.", |
| 68 "I resolved this to \"" + FilePathToUTF8(file_path) + "\"."); | 70 "I resolved this to \"" + FilePathToUTF8(file_path) + "\"."); |
| 69 return Value(); | 71 return Value(); |
| 70 } | 72 } |
| 71 | 73 |
| 72 return ConvertInputToValue(scope->settings(), file_contents, function, | 74 return ConvertInputToValue(scope->settings(), file_contents, function, |
| 73 args[1], err); | 75 args[1], err); |
| 74 } | 76 } |
| 75 | 77 |
| 76 } // namespace functions | 78 } // namespace functions |
| OLD | NEW |