summaryrefslogtreecommitdiffstats
path: root/tools/gn
diff options
context:
space:
mode:
authorhashimoto <hashimoto@chromium.org>2016-02-23 17:23:58 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-24 01:26:21 +0000
commitf1c6101de0ecd583fd47fdc69a2a241367e49b7b (patch)
tree270d3fb9a43927c1cec10a7266c7b84c4bed4eac /tools/gn
parent5ec751cddd0f8145f06ec16c673a4a058c171414 (diff)
downloadchromium_src-f1c6101de0ecd583fd47fdc69a2a241367e49b7b.zip
chromium_src-f1c6101de0ecd583fd47fdc69a2a241367e49b7b.tar.gz
chromium_src-f1c6101de0ecd583fd47fdc69a2a241367e49b7b.tar.bz2
GN: Normalize the build directory path
BUG=586906 TEST=ln -s /tmp out_tmp && out/gn/gn gen //out_tmp/Release Review URL: https://codereview.chromium.org/1723913003 Cr-Commit-Position: refs/heads/master@{#377175}
Diffstat (limited to 'tools/gn')
-rw-r--r--tools/gn/setup.cc44
1 files changed, 41 insertions, 3 deletions
diff --git a/tools/gn/setup.cc b/tools/gn/setup.cc
index 79814e6..9661506 100644
--- a/tools/gn/setup.cc
+++ b/tools/gn/setup.cc
@@ -226,6 +226,21 @@ base::FilePath FindWindowsPython() {
}
#endif
+// Expands all ./, ../, and symbolic links in the given path.
+bool GetRealPath(const base::FilePath& path, base::FilePath* out) {
+#if defined(OS_POSIX)
+ char buf[PATH_MAX];
+ if (!realpath(path.value().c_str(), buf)) {
+ return false;
+ }
+ *out = base::FilePath(buf);
+#else
+ // Do nothing on a non-POSIX system.
+ *out = path;
+#endif
+ return true;
+}
+
} // namespace
const char Setup::kBuildArgFileName[] = "args.gn";
@@ -513,9 +528,16 @@ bool Setup::FillSourceDir(const base::CommandLine& cmdline) {
root_path = dotfile_name_.DirName();
}
+ base::FilePath root_realpath;
+ if (!GetRealPath(root_path, &root_realpath)) {
+ Err(Location(), "Can't get the real root path.",
+ "I could not get the real path of \"" + FilePathToUTF8(root_path) +
+ "\".").PrintToStdout();
+ return false;
+ }
if (scheduler_.verbose_logging())
- scheduler_.Log("Using source root", FilePathToUTF8(root_path));
- build_settings_.SetRootPath(root_path);
+ scheduler_.Log("Using source root", FilePathToUTF8(root_realpath));
+ build_settings_.SetRootPath(root_realpath);
return true;
}
@@ -531,11 +553,27 @@ bool Setup::FillBuildDir(const std::string& build_dir, bool require_exists) {
return false;
}
+ base::FilePath build_dir_path = build_settings_.GetFullPath(resolved);
+ if (!base::CreateDirectory(build_dir_path)) {
+ Err(Location(), "Can't create the build dir.",
+ "I could not create the build dir \"" + FilePathToUTF8(build_dir_path) +
+ "\".").PrintToStdout();
+ return false;
+ }
+ base::FilePath build_dir_realpath;
+ if (!GetRealPath(build_dir_path, &build_dir_realpath)) {
+ Err(Location(), "Can't get the real build dir path.",
+ "I could not get the real path of \"" + FilePathToUTF8(build_dir_path) +
+ "\".").PrintToStdout();
+ return false;
+ }
+ resolved = SourceDirForPath(build_settings_.root_path(),
+ build_dir_realpath);
+
if (scheduler_.verbose_logging())
scheduler_.Log("Using build dir", resolved.value());
if (require_exists) {
- base::FilePath build_dir_path = build_settings_.GetFullPath(resolved);
if (!base::PathExists(build_dir_path.Append(
FILE_PATH_LITERAL("build.ninja")))) {
Err(Location(), "Not a build directory.",