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 630223002: gn: Support build directories outside the source tree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated patch set Created 6 years, 1 month 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
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"
11 11
12 namespace functions { 12 namespace functions {
13 13
14 namespace { 14 namespace {
15 15
16 // Corresponds to the various values of "what" in the function call. 16 // Corresponds to the various values of "what" in the function call.
17 enum What { 17 enum What {
18 WHAT_FILE, 18 WHAT_FILE,
19 WHAT_NAME, 19 WHAT_NAME,
20 WHAT_EXTENSION, 20 WHAT_EXTENSION,
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 SourceDir& current_dir, 29 SourceDir DirForInput(const Settings* settings,
30 const SourceDir& current_dir,
30 const std::string& input_string) { 31 const std::string& input_string) {
31 if (!input_string.empty() && input_string[input_string.size() - 1] == '/') { 32 if (!input_string.empty() && input_string[input_string.size() - 1] == '/') {
32 // Input is a directory. 33 // Input is a directory.
33 return current_dir.ResolveRelativeDir(input_string); 34 return current_dir.ResolveRelativeDir(input_string,
35 settings->build_settings()->root_path_utf8());
34 } 36 }
35 37
36 // Input is a directory. 38 // Input is a directory.
37 return current_dir.ResolveRelativeFile(input_string).GetDir(); 39 return current_dir.ResolveRelativeFile(input_string,
40 settings->build_settings()->root_path_utf8()).GetDir();
38 } 41 }
39 42
40 std::string GetOnePathInfo(const Settings* settings, 43 std::string GetOnePathInfo(const Settings* settings,
41 const SourceDir& current_dir, 44 const SourceDir& current_dir,
42 What what, 45 What what,
43 const Value& input, 46 const Value& input,
44 Err* err) { 47 Err* err) {
45 if (!input.VerifyTypeIs(Value::STRING, err)) 48 if (!input.VerifyTypeIs(Value::STRING, err))
46 return std::string(); 49 return std::string();
47 const std::string& input_string = input.string_value(); 50 const std::string& input_string = input.string_value();
(...skipping 26 matching lines...) Expand all
74 // slashes can't be trimmed. 77 // slashes can't be trimmed.
75 if (dir_incl_slash == "/") 78 if (dir_incl_slash == "/")
76 return std::string("/."); 79 return std::string("/.");
77 if (dir_incl_slash == "//") 80 if (dir_incl_slash == "//")
78 return std::string("//."); 81 return std::string("//.");
79 return dir_incl_slash.substr(0, dir_incl_slash.size() - 1).as_string(); 82 return dir_incl_slash.substr(0, dir_incl_slash.size() - 1).as_string();
80 } 83 }
81 case WHAT_GEN_DIR: { 84 case WHAT_GEN_DIR: {
82 return DirectoryWithNoLastSlash( 85 return DirectoryWithNoLastSlash(
83 GetGenDirForSourceDir(settings, 86 GetGenDirForSourceDir(settings,
84 DirForInput(current_dir, input_string))); 87 DirForInput(settings, current_dir,
88 input_string)));
85 } 89 }
86 case WHAT_OUT_DIR: { 90 case WHAT_OUT_DIR: {
87 return DirectoryWithNoLastSlash( 91 return DirectoryWithNoLastSlash(
88 GetOutputDirForSourceDir(settings, 92 GetOutputDirForSourceDir(settings,
89 DirForInput(current_dir, input_string))); 93 DirForInput(settings, current_dir,
94 input_string)));
90 } 95 }
91 case WHAT_ABSPATH: { 96 case WHAT_ABSPATH: {
92 if (!input_string.empty() && input_string[input_string.size() - 1] == '/') 97 if (!input_string.empty() &&
93 return current_dir.ResolveRelativeDir(input_string).value(); 98 input_string[input_string.size() - 1] == '/') {
94 else 99 return current_dir.ResolveRelativeDir(input_string,
95 return current_dir.ResolveRelativeFile(input_string).value(); 100 settings->build_settings()->root_path_utf8()).value();
101 } else {
102 return current_dir.ResolveRelativeFile(input_string,
103 settings->build_settings()->root_path_utf8()).value();
104 }
96 } 105 }
97 default: 106 default:
98 NOTREACHED(); 107 NOTREACHED();
99 return std::string(); 108 return std::string();
100 } 109 }
101 } 110 }
102 111
103 } // namespace 112 } // namespace
104 113
105 const char kGetPathInfo[] = "get_path_info"; 114 const char kGetPathInfo[] = "get_path_info";
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 return Value(); 238 return Value();
230 } 239 }
231 return result; 240 return result;
232 } 241 }
233 242
234 *err = Err(args[0], "Path must be a string or a list of strings."); 243 *err = Err(args[0], "Path must be a string or a list of strings.");
235 return Value(); 244 return Value();
236 } 245 }
237 246
238 } // namespace functions 247 } // namespace functions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698