| 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" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "tools/gn/err.h" | 13 #include "tools/gn/err.h" |
| 14 #include "tools/gn/filesystem_utils.h" | 14 #include "tools/gn/filesystem_utils.h" |
| 15 #include "tools/gn/functions.h" | 15 #include "tools/gn/functions.h" |
| 16 #include "tools/gn/input_file.h" | 16 #include "tools/gn/input_file.h" |
| 17 #include "tools/gn/parse_tree.h" | 17 #include "tools/gn/parse_tree.h" |
| 18 #include "tools/gn/scheduler.h" | 18 #include "tools/gn/scheduler.h" |
| 19 | 19 |
| 20 namespace functions { | 20 namespace functions { |
| 21 | 21 |
| 22 const char kWriteFile[] = "write_file"; | 22 const char kWriteFile[] = "write_file"; |
| 23 const char kWriteFile_HelpShort[] = | 23 const char kWriteFile_HelpShort[] = |
| 24 "write_file: Write a file to disk."; | 24 "write_file: Write a file to disk."; |
| 25 const char kWriteFile_Help[] = | 25 const char kWriteFile_Help[] = |
| 26 "write_file: Write a file to disk.\n" | 26 R"(write_file: Write a file to disk. |
| 27 "\n" | 27 |
| 28 " write_file(filename, data)\n" | 28 write_file(filename, data) |
| 29 "\n" | 29 |
| 30 " If data is a list, the list will be written one-item-per-line with no\n" | 30 If data is a list, the list will be written one-item-per-line with no quoting |
| 31 " quoting or brackets.\n" | 31 or brackets. |
| 32 "\n" | 32 |
| 33 " If the file exists and the contents are identical to that being\n" | 33 If the file exists and the contents are identical to that being written, the |
| 34 " written, the file will not be updated. This will prevent unnecessary\n" | 34 file will not be updated. This will prevent unnecessary rebuilds of targets |
| 35 " rebuilds of targets that depend on this file.\n" | 35 that depend on this file. |
| 36 "\n" | 36 |
| 37 " One use for write_file is to write a list of inputs to an script\n" | 37 One use for write_file is to write a list of inputs to an script that might |
| 38 " that might be too long for the command line. However, it is\n" | 38 be too long for the command line. However, it is preferrable to use response |
| 39 " preferrable to use response files for this purpose. See\n" | 39 files for this purpose. See "gn help response_file_contents". |
| 40 " \"gn help response_file_contents\".\n" | 40 |
| 41 "\n" | 41 TODO(brettw) we probably need an optional third argument to control list |
| 42 " TODO(brettw) we probably need an optional third argument to control\n" | 42 formatting. |
| 43 " list formatting.\n" | 43 |
| 44 "\n" | 44 Arguments |
| 45 "Arguments\n" | 45 |
| 46 "\n" | 46 filename |
| 47 " filename\n" | 47 Filename to write. This must be within the output directory. |
| 48 " Filename to write. This must be within the output directory.\n" | 48 |
| 49 "\n" | 49 data |
| 50 " data:\n" | 50 The list or string to write. |
| 51 " The list or string to write.\n"; | 51 )"; |
| 52 | 52 |
| 53 Value RunWriteFile(Scope* scope, | 53 Value RunWriteFile(Scope* scope, |
| 54 const FunctionCallNode* function, | 54 const FunctionCallNode* function, |
| 55 const std::vector<Value>& args, | 55 const std::vector<Value>& args, |
| 56 Err* err) { | 56 Err* err) { |
| 57 if (args.size() != 2) { | 57 if (args.size() != 2) { |
| 58 *err = Err(function->function(), "Wrong number of arguments to write_file", | 58 *err = Err(function->function(), "Wrong number of arguments to write_file", |
| 59 "I expected two arguments."); | 59 "I expected two arguments."); |
| 60 return Value(); | 60 return Value(); |
| 61 } | 61 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 scope->settings()->build_settings()->GetFullPath(source_file); | 94 scope->settings()->build_settings()->GetFullPath(source_file); |
| 95 | 95 |
| 96 // Make sure we're not replacing the same contents. | 96 // Make sure we're not replacing the same contents. |
| 97 if (!WriteFileIfChanged(file_path, contents.str(), err)) | 97 if (!WriteFileIfChanged(file_path, contents.str(), err)) |
| 98 *err = Err(function->function(), err->message(), err->help_text()); | 98 *err = Err(function->function(), err->message(), err->help_text()); |
| 99 | 99 |
| 100 return Value(); | 100 return Value(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 } // namespace functions | 103 } // namespace functions |
| OLD | NEW |