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

Unified Diff: tools/gn/filesystem_utils.cc

Issue 80463004: GN generator for GYP actions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/filesystem_utils.h ('k') | tools/gn/filesystem_utils_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/filesystem_utils.cc
diff --git a/tools/gn/filesystem_utils.cc b/tools/gn/filesystem_utils.cc
index ee7c5d566cf8d02941e3b0602e53c260f002b668..5d9b5f1329a36f4af322486643b33f1cfc3c2938 100644
--- a/tools/gn/filesystem_utils.cc
+++ b/tools/gn/filesystem_utils.cc
@@ -11,6 +11,7 @@
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "tools/gn/location.h"
+#include "tools/gn/settings.h"
#include "tools/gn/source_dir.h"
namespace {
@@ -546,3 +547,87 @@ std::string RebaseSourceAbsolutePath(const std::string& input,
return ret;
}
+
+std::string DirectoryWithNoLastSlash(const SourceDir& dir) {
+ std::string ret;
+
+ if (dir.value().empty()) {
+ // Just keep input the same.
+ } else if (dir.value() == "/") {
+ ret.assign("/.");
+ } else if (dir.value() == "//") {
+ ret.assign("//.");
+ } else {
+ ret.assign(dir.value());
+ ret.resize(ret.size() - 1);
+ }
+ return ret;
+}
+
+SourceDir GetToolchainOutputDir(const Settings* settings) {
+ const OutputFile& toolchain_subdir = settings->toolchain_output_subdir();
+
+ std::string result = settings->build_settings()->build_dir().value();
+ if (!toolchain_subdir.value().empty())
+ result.append(toolchain_subdir.value());
+
+ return SourceDir(SourceDir::SWAP_IN, &result);
+}
+
+SourceDir GetToolchainGenDir(const Settings* settings) {
+ const OutputFile& toolchain_subdir = settings->toolchain_output_subdir();
+
+ std::string result = settings->build_settings()->build_dir().value();
+ if (!toolchain_subdir.value().empty())
+ result.append(toolchain_subdir.value());
+
+ result.append("gen/");
+ return SourceDir(SourceDir::SWAP_IN, &result);
+}
+
+SourceDir GetOutputDirForSourceDir(const Settings* settings,
+ const SourceDir& source_dir) {
+ SourceDir toolchain = GetToolchainOutputDir(settings);
+
+ std::string ret;
+ toolchain.SwapValue(&ret);
+ ret.append("obj/");
+
+ // The source dir should be source-absolute, so we trim off the two leading
+ // slashes to append to the toolchain object directory.
+ DCHECK(source_dir.is_source_absolute());
+ ret.append(&source_dir.value()[2], source_dir.value().size() - 2);
+
+ return SourceDir(SourceDir::SWAP_IN, &ret);
+}
+
+SourceDir GetGenDirForSourceDir(const Settings* settings,
+ const SourceDir& source_dir) {
+ SourceDir toolchain = GetToolchainGenDir(settings);
+
+ std::string ret;
+ toolchain.SwapValue(&ret);
+
+ // The source dir should be source-absolute, so we trim off the two leading
+ // slashes to append to the toolchain object directory.
+ DCHECK(source_dir.is_source_absolute());
+ ret.append(&source_dir.value()[2], source_dir.value().size() - 2);
+
+ return SourceDir(SourceDir::SWAP_IN, &ret);
+}
+
+SourceDir GetTargetOutputDir(const Target* target) {
+ return GetOutputDirForSourceDir(target->settings(), target->label().dir());
+}
+
+SourceDir GetTargetGenDir(const Target* target) {
+ return GetGenDirForSourceDir(target->settings(), target->label().dir());
+}
+
+SourceDir GetCurrentOutputDir(const Scope* scope) {
+ return GetOutputDirForSourceDir(scope->settings(), scope->GetSourceDir());
+}
+
+SourceDir GetCurrentGenDir(const Scope* scope) {
+ return GetGenDirForSourceDir(scope->settings(), scope->GetSourceDir());
+}
« 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