Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: tools/gn/function_write_file.cc

Issue 1155713006: GN: Make file/dir resolving return errors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gn/function_rebase_path.cc ('k') | tools/gn/functions.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 const FunctionCallNode* function, 93 const FunctionCallNode* function,
94 const std::vector<Value>& args, 94 const std::vector<Value>& args,
95 Err* err) { 95 Err* err) {
96 if (args.size() != 2) { 96 if (args.size() != 2) {
97 *err = Err(function->function(), "Wrong number of arguments to write_file", 97 *err = Err(function->function(), "Wrong number of arguments to write_file",
98 "I expected two arguments."); 98 "I expected two arguments.");
99 return Value(); 99 return Value();
100 } 100 }
101 101
102 // Compute the file name and make sure it's in the output dir. 102 // Compute the file name and make sure it's in the output dir.
103 if (!args[0].VerifyTypeIs(Value::STRING, err)) 103 const SourceDir& cur_dir = scope->GetSourceDir();
104 SourceFile source_file = cur_dir.ResolveRelativeFile(args[0], err,
105 scope->settings()->build_settings()->root_path_utf8());
106 if (err->has_error())
104 return Value(); 107 return Value();
105 const SourceDir& cur_dir = scope->GetSourceDir();
106 SourceFile source_file = cur_dir.ResolveRelativeFile(args[0].string_value(),
107 scope->settings()->build_settings()->root_path_utf8());
108 if (!EnsureStringIsInOutputDir( 108 if (!EnsureStringIsInOutputDir(
109 scope->settings()->build_settings()->build_dir(), 109 scope->settings()->build_settings()->build_dir(),
110 source_file.value(), args[0].origin(), err)) 110 source_file.value(), args[0].origin(), err))
111 return Value(); 111 return Value();
112 112
113 // Compute output. 113 // Compute output.
114 std::ostringstream contents; 114 std::ostringstream contents;
115 if (args[1].type() == Value::LIST) { 115 if (args[1].type() == Value::LIST) {
116 const std::vector<Value>& list = args[1].list_value(); 116 const std::vector<Value>& list = args[1].list_value();
117 for (const auto& cur : list) 117 for (const auto& cur : list)
(...skipping 22 matching lines...) Expand all
140 if (DoWriteFile(file_path, new_contents.c_str(), int_size) 140 if (DoWriteFile(file_path, new_contents.c_str(), int_size)
141 != int_size) { 141 != int_size) {
142 *err = Err(function->function(), "Unable to write file.", 142 *err = Err(function->function(), "Unable to write file.",
143 "I was writing \"" + FilePathToUTF8(file_path) + "\"."); 143 "I was writing \"" + FilePathToUTF8(file_path) + "\".");
144 return Value(); 144 return Value();
145 } 145 }
146 return Value(); 146 return Value();
147 } 147 }
148 148
149 } // namespace functions 149 } // namespace functions
OLDNEW
« no previous file with comments | « tools/gn/function_rebase_path.cc ('k') | tools/gn/functions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698