| 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/file_util.h" | 8 #include "base/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 24 matching lines...) Expand all Loading... |
| 35 " Filename to write. This must be within the output directory.\n" | 35 " Filename to write. This must be within the output directory.\n" |
| 36 "\n" | 36 "\n" |
| 37 " data:\n" | 37 " data:\n" |
| 38 " The list or string to write.\n"; | 38 " The list or string to write.\n"; |
| 39 | 39 |
| 40 Value RunWriteFile(Scope* scope, | 40 Value RunWriteFile(Scope* scope, |
| 41 const FunctionCallNode* function, | 41 const FunctionCallNode* function, |
| 42 const std::vector<Value>& args, | 42 const std::vector<Value>& args, |
| 43 Err* err) { | 43 Err* err) { |
| 44 if (args.size() != 2) { | 44 if (args.size() != 2) { |
| 45 *err = Err(function->function(), "Wrong number of args to write_file", | 45 *err = Err(function->function(), "Wrong number of arguments to write_file", |
| 46 "I expected two arguments."); | 46 "I expected two arguments."); |
| 47 return Value(); | 47 return Value(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 // Compute the file name and make sure it's in the output dir. | 50 // Compute the file name and make sure it's in the output dir. |
| 51 if (!args[0].VerifyTypeIs(Value::STRING, err)) | 51 if (!args[0].VerifyTypeIs(Value::STRING, err)) |
| 52 return Value(); | 52 return Value(); |
| 53 const SourceDir& cur_dir = scope->GetSourceDir(); | 53 const SourceDir& cur_dir = scope->GetSourceDir(); |
| 54 SourceFile source_file = cur_dir.ResolveRelativeFile(args[0].string_value()); | 54 SourceFile source_file = cur_dir.ResolveRelativeFile(args[0].string_value()); |
| 55 if (!EnsureStringIsInOutputDir( | 55 if (!EnsureStringIsInOutputDir( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 80 if (file_util::WriteFile(file_path, contents_string.c_str(), int_size) | 80 if (file_util::WriteFile(file_path, contents_string.c_str(), int_size) |
| 81 != int_size) { | 81 != int_size) { |
| 82 *err = Err(function->function(), "Unable to write file.", | 82 *err = Err(function->function(), "Unable to write file.", |
| 83 "I was writing \"" + FilePathToUTF8(file_path) + "\"."); | 83 "I was writing \"" + FilePathToUTF8(file_path) + "\"."); |
| 84 return Value(); | 84 return Value(); |
| 85 } | 85 } |
| 86 return Value(); | 86 return Value(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 } // namespace functions | 89 } // namespace functions |
| OLD | NEW |