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

Side by Side Diff: tools/gn/function_get_path_info.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_exec_script.cc ('k') | tools/gn/function_read_file.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "tools/gn/err.h" 5 #include "tools/gn/err.h"
6 #include "tools/gn/filesystem_utils.h" 6 #include "tools/gn/filesystem_utils.h"
7 #include "tools/gn/functions.h" 7 #include "tools/gn/functions.h"
8 #include "tools/gn/parse_tree.h" 8 #include "tools/gn/parse_tree.h"
9 #include "tools/gn/scope.h" 9 #include "tools/gn/scope.h"
10 #include "tools/gn/value.h" 10 #include "tools/gn/value.h"
(...skipping 10 matching lines...) Expand all
21 WHAT_DIR, 21 WHAT_DIR,
22 WHAT_ABSPATH, 22 WHAT_ABSPATH,
23 WHAT_GEN_DIR, 23 WHAT_GEN_DIR,
24 WHAT_OUT_DIR, 24 WHAT_OUT_DIR,
25 }; 25 };
26 26
27 // Returns the directory containing the input (resolving it against the 27 // Returns the directory containing the input (resolving it against the
28 // |current_dir|), regardless of whether the input is a directory or a file. 28 // |current_dir|), regardless of whether the input is a directory or a file.
29 SourceDir DirForInput(const Settings* settings, 29 SourceDir DirForInput(const Settings* settings,
30 const SourceDir& current_dir, 30 const SourceDir& current_dir,
31 const std::string& input_string) { 31 const Value& input,
32 Err* err) {
33 // Input should already have been validated as a string.
34 const std::string& input_string = input.string_value();
35
32 if (!input_string.empty() && input_string[input_string.size() - 1] == '/') { 36 if (!input_string.empty() && input_string[input_string.size() - 1] == '/') {
33 // Input is a directory. 37 // Input is a directory.
34 return current_dir.ResolveRelativeDir(input_string, 38 return current_dir.ResolveRelativeDir(input, err,
35 settings->build_settings()->root_path_utf8()); 39 settings->build_settings()->root_path_utf8());
36 } 40 }
37 41
38 // Input is a directory. 42 // Input is a directory.
39 return current_dir.ResolveRelativeFile(input_string, 43 return current_dir.ResolveRelativeFile(input, err,
40 settings->build_settings()->root_path_utf8()).GetDir(); 44 settings->build_settings()->root_path_utf8()).GetDir();
41 } 45 }
42 46
43 std::string GetOnePathInfo(const Settings* settings, 47 std::string GetOnePathInfo(const Settings* settings,
44 const SourceDir& current_dir, 48 const SourceDir& current_dir,
45 What what, 49 What what,
46 const Value& input, 50 const Value& input,
47 Err* err) { 51 Err* err) {
48 if (!input.VerifyTypeIs(Value::STRING, err)) 52 if (!input.VerifyTypeIs(Value::STRING, err))
49 return std::string(); 53 return std::string();
(...skipping 28 matching lines...) Expand all
78 if (dir_incl_slash == "/") 82 if (dir_incl_slash == "/")
79 return std::string("/."); 83 return std::string("/.");
80 if (dir_incl_slash == "//") 84 if (dir_incl_slash == "//")
81 return std::string("//."); 85 return std::string("//.");
82 return dir_incl_slash.substr(0, dir_incl_slash.size() - 1).as_string(); 86 return dir_incl_slash.substr(0, dir_incl_slash.size() - 1).as_string();
83 } 87 }
84 case WHAT_GEN_DIR: { 88 case WHAT_GEN_DIR: {
85 return DirectoryWithNoLastSlash( 89 return DirectoryWithNoLastSlash(
86 GetGenDirForSourceDir(settings, 90 GetGenDirForSourceDir(settings,
87 DirForInput(settings, current_dir, 91 DirForInput(settings, current_dir,
88 input_string))); 92 input, err)));
89 } 93 }
90 case WHAT_OUT_DIR: { 94 case WHAT_OUT_DIR: {
91 return DirectoryWithNoLastSlash( 95 return DirectoryWithNoLastSlash(
92 GetOutputDirForSourceDir(settings, 96 GetOutputDirForSourceDir(settings,
93 DirForInput(settings, current_dir, 97 DirForInput(settings, current_dir,
94 input_string))); 98 input, err)));
95 } 99 }
96 case WHAT_ABSPATH: { 100 case WHAT_ABSPATH: {
97 if (!input_string.empty() && 101 if (!input_string.empty() &&
98 input_string[input_string.size() - 1] == '/') { 102 input_string[input_string.size() - 1] == '/') {
99 return current_dir.ResolveRelativeDir(input_string, 103 return current_dir.ResolveRelativeDir(input, err,
100 settings->build_settings()->root_path_utf8()).value(); 104 settings->build_settings()->root_path_utf8()).value();
101 } else { 105 } else {
102 return current_dir.ResolveRelativeFile(input_string, 106 return current_dir.ResolveRelativeFile(input, err,
103 settings->build_settings()->root_path_utf8()).value(); 107 settings->build_settings()->root_path_utf8()).value();
104 } 108 }
105 } 109 }
106 default: 110 default:
107 NOTREACHED(); 111 NOTREACHED();
108 return std::string(); 112 return std::string();
109 } 113 }
110 } 114 }
111 115
112 } // namespace 116 } // namespace
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 return Value(); 242 return Value();
239 } 243 }
240 return result; 244 return result;
241 } 245 }
242 246
243 *err = Err(args[0], "Path must be a string or a list of strings."); 247 *err = Err(args[0], "Path must be a string or a list of strings.");
244 return Value(); 248 return Value();
245 } 249 }
246 250
247 } // namespace functions 251 } // namespace functions
OLDNEW
« no previous file with comments | « tools/gn/function_exec_script.cc ('k') | tools/gn/function_read_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698