summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorjsbell@chromium.org <jsbell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-02 00:12:02 +0000
committerjsbell@chromium.org <jsbell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-02 00:12:02 +0000
commit91dc790ab7c7d2f287c24947c7eaca2d0f6217ba (patch)
tree46d5ab19fcbf67317b607b079a7358799fb55a78 /tools
parentf635e0b4eb22336ede68f0a34b967bd4ef819512 (diff)
downloadchromium_src-91dc790ab7c7d2f287c24947c7eaca2d0f6217ba.zip
chromium_src-91dc790ab7c7d2f287c24947c7eaca2d0f6217ba.tar.gz
chromium_src-91dc790ab7c7d2f287c24947c7eaca2d0f6217ba.tar.bz2
Revert 267672 "Remove URL from base's DEPS"
Only base/DEPS file was part of the CL and should have changed. It looks like a manual commit brought in the rest, causing build failures. Reverting the whole thing for now. > Remove URL from base's DEPS > > +url is added at the root, and we don't want base to depend on it. Remove this rule explicitly in base to prevent regressions. > > R=viettrungluu@chromium.org > > Review URL: https://codereview.chromium.org/262773006 TBR=brettw@chromium.org Review URL: https://codereview.chromium.org/265893005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267687 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rw-r--r--tools/gn/BUILD.gn1
-rw-r--r--tools/gn/args.cc29
-rw-r--r--tools/gn/command_args.cc221
-rw-r--r--tools/gn/gn.gyp1
-rw-r--r--tools/gn/ninja_build_writer.cc23
-rw-r--r--tools/gn/setup.cc88
-rw-r--r--tools/gn/setup.h29
-rw-r--r--tools/gn/value.cc14
-rw-r--r--tools/gn/value.h3
-rw-r--r--tools/gn/value_unittest.cc28
10 files changed, 83 insertions, 354 deletions
diff --git a/tools/gn/BUILD.gn b/tools/gn/BUILD.gn
index 4657c57..0d2fdb5 100644
--- a/tools/gn/BUILD.gn
+++ b/tools/gn/BUILD.gn
@@ -203,7 +203,6 @@ test("gn_unittests") {
"test_with_scope.cc",
"test_with_scope.h",
"tokenizer_unittest.cc",
- "value_unittest.cc",
"visibility_unittest.cc",
]
deps = [
diff --git a/tools/gn/args.cc b/tools/gn/args.cc
index daa902ec..2c4891c 100644
--- a/tools/gn/args.cc
+++ b/tools/gn/args.cc
@@ -26,33 +26,20 @@ const char kBuildArgs_Help[] =
" - default_os\n"
" - os (by default this is the same as \"default_os\")\n"
"\n"
- " If specified, arguments from the --args command line flag are used. If\n"
- " that flag is not specified, args from previous builds in the build\n"
- " directory will be used (this is in the file gn.args in the build\n"
- " directory).\n"
+ " Second, arguments specified on the command-line via \"--args\" are\n"
+ " applied. These can override the system default ones, and add new ones.\n"
+ " These are whitespace-separated. For example:\n"
"\n"
- " Last, for targets being compiled with a non-default toolchain, the\n"
- " toolchain overrides are applied. These are specified in the\n"
+ " gn --args=\"enable_doom_melon=false\" os=\\\"beos\\\"\n"
+ "\n"
+ " Third, toolchain overrides are applied. These are specified in the\n"
" toolchain_args section of a toolchain definition. The use-case for\n"
" this is that a toolchain may be building code for a different\n"
" platform, and that it may want to always specify Posix, for example.\n"
" See \"gn help toolchain_args\" for more.\n"
"\n"
- " If you specify an override for a build argument that never appears in\n"
- " a \"declare_args\" call, a nonfatal error will be displayed.\n"
- "\n"
- "Examples\n"
- "\n"
- " gn args out/FooBar\n"
- " Create the directory out/FooBar and open an editor. You would type\n"
- " something like this into that file:\n"
- " enable_doom_melon=false\n"
- " os=\"android\"\n"
- "\n"
- " gn gen out/FooBar --args=\"enable_doom_melon=true os=\\\"android\\\"\"\n"
- " This will overwrite the build directory with the given arguments.\n"
- " (Note that the quotes inside the args command will usually need to\n"
- " be escaped for your shell to pass through strings values.)\n"
+ " It is an error to specify an override for a build argument that never\n"
+ " appears in a \"declare_args\" call.\n"
"\n"
"How build arguments are used\n"
"\n"
diff --git a/tools/gn/command_args.cc b/tools/gn/command_args.cc
index cbcab25..72a623f 100644
--- a/tools/gn/command_args.cc
+++ b/tools/gn/command_args.cc
@@ -4,9 +4,6 @@
#include <map>
-#include "base/command_line.h"
-#include "base/environment.h"
-#include "base/process/launch.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "tools/gn/commands.h"
@@ -16,19 +13,10 @@
#include "tools/gn/standard_out.h"
#include "tools/gn/tokenizer.h"
-#if defined(OS_WIN)
-#include <windows.h>
-#else
-#include <stdlib.h>
-#endif
-
namespace commands {
namespace {
-const char kSwitchList[] = "list";
-const char kSwitchShort[] = "short";
-
bool DoesLineBeginWithComment(const base::StringPiece& line) {
// Skip whitespace.
size_t i = 0;
@@ -107,50 +95,67 @@ void PrintArgHelp(const base::StringPiece& name, const Value& value) {
}
}
-int ListArgs(const std::string& build_dir) {
+} // namespace
+
+extern const char kArgs[] = "args";
+extern const char kArgs_HelpShort[] =
+ "args: Display configurable arguments declared by the build.";
+extern const char kArgs_Help[] =
+ "gn args [arg name]\n"
+ " Displays all arguments declared by buildfiles along with their\n"
+ " description. Build arguments are anything in a declare_args() block\n"
+ " in any buildfile. The comment preceding the declaration will be\n"
+ " displayed here (so comment well!).\n"
+ "\n"
+ " These arguments can be overridden on the command-line:\n"
+ " --args=\"doom_melon_setting=5 component_build=1\"\n"
+ " or in a toolchain definition (see \"gn help buildargs\" for more on\n"
+ " how this all works).\n"
+ "\n"
+ " If \"arg name\" is specified, only the information for that argument\n"
+ " will be displayed. Otherwise all arguments will be displayed.\n";
+
+int RunArgs(const std::vector<std::string>& args) {
Setup* setup = new Setup;
setup->set_check_for_bad_items(false);
- if (!setup->DoSetup(build_dir) || !setup->Run())
+ // TODO(brettw) bug 343726: Use a temporary directory instead of this
+ // default one to avoid messing up any build that's in there.
+ if (!setup->DoSetup("//out/Default/") || !setup->Run())
return 1;
Scope::KeyValueMap build_args;
setup->build_settings().build_args().MergeDeclaredArguments(&build_args);
- // Find all of the arguments we care about. Use a regular map so they're
- // sorted nicely when we write them out.
- std::map<base::StringPiece, Value> sorted_args;
- std::string list_value =
- base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(kSwitchList);
- if (list_value.empty()) {
- // List all values.
- for (Scope::KeyValueMap::const_iterator i = build_args.begin();
- i != build_args.end(); ++i)
- sorted_args.insert(*i);
- } else {
- // List just the one specified as the parameter to --list.
- Scope::KeyValueMap::const_iterator found_arg = build_args.find(list_value);
+ if (args.size() == 1) {
+ // Get help on a specific command.
+ Scope::KeyValueMap::const_iterator found_arg = build_args.find(args[0]);
if (found_arg == build_args.end()) {
Err(Location(), "Unknown build argument.",
- "You asked for \"" + list_value + "\" which I didn't find in any "
- "build file\nassociated with this build.").PrintToStdout();
+ "You asked for \"" + args[0] + "\" which I didn't find in any "
+ "buildfile\nassociated with this build.");
return 1;
}
- sorted_args.insert(*found_arg);
- }
-
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchShort)) {
- // Short key=value output.
- for (std::map<base::StringPiece, Value>::iterator i = sorted_args.begin();
- i != sorted_args.end(); ++i) {
- OutputString(i->first.as_string());
- OutputString(" = ");
- OutputString(i->second.ToString(true));
- OutputString("\n");
- }
+ PrintArgHelp(args[0], found_arg->second);
return 0;
+ } else if (args.size() > 1) {
+ // Too many arguments.
+ Err(Location(), "You're holding it wrong.",
+ "Usage: \"gn args [arg name]\"").PrintToStdout();
+ return 1;
}
- // Long output.
+ // List all arguments. First put them in a regular map so they're sorted.
+ std::map<base::StringPiece, Value> sorted_args;
+ for (Scope::KeyValueMap::const_iterator i = build_args.begin();
+ i != build_args.end(); ++i)
+ sorted_args.insert(*i);
+
+ OutputString(
+ "Available build arguments. Note that the which arguments are declared\n"
+ "and their default values may depend on other arguments or the current\n"
+ "platform and architecture. So setting some values may add, remove, or\n"
+ "change the default value of other values.\n\n");
+
for (std::map<base::StringPiece, Value>::iterator i = sorted_args.begin();
i != sorted_args.end(); ++i) {
PrintArgHelp(i->first, i->second);
@@ -160,136 +165,4 @@ int ListArgs(const std::string& build_dir) {
return 0;
}
-int EditArgsFile(const std::string& build_dir) {
- {
- // Scope the setup. We only use it for some basic state. We'll do the
- // "real" build below in the gen command.
- Setup setup;
- setup.set_check_for_bad_items(false);
- // Don't fill build arguments. We're about to edit the file which supplies
- // these in the first place.
- setup.set_fill_arguments(false);
- if (!setup.DoSetup(build_dir) || !setup.Run())
- return 1;
-
- base::FilePath build_arg_file =
- setup.build_settings().GetFullPath(setup.GetBuildArgFile());
-
- // Get the path to the user's editor.
- base::FilePath editor;
-#if defined(OS_WIN)
- // We want to use 16-bit chars on Windows, so dont' go through the getenv
- // wrappers.
- base::char16 env_buf[MAX_PATH]
- if (::GetEnvironmentVariableW(L"EDITOR", env_buf, MAX_PATH) == 0)
- editor = base::FilePath(base::string16("notepad.exe"));
- else
- editor = base::FilePath(base::string16(env_buf));
-
- base::CommandLine editor_cmdline(editor);
- editor_cmdline.AppendArgPath(build_arg_file);
-
- // Use GetAppOutput as a simple way to wait for the process to exit.
- std::string output;
- base::GetAppOutput(editor_cmdline, &output);
-#else
- const char* editor_ptr = getenv("VISUAL");
- if (!editor_ptr)
- editor_ptr = getenv("EDITOR");
- if (!editor_ptr)
- editor_ptr = "vi";
-
- std::string cmd(editor_ptr);
- cmd.append(" \"");
-
- std::string escaped_build_arg_file = build_arg_file.value();
- ReplaceSubstringsAfterOffset(&escaped_build_arg_file, 0, "\"", "\\\"");
- cmd.append(escaped_build_arg_file);
-
- cmd.push_back('"');
- system(cmd.c_str());
-#endif
- }
-
- // Now do a normal "gen" command.
- std::vector<std::string> gen_commands;
- gen_commands.push_back(build_dir);
- return RunGen(gen_commands);
-}
-
-} // namespace
-
-extern const char kArgs[] = "args";
-extern const char kArgs_HelpShort[] =
- "args: Display or configure arguments declared by the build.";
-extern const char kArgs_Help[] =
- "gn args [arg name]\n"
- "\n"
- " See also \"gn help buildargs\" for a more high-level overview of how\n"
- " build arguments work.\n"
- "\n"
- "Usage\n"
- " gn args <dir_name>\n"
- " Open the arguments for the given build directory in an editor\n"
- " (as specified by the EDITOR environment variable). If the given\n"
- " build directory doesn't exist, it will be created and an empty\n"
- " args file will be opened in the editor. You would type something\n"
- " like this into that file:\n"
- " enable_doom_melon=false\n"
- " os=\"android\"\n"
- "\n"
- " Note: you can edit the build args manually by editing the file\n"
- " \"gn.args\" in the build directory and then running\n"
- " \"gn gen <build_dir>\".\n"
- "\n"
- " gn args <dir_name> --list[=<exact_arg>] [--short]\n"
- " Lists all build arguments available in the current configuration,\n"
- " or, if an exact_arg is specified for the list flag, just that one\n"
- " build argument.\n"
- "\n"
- " The output will list the declaration location, default value, and\n"
- " comment preceeding the declaration. If --short is specified,\n"
- " only the names and values will be printed.\n"
- "\n"
- " If the dir_name is specified, the build configuration will be\n"
- " taken from that build directory. The reason this is needed is that\n"
- " the definition of some arguments is dependent on the build\n"
- " configuration, so setting some values might add, remove, or change\n"
- " the default values for other arguments. Specifying your exact\n"
- " configuration allows the proper arguments to be displayed.\n"
- "\n"
- " Instead of specifying the dir_name, you can also use the\n"
- " command-line flag to specify the build configuration:\n"
- " --args=<exact list of args to use>\n"
- "\n"
- "Examples\n"
- " gn args out/Debug\n"
- " Opens an editor with the args for out/Debug.\n"
- "\n"
- " gn args out/Debug --list --short\n"
- " Prints all arguments with their default values for the out/Debug\n"
- " build.\n"
- "\n"
- " gn args out/Debug --list=cpu_arch\n"
- " Prints information about the \"cpu_arch\" argument for the out/Debug\n"
- " build.\n"
- "\n"
- " gn args --list --args=\"os=\\\"android\\\" enable_doom_melon=true\"\n"
- " Prints all arguments with the default values for a build with the\n"
- " given arguments set (which may affect the values of other\n"
- " arguments).\n";
-
-int RunArgs(const std::vector<std::string>& args) {
- if (args.size() != 1) {
- Err(Location(), "Exactly one build dir needed.",
- "Usage: \"gn args <build_dir>\"\n"
- "Or see \"gn help args\" for more variants.").PrintToStdout();
- return 1;
- }
-
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchList))
- return ListArgs(args[0]);
- return EditArgsFile(args[0]);
-}
-
} // namespace commands
diff --git a/tools/gn/gn.gyp b/tools/gn/gn.gyp
index 8be6a3b..93ec26e 100644
--- a/tools/gn/gn.gyp
+++ b/tools/gn/gn.gyp
@@ -203,7 +203,6 @@
'test_with_scope.cc',
'test_with_scope.h',
'tokenizer_unittest.cc',
- 'value_unittest.cc',
'visibility_unittest.cc',
],
'dependencies': [
diff --git a/tools/gn/ninja_build_writer.cc b/tools/gn/ninja_build_writer.cc
index f903904..c0fc7fc 100644
--- a/tools/gn/ninja_build_writer.cc
+++ b/tools/gn/ninja_build_writer.cc
@@ -51,11 +51,7 @@ std::string GetSelfInvocationCommand(const BuildSettings* build_settings) {
const CommandLine::SwitchMap& switches = our_cmdline.GetSwitches();
for (CommandLine::SwitchMap::const_iterator i = switches.begin();
i != switches.end(); ++i) {
- // Only write arguments we haven't already written. Always skip "args"
- // since those will have been written to the file and will be used
- // implicitly in the future. Keeping --args would mean changes to the file
- // would be ignored.
- if (i->first != "q" && i->first != "root" && i->first != "args") {
+ if (i->first != "q" && i->first != "root") {
std::string escaped_value =
EscapeString(FilePathToUTF8(i->second), escape_shell, NULL);
cmdline.AppendSwitchASCII(i->first, escaped_value);
@@ -134,6 +130,23 @@ void NinjaBuildWriter::WriteNinjaRules() {
<< " generator = 1\n"
<< " depfile = build.ninja.d\n";
+ // Provide a way to force regenerating ninja files if the user is suspicious
+ // something is out-of-date. This will be "ninja refresh".
+ out_ << "\nbuild refresh: gn\n";
+
+ // Provide a way to see what flags are associated with this build:
+ // This will be "ninja show".
+ const CommandLine& our_cmdline = *CommandLine::ForCurrentProcess();
+ std::string args = our_cmdline.GetSwitchValueASCII("args");
+ out_ << "rule echo\n";
+ out_ << " command = echo $text\n";
+ out_ << " description = ECHO $desc\n";
+ out_ << "build show: echo\n";
+ out_ << " desc = build arguments:\n";
+ out_ << " text = "
+ << (args.empty() ? std::string("No build args, using defaults.") : args)
+ << "\n";
+
// Input build files. These go in the ".d" file. If we write them as
// dependencies in the .ninja file itself, ninja will expect the files to
// exist and will error if they don't. When files are listed in a depfile,
diff --git a/tools/gn/setup.cc b/tools/gn/setup.cc
index 5ff6123..d956c0f 100644
--- a/tools/gn/setup.cc
+++ b/tools/gn/setup.cc
@@ -7,7 +7,6 @@
#include <stdlib.h>
#include <algorithm>
-#include <sstream>
#include "base/bind.h"
#include "base/command_line.h"
@@ -134,8 +133,6 @@ void DecrementWorkCount() {
// CommonSetup -----------------------------------------------------------------
-const char CommonSetup::kBuildArgFileName[] = "gn.args";
-
CommonSetup::CommonSetup()
: build_settings_(),
loader_(new LoaderImpl(&build_settings_)),
@@ -218,8 +215,7 @@ bool CommonSetup::RunPostMessageLoop() {
Setup::Setup()
: CommonSetup(),
empty_settings_(&empty_build_settings_, std::string()),
- dotfile_scope_(&empty_settings_),
- fill_arguments_(true) {
+ dotfile_scope_(&empty_settings_) {
empty_settings_.set_toolchain_label(Label());
build_settings_.set_item_defined_callback(
base::Bind(&ItemDefinedCallback, scheduler_.main_loop(), builder_));
@@ -240,6 +236,8 @@ bool Setup::DoSetup(const std::string& build_dir) {
cmdline->HasSwitch(kTracelogSwitch))
EnableTracing();
+ if (!FillArguments(*cmdline))
+ return false;
if (!FillSourceDir(*cmdline))
return false;
if (!RunConfigFile())
@@ -248,10 +246,6 @@ bool Setup::DoSetup(const std::string& build_dir) {
return false;
if (!FillBuildDir(build_dir)) // Must be after FillSourceDir to resolve.
return false;
- if (fill_arguments_) {
- if (!FillArguments(*cmdline))
- return false;
- }
FillPythonPath();
return true;
@@ -268,54 +262,15 @@ Scheduler* Setup::GetScheduler() {
return &scheduler_;
}
-SourceFile Setup::GetBuildArgFile() const {
- return SourceFile(build_settings_.build_dir().value() + kBuildArgFileName);
-}
-
bool Setup::FillArguments(const CommandLine& cmdline) {
- // Add a dependency on the build arguments file. If this changes, we want
- // to re-generated the build.
- g_scheduler->AddGenDependency(build_settings_.GetFullPath(GetBuildArgFile()));
-
- // Use the args on the command line if specified, and save them. Do this even
- // if the list is empty (this means clear any defaults).
- if (cmdline.HasSwitch(kSwitchArgs)) {
- if (!FillArgsFromCommandLine(cmdline.GetSwitchValueASCII(kSwitchArgs)))
- return false;
- SaveArgsToFile();
- return true;
- }
+ std::string args = cmdline.GetSwitchValueASCII(kSwitchArgs);
+ if (args.empty())
+ return true; // Nothing to set.
- // No command line args given, use the arguments from the build dir (if any).
- return FillArgsFromFile();
-}
-
-bool Setup::FillArgsFromCommandLine(const std::string& args) {
args_input_file_.reset(new InputFile(SourceFile()));
args_input_file_->SetContents(args);
- args_input_file_->set_friendly_name("the command-line \"--args\"");
- return FillArgsFromArgsInputFile();
-}
+ args_input_file_->set_friendly_name("the command-line \"--args\" settings");
-bool Setup::FillArgsFromFile() {
- SourceFile build_arg_source_file = GetBuildArgFile();
- base::FilePath build_arg_file =
- build_settings_.GetFullPath(build_arg_source_file);
-
- std::string contents;
- if (!base::ReadFileToString(build_arg_file, &contents))
- return true; // File doesn't exist, continue with default args.
- if (contents.empty())
- return true; // Empty file, do nothing.
-
- args_input_file_.reset(new InputFile(build_arg_source_file));
- args_input_file_->SetContents(contents);
- args_input_file_->set_friendly_name(
- "build arg file (use \"gn args <out_dir>\" to edit)");
- return FillArgsFromArgsInputFile();
-}
-
-bool Setup::FillArgsFromArgsInputFile() {
Err err;
args_tokens_ = Tokenizer::Tokenize(args_input_file_.get(), &err);
if (err.has_error()) {
@@ -343,35 +298,6 @@ bool Setup::FillArgsFromArgsInputFile() {
return true;
}
-bool Setup::SaveArgsToFile() {
- Scope::KeyValueMap args = build_settings_.build_args().GetAllOverrides();
-
- std::ostringstream stream;
- for (Scope::KeyValueMap::const_iterator i = args.begin();
- i != args.end(); ++i) {
- stream << i->first.as_string() << " = " << i->second.ToString(true);
- stream << std::endl;
- }
-
- // For the first run, the build output dir might not be created yet, so do
- // that so we can write a file into it. Ignore errors, we'll catch the error
- // when we try to write a file to it below.
- base::FilePath build_arg_file =
- build_settings_.GetFullPath(GetBuildArgFile());
- base::CreateDirectory(build_arg_file.DirName());
-
- std::string contents = stream.str();
- if (base::WriteFile(build_arg_file, contents.c_str(), contents.size()) ==
- -1) {
- Err(Location(), "Args file could not be written.",
- "The file is \"" + FilePathToUTF8(build_arg_file) +
- "\"").PrintToStdout();
- return false;
- }
-
- return true;
-}
-
bool Setup::FillSourceDir(const CommandLine& cmdline) {
// Find the .gn file.
base::FilePath root_path;
diff --git a/tools/gn/setup.h b/tools/gn/setup.h
index 0cd0a79..eb9d37b 100644
--- a/tools/gn/setup.h
+++ b/tools/gn/setup.h
@@ -58,10 +58,6 @@ class CommonSetup {
Builder* builder() { return builder_.get(); }
LoaderImpl* loader() { return loader_.get(); }
- // Name of the file in the root build directory that contains the build
- // arguements.
- static const char kBuildArgFileName[];
-
protected:
CommonSetup();
CommonSetup(const CommonSetup& other);
@@ -109,31 +105,10 @@ class Setup : public CommonSetup {
virtual Scheduler* GetScheduler() OVERRIDE;
- // Returns the file used to store the build arguments. Note that the path
- // might not exist.
- SourceFile GetBuildArgFile() const;
-
- // Sets whether the build arguments should be filled during setup from the
- // command line/build argument file. This will be true by default. The use
- // case for setting it to false is when editing build arguments, we don't
- // want to rely on them being valid.
- void set_fill_arguments(bool fa) { fill_arguments_ = fa; }
-
private:
// Fills build arguments. Returns true on success.
bool FillArguments(const base::CommandLine& cmdline);
- // Fills the build arguments from the command line or from the build arg file.
- bool FillArgsFromCommandLine(const std::string& args);
- bool FillArgsFromFile();
-
- // Given an already-loaded args_input_file_, parses and saves the resulting
- // arguments. Backend for the different FillArgs variants.
- bool FillArgsFromArgsInputFile();
-
- // Writes the build arguments to the build arg file.
- bool SaveArgsToFile();
-
// Fills the root directory into the settings. Returns true on success.
bool FillSourceDir(const base::CommandLine& cmdline);
@@ -165,10 +140,6 @@ class Setup : public CommonSetup {
std::vector<Token> dotfile_tokens_;
scoped_ptr<ParseNode> dotfile_root_;
- // Set to true when we should populate the build arguments from the command
- // line or build argument file. See setter above.
- bool fill_arguments_;
-
// State for invoking the command line args. We specifically want to keep
// this around for the entire run so that Values can blame to the command
// line when we issue errors about them.
diff --git a/tools/gn/value.cc b/tools/gn/value.cc
index 3632ddf..1fb7155 100644
--- a/tools/gn/value.cc
+++ b/tools/gn/value.cc
@@ -5,7 +5,6 @@
#include "tools/gn/value.h"
#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_util.h"
#include "tools/gn/scope.h"
Value::Value()
@@ -131,17 +130,8 @@ std::string Value::ToString(bool quote_string) const {
case INTEGER:
return base::Int64ToString(int_value_);
case STRING:
- if (quote_string) {
- std::string escaped = string_value_;
- // First escape all special uses of a backslash.
- ReplaceSubstringsAfterOffset(&escaped, 0, "\\$", "\\\\$");
- ReplaceSubstringsAfterOffset(&escaped, 0, "\\\"", "\\\\\"");
-
- // Now escape special chars.
- ReplaceSubstringsAfterOffset(&escaped, 0, "$", "\\$");
- ReplaceSubstringsAfterOffset(&escaped, 0, "\"", "\\\"");
- return "\"" + escaped + "\"";
- }
+ if (quote_string)
+ return "\"" + string_value_ + "\"";
return string_value_;
case LIST: {
std::string result = "[";
diff --git a/tools/gn/value.h b/tools/gn/value.h
index 87a2941..e6a9813 100644
--- a/tools/gn/value.h
+++ b/tools/gn/value.h
@@ -106,8 +106,7 @@ class Value {
void SetScopeValue(scoped_ptr<Scope> scope);
// Converts the given value to a string. Returns true if strings should be
- // quoted or the ToString of a string should be the string itself. If the
- // string is quoted, it will also enable escaping.
+ // quoted or the ToString of a string should be the string itself.
std::string ToString(bool quote_strings) const;
// Verifies that the value is of the given type. If it isn't, returns
diff --git a/tools/gn/value_unittest.cc b/tools/gn/value_unittest.cc
deleted file mode 100644
index a0fdde5..0000000
--- a/tools/gn/value_unittest.cc
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "testing/gtest/include/gtest/gtest.h"
-#include "tools/gn/value.h"
-
-TEST(Value, ToString) {
- Value strval(NULL, "hi\" $me\\you\\$\\\"");
- EXPECT_EQ("hi\" $me\\you\\$\\\"", strval.ToString(false));
- EXPECT_EQ("\"hi\\\" \\$me\\you\\\\\\$\\\\\\\"\"", strval.ToString(true));
-
- // Test lists, bools, and ints.
- Value listval(NULL, Value::LIST);
- listval.list_value().push_back(Value(NULL, "hi\"me"));
- listval.list_value().push_back(Value(NULL, true));
- listval.list_value().push_back(Value(NULL, false));
- listval.list_value().push_back(Value(NULL, static_cast<int64>(42)));
- // Printing lists always causes embedded strings to be quoted (ignoring the
- // quote flag), or else they wouldn't make much sense.
- EXPECT_EQ("[\"hi\\\"me\", true, false, 42]", listval.ToString(false));
- EXPECT_EQ("[\"hi\\\"me\", true, false, 42]", listval.ToString(true));
-
- // Some weird types, we may want to enhance or change printing of these, but
- // here we test the current behavior.
- EXPECT_EQ("<void>", Value().ToString(false));
- EXPECT_EQ("<scope>", Value(NULL, Value::SCOPE).ToString(false));
-}