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

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

Issue 429423002: Refactor GN source expansions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « tools/gn/filesystem_utils.h ('k') | tools/gn/filesystem_utils_unittest.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 "tools/gn/filesystem_utils.h" 5 #include "tools/gn/filesystem_utils.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "tools/gn/file_template.h"
15 #include "tools/gn/location.h" 14 #include "tools/gn/location.h"
16 #include "tools/gn/settings.h" 15 #include "tools/gn/settings.h"
17 #include "tools/gn/source_dir.h" 16 #include "tools/gn/source_dir.h"
18 17
19 namespace { 18 namespace {
20 19
21 enum DotDisposition { 20 enum DotDisposition {
22 // The given dot is just part of a filename and is not special. 21 // The given dot is just part of a filename and is not special.
23 NOT_A_DIRECTORY, 22 NOT_A_DIRECTORY,
24 23
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 for (; cur >= 0; cur--) { 327 for (; cur >= 0; cur--) {
329 if (dir_string[cur] == '/') 328 if (dir_string[cur] == '/')
330 return base::StringPiece(&dir_string[cur + 1], end - cur - 1); 329 return base::StringPiece(&dir_string[cur + 1], end - cur - 1);
331 } 330 }
332 return base::StringPiece(&dir_string[0], end); 331 return base::StringPiece(&dir_string[0], end);
333 } 332 }
334 333
335 bool EnsureStringIsInOutputDir(const SourceDir& dir, 334 bool EnsureStringIsInOutputDir(const SourceDir& dir,
336 const std::string& str, 335 const std::string& str,
337 const Value& originating, 336 const Value& originating,
338 bool allow_templates,
339 Err* err) { 337 Err* err) {
340 // This check will be wrong for all proper prefixes "e.g. "/output" will 338 // This check will be wrong for all proper prefixes "e.g. "/output" will
341 // match "/out" but we don't really care since this is just a sanity check. 339 // match "/out" but we don't really care since this is just a sanity check.
342 const std::string& dir_str = dir.value(); 340 const std::string& dir_str = dir.value();
343 if (str.compare(0, dir_str.length(), dir_str) == 0) 341 if (str.compare(0, dir_str.length(), dir_str) == 0)
344 return true; // Output directory is hardcoded. 342 return true; // Output directory is hardcoded.
345 343
346 if (allow_templates) {
347 // Allow the string to begin with any source expansion inside the output
348 // directory.
349 if (StartsWithASCII(str, FileTemplate::kSourceGenDir, true) ||
350 StartsWithASCII(str, FileTemplate::kSourceOutDir, true))
351 return true;
352 }
353
354 *err = Err(originating, "File is not inside output directory.", 344 *err = Err(originating, "File is not inside output directory.",
355 "The given file should be in the output directory. Normally you would " 345 "The given file should be in the output directory. Normally you would "
356 "specify\n\"$target_out_dir/foo\" or " 346 "specify\n\"$target_out_dir/foo\" or "
357 "\"$target_gen_dir/foo\". I interpreted this as\n\"" 347 "\"$target_gen_dir/foo\". I interpreted this as\n\""
358 + str + "\"."); 348 + str + "\".");
359 return false; 349 return false;
360 } 350 }
361 351
362 bool IsPathAbsolute(const base::StringPiece& path) { 352 bool IsPathAbsolute(const base::StringPiece& path) {
363 if (path.empty()) 353 if (path.empty())
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 return GetGenDirForSourceDir(target->settings(), target->label().dir()); 752 return GetGenDirForSourceDir(target->settings(), target->label().dir());
763 } 753 }
764 754
765 SourceDir GetCurrentOutputDir(const Scope* scope) { 755 SourceDir GetCurrentOutputDir(const Scope* scope) {
766 return GetOutputDirForSourceDir(scope->settings(), scope->GetSourceDir()); 756 return GetOutputDirForSourceDir(scope->settings(), scope->GetSourceDir());
767 } 757 }
768 758
769 SourceDir GetCurrentGenDir(const Scope* scope) { 759 SourceDir GetCurrentGenDir(const Scope* scope) {
770 return GetGenDirForSourceDir(scope->settings(), scope->GetSourceDir()); 760 return GetGenDirForSourceDir(scope->settings(), scope->GetSourceDir());
771 } 761 }
OLDNEW
« no previous file with comments | « tools/gn/filesystem_utils.h ('k') | tools/gn/filesystem_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698