Skip to content

Commit

Permalink
Correct gn path rebasing for object files located inside build direct…
Browse files Browse the repository at this point in the history
…ory.

BUG=none

Review URL: https://codereview.chromium.org/262143003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268372 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
ajwong@chromium.org committed May 6, 2014
1 parent e2da1f3 commit a09aa4a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
15 changes: 15 additions & 0 deletions tools/gn/ninja_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "tools/gn/ninja_helper.h"

#include "base/logging.h"
#include "base/strings/string_util.h"
#include "tools/gn/filesystem_utils.h"
#include "tools/gn/string_utils.h"
#include "tools/gn/target.h"
Expand Down Expand Up @@ -93,6 +94,20 @@ OutputFile NinjaHelper::GetOutputFileForSource(
if (source.is_system_absolute())
return OutputFile(source.value());

// Files that are already inside the build dir should not be made
// relative to the source tree. Doing so will insert an unnecessary
// "../.." into the path which won't match the corresponding target
// name in ninja.
CHECK(build_settings_->build_dir().is_source_absolute());
CHECK(source.is_source_absolute());
if (StartsWithASCII(source.value(),
build_settings_->build_dir().value(),
true)) {
return OutputFile(
source.value().substr(
build_settings_->build_dir().value().size()));
}

// Construct the relative location of the file from the build dir.
OutputFile ret(build_to_src_no_last_slash());
source.SourceAbsoluteWithOneSlash().AppendToString(&ret.value());
Expand Down
28 changes: 27 additions & 1 deletion tools/gn/ninja_helper_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class HelperSetterUpper {
settings.set_target_os(Settings::WIN);

// Output going to "out/Debug".
build_settings.SetBuildDir(SourceDir("/out/Debug/"));
build_settings.SetBuildDir(SourceDir("//out/Debug/"));

// Our source target is in "tools/gn".
target.set_output_type(Target::EXECUTABLE);
Expand Down Expand Up @@ -58,6 +58,32 @@ TEST(NinjaHelper, GetOutputFileForSource) {
SOURCE_CC).value());
}

TEST(NinjaHelper, GetOutputFileForObject) {
HelperSetterUpper setup;
NinjaHelper helper(&setup.build_settings);

EXPECT_EQ(OutputFile("../../tools/gn/foo.o").value(),
helper.GetOutputFileForSource(&setup.target,
SourceFile("//tools/gn/foo.o"),
SOURCE_O).value());

EXPECT_EQ(OutputFile("../../tools/gn/foo.obj").value(),
helper.GetOutputFileForSource(&setup.target,
SourceFile("//tools/gn/foo.obj"),
SOURCE_O).value());

EXPECT_EQ(OutputFile("nested/foo.o").value(),
helper.GetOutputFileForSource(
&setup.target,
SourceFile("//out/Debug/nested/foo.o"),
SOURCE_O).value());

EXPECT_EQ(OutputFile("/abs/rooted/foo.o").value(),
helper.GetOutputFileForSource(&setup.target,
SourceFile("/abs/rooted/foo.o"),
SOURCE_O).value());
}

TEST(NinjaHelper, GetTargetOutputFile) {
HelperSetterUpper setup;
NinjaHelper helper(&setup.build_settings);
Expand Down

0 comments on commit a09aa4a

Please sign in to comment.