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 <iostream> | 5 #include <iostream> |
6 #include <sstream> | 6 #include <sstream> |
7 | 7 |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 if (args.size() != 2) { | 50 if (args.size() != 2) { |
51 *err = Err(function->function(), "Wrong number of arguments to write_file", | 51 *err = Err(function->function(), "Wrong number of arguments to write_file", |
52 "I expected two arguments."); | 52 "I expected two arguments."); |
53 return Value(); | 53 return Value(); |
54 } | 54 } |
55 | 55 |
56 // Compute the file name and make sure it's in the output dir. | 56 // Compute the file name and make sure it's in the output dir. |
57 if (!args[0].VerifyTypeIs(Value::STRING, err)) | 57 if (!args[0].VerifyTypeIs(Value::STRING, err)) |
58 return Value(); | 58 return Value(); |
59 const SourceDir& cur_dir = scope->GetSourceDir(); | 59 const SourceDir& cur_dir = scope->GetSourceDir(); |
60 SourceFile source_file = cur_dir.ResolveRelativeFile(args[0].string_value()); | 60 SourceFile source_file = cur_dir.ResolveRelativeFile(args[0].string_value(), |
| 61 scope->settings()->build_settings()->root_path_utf8()); |
61 if (!EnsureStringIsInOutputDir( | 62 if (!EnsureStringIsInOutputDir( |
62 scope->settings()->build_settings()->build_dir(), | 63 scope->settings()->build_settings()->build_dir(), |
63 source_file.value(), args[0].origin(), err)) | 64 source_file.value(), args[0].origin(), err)) |
64 return Value(); | 65 return Value(); |
65 | 66 |
66 // Compute output. | 67 // Compute output. |
67 std::ostringstream contents; | 68 std::ostringstream contents; |
68 if (args[1].type() == Value::LIST) { | 69 if (args[1].type() == Value::LIST) { |
69 const std::vector<Value>& list = args[1].list_value(); | 70 const std::vector<Value>& list = args[1].list_value(); |
70 for (const auto& cur : list) | 71 for (const auto& cur : list) |
(...skipping 22 matching lines...) Expand all Loading... |
93 if (base::WriteFile(file_path, new_contents.c_str(), int_size) | 94 if (base::WriteFile(file_path, new_contents.c_str(), int_size) |
94 != int_size) { | 95 != int_size) { |
95 *err = Err(function->function(), "Unable to write file.", | 96 *err = Err(function->function(), "Unable to write file.", |
96 "I was writing \"" + FilePathToUTF8(file_path) + "\"."); | 97 "I was writing \"" + FilePathToUTF8(file_path) + "\"."); |
97 return Value(); | 98 return Value(); |
98 } | 99 } |
99 return Value(); | 100 return Value(); |
100 } | 101 } |
101 | 102 |
102 } // namespace functions | 103 } // namespace functions |
OLD | NEW |