Commit 8d94c765 authored by brettw@chromium.org's avatar brettw@chromium.org

Hook up symbol files to the Windows GN build.

Previously the GN Windows build specified the symbol file $pdbfile but this variable was never defined, so the command like would just say "/Fd" and the default one would be used.

This patch defines some per-target variables in the ninja file for the toolchain to use. The Windows toolchain uses these to construct C- and C++-specific pdb files (the MS tools can't share between these two) for the current target.

BUG=
R=scottmg@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284137 0039d316-1c4b-4281-b951-d872f2087c98
parent 6dbfee52
......@@ -22,6 +22,11 @@ exec_script("setup_toolchain.py",
stamp_command = "$python_path gyp-win-tool stamp \$out"
copy_command = "$python_path gyp-win-tool recursive-mirror \$in \$out"
# MSVC can't share PDB files between compilers compiling C and C++ files, so
# we construct different names for each type.
c_pdb_suffix = " /Fd\${target_out_dir}/\${target_name}_c.pdb"
cc_pdb_suffix = " /Fd\${target_out_dir}/\${target_name}_cc.pdb"
# 32-bit toolchain -------------------------------------------------------------
toolchain("32") {
......@@ -29,16 +34,16 @@ toolchain("32") {
lib_prefix = ""
lib_dir_prefix="/LIBPATH:"
cc_command = "ninja -t msvc -e environment.x86 -- cl.exe /nologo /showIncludes /FC @\$out.rsp /c \$in /Fo\$out /Fd\$pdbname"
cc_command = "ninja -t msvc -e environment.x86 -- cl.exe /nologo /showIncludes /FC @\$out.rsp /c \$in /Fo\$out"
tool("cc") {
command = cc_command
command = cc_command + c_pdb_suffix
description = "CC \$out"
rspfile = "\$out.rsp"
rspfile_content = "\$defines \$includes \$cflags \$cflags_c"
depsformat = "msvc"
}
tool("cxx") {
command = cc_command # Same as above
command = cc_command + cc_pdb_suffix
description = "CXX \$out"
rspfile = "\$out.rsp"
rspfile_content = "\$defines \$includes \$cflags \$cflags_cc"
......@@ -88,16 +93,16 @@ toolchain("64") {
lib_prefix = ""
lib_dir_prefix="/LIBPATH:"
cc_command = "ninja -t msvc -e environment.x64 -- cl.exe /nologo /showIncludes /FC @\$out.rsp /c \$in /Fo\$out /Fd\$pdbname"
cc_command = "ninja -t msvc -e environment.x64 -- cl.exe /nologo /showIncludes /FC @\$out.rsp /c \$in /Fo\$out"
tool("cc") {
command = cc_command
command = cc_command + c_pdb_suffix
description = "CC \$out"
rspfile = "\$out.rsp"
rspfile_content = "\$defines \$includes \$cflags \$cflags_c"
depsformat = "msvc"
}
tool("cxx") {
command = cc_command # Same as above
command = cc_command + cc_pdb_suffix
description = "CXX \$out"
rspfile = "\$out.rsp"
rspfile_content = "\$defines \$includes \$cflags \$cflags_cc"
......
......@@ -160,13 +160,14 @@ const char kTool_Help[] =
" given file type. See also \"gn help toolchain\".\n"
"\n"
"Command types:\n"
"\n"
" The following values may be passed to the tool() function for the type\n"
" of the command:\n"
"\n"
" \"cc\", \"cxx\", \"objc\", \"objcxx\", \"asm\", \"alink\", \"solink\",\n"
" \"link\", \"stamp\", \"copy\"\n"
"\n"
"Command flags:\n"
"Command flags\n"
"\n"
" These variables may be specified in the { } block after the tool call.\n"
" They are passed directly to Ninja. See the ninja documentation for how\n"
......@@ -188,7 +189,37 @@ const char kTool_Help[] =
" added to the link like with a \"-framework\" switch and the lib prefix\n"
" will be ignored.\n"
"\n"
"Example:\n"
"Ninja variables available to tool invocations\n"
"\n"
" When writing tool commands, you use the various built-in Ninja\n"
" variables like \"$in\" and \"$out\" (note that the $ must be escaped\n"
" for it to be passed to Ninja, so write \"\\$in\" in the command\n"
" string).\n"
"\n"
" GN defines the following variables for binary targets to access the\n"
" various computed information needed for compiling:\n"
"\n"
" - Compiler flags: \"cflags\", \"cflags_c\", \"cflags_cc\",\n"
" \"cflags_objc\", \"cflags_objcc\"\n"
"\n"
" - Linker flags: \"ldflags\", \"libs\"\n"
"\n"
" GN sets these other variables with target information that can be\n"
" used for computing names for supplimetary files:\n"
"\n"
" - \"target_name\": The name of the current target with no\n"
" path information. For example \"mylib\".\n"
"\n"
" - \"target_out_dir\": The value of \"target_out_dir\" from the BUILD\n"
" file for this target (see \"gn help target_out_dir\"), relative\n"
" to the root build directory with no trailing slash.\n"
"\n"
" - \"root_out_dir\": The value of \"root_out_dir\" from the BUILD\n"
" file for this target (see \"gn help root_out_dir\"), relative\n"
" to the root build directory with no trailing slash.\n"
"\n"
"Example\n"
"\n"
" toolchain(\"my_toolchain\") {\n"
" # Put these at the top to apply to all tools below.\n"
" lib_prefix = \"-l\"\n"
......
......@@ -125,7 +125,16 @@ void NinjaBinaryTargetWriter::WriteCompilerVars() {
#undef WRITE_FLAGS
// Write some variables about the target for the toolchain definition to use.
out_ << "target_name = " << target_->label().name() << std::endl;
out_ << "target_out_dir = ";
path_output_.WriteDir(out_, helper_.GetTargetOutputDir(target_),
PathOutput::DIR_NO_LAST_SLASH);
out_ << std::endl;
out_ << "root_out_dir = ";
path_output_.WriteDir(out_, target_->settings()->toolchain_output_subdir(),
PathOutput::DIR_NO_LAST_SLASH);
out_ << std::endl << std::endl;
}
void NinjaBinaryTargetWriter::WriteSources(
......
......@@ -75,6 +75,32 @@ void PathOutput::WriteFile(std::ostream& out, const OutputFile& file) const {
EscapeStringToStream(out, file.value(), options_);
}
void PathOutput::WriteDir(std::ostream& out,
const OutputFile& file,
DirSlashEnding slash_ending) const {
DCHECK(file.value().empty() ||
file.value()[file.value().size() - 1] == '/');
switch (slash_ending) {
case DIR_INCLUDE_LAST_SLASH:
EscapeStringToStream(out, file.value(), options_);
break;
case DIR_NO_LAST_SLASH:
if (!file.value().empty() &&
file.value()[file.value().size() - 1] == '/') {
// Trim trailing slash.
EscapeStringToStream(
out,
base::StringPiece(file.value().data(), file.value().size() - 1),
options_);
} else {
// Doesn't end with a slash, write the whole thing.
EscapeStringToStream(out, file.value(), options_);
}
break;
}
}
void PathOutput::WriteFile(std::ostream& out,
const base::FilePath& file) const {
// Assume native file paths are always absolute.
......
......@@ -49,10 +49,16 @@ class PathOutput {
void WriteFile(std::ostream& out, const SourceFile& file) const;
void WriteFile(std::ostream& out, const OutputFile& file) const;
void WriteFile(std::ostream& out, const base::FilePath& file) const;
// This variant assumes the dir ends in a trailing slash or is empty.
void WriteDir(std::ostream& out,
const SourceDir& dir,
DirSlashEnding slash_ending) const;
void WriteDir(std::ostream& out,
const OutputFile& file,
DirSlashEnding slash_ending) const;
// Backend for WriteFile and WriteDir. This appends the given file or
// directory string to the file.
void WritePathStr(std::ostream& out, const base::StringPiece& str) const;
......
......@@ -5,6 +5,7 @@
#include <sstream>
#include "testing/gtest/include/gtest/gtest.h"
#include "tools/gn/output_file.h"
#include "tools/gn/path_output.h"
#include "tools/gn/source_dir.h"
#include "tools/gn/source_file.h"
......@@ -213,8 +214,6 @@ TEST(PathOutput, WriteDir) {
// Output inside current dir.
{
std::ostringstream out;
writer.WriteDir(out, SourceDir("//out/Debug/"),
PathOutput::DIR_INCLUDE_LAST_SLASH);
EXPECT_EQ("./", out.str());
......@@ -237,6 +236,26 @@ TEST(PathOutput, WriteDir) {
PathOutput::DIR_NO_LAST_SLASH);
EXPECT_EQ("foo", out.str());
}
// WriteDir using an OutputFile.
{
std::ostringstream out;
writer.WriteDir(out, OutputFile("foo/"),
PathOutput::DIR_INCLUDE_LAST_SLASH);
EXPECT_EQ("foo/", out.str());
}
{
std::ostringstream out;
writer.WriteDir(out, OutputFile("foo/"),
PathOutput::DIR_NO_LAST_SLASH);
EXPECT_EQ("foo", out.str());
}
{
std::ostringstream out;
writer.WriteDir(out, OutputFile(),
PathOutput::DIR_INCLUDE_LAST_SLASH);
EXPECT_EQ("", out.str());
}
}
{
// Empty build dir writer.
......
......@@ -216,7 +216,7 @@ const char kTargetOutDir[] = "target_out_dir";
const char kTargetOutDir_HelpShort[] =
"target_out_dir: [string] Directory for target output files.";
const char kTargetOutDir_Help[] =
"target_out_dir: [string] Directory for target output files."
"target_out_dir: [string] Directory for target output files.\n"
"\n"
" Absolute path to the target's generated file directory. If your\n"
" current target is in \"//tools/doom_melon\" then this value might be\n"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment