Use paths relative to build dir in custom actions. Also inserts a space between the rule name and the inputs in the generated ninja. BUG=309227 Review URL: https://codereview.chromium.org/30253002 Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 5d708cc57d82fd783827dd27a15633a87d8db3b8
diff --git a/tools/gn/ninja_script_target_writer.cc b/tools/gn/ninja_script_target_writer.cc index 5dd8095..1b8358c 100644 --- a/tools/gn/ninja_script_target_writer.cc +++ b/tools/gn/ninja_script_target_writer.cc
@@ -94,10 +94,9 @@ } else { // Posix can execute Python directly. out_ << "rule " << custom_rule_name << std::endl; - out_ << " command = cd "; - path_output_.WriteDir(out_, target_->label().dir(), - PathOutput::DIR_NO_LAST_SLASH); - out_ << "; $pythonpath "; + out_ << " command = "; + path_output_.WriteFile(out_, settings_->build_settings()->python_path()); + out_ << " "; path_output_.WriteFile(out_, target_->script_values().script()); args_template.WriteWithNinjaExpansions(out_); out_ << std::endl; @@ -135,7 +134,7 @@ out_ << "build"; WriteOutputFilesForBuildLine(output_template, sources[i], output_files); - out_ << ": " << custom_rule_name; + out_ << ": " << custom_rule_name << " "; path_output_.WriteFile(out_, sources[i]); out_ << implicit_deps << std::endl;
diff --git a/tools/gn/ninja_script_target_writer_unittest.cc b/tools/gn/ninja_script_target_writer_unittest.cc index f3e7bf1..1394717 100644 --- a/tools/gn/ninja_script_target_writer_unittest.cc +++ b/tools/gn/ninja_script_target_writer_unittest.cc
@@ -84,6 +84,8 @@ // Posix. { setup.settings()->set_target_os(Settings::LINUX); + setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( + "/usr/bin/python"))); std::ostringstream out; NinjaScriptTargetWriter writer(&target, out); @@ -91,14 +93,17 @@ const char expected_linux[] = "rule __foo_bar___rule\n" - " command = cd ../../foo; $pythonpath ../../foo/script.py -i ${source} \"--out=foo$ bar${source_name_part}.o\"\n" + " command = /usr/bin/python ../../foo/script.py -i ${source} " + "\"--out=foo$ bar${source_name_part}.o\"\n" " description = CUSTOM //foo:bar()\n" " restat = 1\n" "\n" - "build input1.out: __foo_bar___rule../../foo/input1.txt | ../../foo/included.txt\n" + "build input1.out: __foo_bar___rule ../../foo/input1.txt | " + "../../foo/included.txt\n" " source = ../../foo/input1.txt\n" " source_name_part = input1\n" - "build input2.out: __foo_bar___rule../../foo/input2.txt | ../../foo/included.txt\n" + "build input2.out: __foo_bar___rule ../../foo/input2.txt | " + "../../foo/included.txt\n" " source = ../../foo/input2.txt\n" " source_name_part = input2\n" "\n" @@ -127,17 +132,21 @@ // depending if we're on actual Windows or Linux pretending to be Windows. const char expected_win[] = "rule __foo_bar___rule\n" - " command = C:/python/python.exe gyp-win-tool action-wrapper environment.x86 __foo_bar___rule.$unique_name.rsp\n" + " command = C:/python/python.exe gyp-win-tool action-wrapper " + "environment.x86 __foo_bar___rule.$unique_name.rsp\n" " description = CUSTOM //foo:bar()\n" " restat = 1\n" " rspfile = __foo_bar___rule.$unique_name.rsp\n" - " rspfile_content = C:/python/python.exe ../../foo/script.py -i ${source} \"--out=foo$ bar${source_name_part}.o\"\n" + " rspfile_content = C:/python/python.exe ../../foo/script.py -i " + "${source} \"--out=foo$ bar${source_name_part}.o\"\n" "\n" - "build input1.out: __foo_bar___rule../../foo/input1.txt | ../../foo/included.txt\n" + "build input1.out: __foo_bar___rule ../../foo/input1.txt | " + "../../foo/included.txt\n" " unique_name = 0\n" " source = ../../foo/input1.txt\n" " source_name_part = input1\n" - "build input2.out: __foo_bar___rule../../foo/input2.txt | ../../foo/included.txt\n" + "build input2.out: __foo_bar___rule ../../foo/input2.txt | " + "../../foo/included.txt\n" " unique_name = 1\n" " source = ../../foo/input2.txt\n" " source_name_part = input2\n"