| 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());
|
| +}
|
|
|