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

Unified Diff: tools/gn/filesystem_utils.cc

Issue 1256043006: Reference written files relatively when possible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: tools/gn/filesystem_utils.cc
diff --git a/tools/gn/filesystem_utils.cc b/tools/gn/filesystem_utils.cc
index 663e6ac3f0c188d708a366d3326eb273605d4130..1f8fe81d2cf2668c10a2de2155f50351a4c18c00 100644
--- a/tools/gn/filesystem_utils.cc
+++ b/tools/gn/filesystem_utils.cc
@@ -332,6 +332,32 @@ bool EnsureStringIsInOutputDir(const SourceDir& output_dir,
return false;
}
+base::FilePath::StringType ComputeStringInOutputDir(const SourceDir& output_dir,
+ const SourceFile& output_file,
+ Err* err) {
+ if (output_file.is_source_absolute() != output_dir.is_source_absolute()) {
+ *err = Err(nullptr,
+ "Cannot determine if output file is in output directory",
+ "Absolute files/dirs are incomparable with source rooted ones.");
+ return base::FilePath::StringType();
+ }
+
+ const std::string& dir_str = output_dir.value();
+ const std::string& str = output_file.value();
+ if (str.compare(0, dir_str.length(), dir_str) != 0 ||
+ str.length() <= dir_str.length() ||
+ IsSlash(str[dir_str.length()])) {
+ *err = Err(nullptr, "File is not inside output directory.",
+ "The given file should be in the output directory. Normally you would "
+ "specify\n\"$target_out_dir/foo\" or "
+ "\"$target_gen_dir/foo\". I interpreted this as\n\""
+ + str + "\".");
+ return base::FilePath::StringType();
+ }
+ return base::FilePath::StringType(str.c_str() + dir_str.length(),
+ str.length() - dir_str.length());
+}
+
bool IsPathAbsolute(const base::StringPiece& path) {
if (path.empty())
return false;

Powered by Google App Engine
This is Rietveld 408576698