| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <sstream> | 6 #include <sstream> |
| 7 | 7 |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "tools/gn/file_template.h" | 9 #include "tools/gn/file_template.h" |
| 10 #include "tools/gn/ninja_script_target_writer.h" | 10 #include "tools/gn/ninja_script_target_writer.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 target.script_values().args().push_back( | 77 target.script_values().args().push_back( |
| 78 "--out=foo bar{{source_name_part}}.o"); | 78 "--out=foo bar{{source_name_part}}.o"); |
| 79 | 79 |
| 80 target.script_values().outputs().push_back(SourceFile("//out/Debug/{{source_na
me_part}}.out")); | 80 target.script_values().outputs().push_back(SourceFile("//out/Debug/{{source_na
me_part}}.out")); |
| 81 | 81 |
| 82 target.source_prereqs().push_back(SourceFile("//foo/included.txt")); | 82 target.source_prereqs().push_back(SourceFile("//foo/included.txt")); |
| 83 | 83 |
| 84 // Posix. | 84 // Posix. |
| 85 { | 85 { |
| 86 setup.settings()->set_target_os(Settings::LINUX); | 86 setup.settings()->set_target_os(Settings::LINUX); |
| 87 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( |
| 88 "/usr/bin/python"))); |
| 87 | 89 |
| 88 std::ostringstream out; | 90 std::ostringstream out; |
| 89 NinjaScriptTargetWriter writer(&target, out); | 91 NinjaScriptTargetWriter writer(&target, out); |
| 90 writer.Run(); | 92 writer.Run(); |
| 91 | 93 |
| 92 const char expected_linux[] = | 94 const char expected_linux[] = |
| 93 "rule __foo_bar___rule\n" | 95 "rule __foo_bar___rule\n" |
| 94 " command = cd ../../foo; $pythonpath ../../foo/script.py -i ${source}
\"--out=foo$ bar${source_name_part}.o\"\n" | 96 " command = /usr/bin/python ../../foo/script.py -i ${source} " |
| 97 "\"--out=foo$ bar${source_name_part}.o\"\n" |
| 95 " description = CUSTOM //foo:bar()\n" | 98 " description = CUSTOM //foo:bar()\n" |
| 96 " restat = 1\n" | 99 " restat = 1\n" |
| 97 "\n" | 100 "\n" |
| 98 "build input1.out: __foo_bar___rule../../foo/input1.txt | ../../foo/incl
uded.txt\n" | 101 "build input1.out: __foo_bar___rule ../../foo/input1.txt | " |
| 102 "../../foo/included.txt\n" |
| 99 " source = ../../foo/input1.txt\n" | 103 " source = ../../foo/input1.txt\n" |
| 100 " source_name_part = input1\n" | 104 " source_name_part = input1\n" |
| 101 "build input2.out: __foo_bar___rule../../foo/input2.txt | ../../foo/incl
uded.txt\n" | 105 "build input2.out: __foo_bar___rule ../../foo/input2.txt | " |
| 106 "../../foo/included.txt\n" |
| 102 " source = ../../foo/input2.txt\n" | 107 " source = ../../foo/input2.txt\n" |
| 103 " source_name_part = input2\n" | 108 " source_name_part = input2\n" |
| 104 "\n" | 109 "\n" |
| 105 "build obj/foo/bar.stamp: tc_stamp input1.out input2.out\n"; | 110 "build obj/foo/bar.stamp: tc_stamp input1.out input2.out\n"; |
| 106 | 111 |
| 107 std::string out_str = out.str(); | 112 std::string out_str = out.str(); |
| 108 #if defined(OS_WIN) | 113 #if defined(OS_WIN) |
| 109 std::replace(out_str.begin(), out_str.end(), '\\', '/'); | 114 std::replace(out_str.begin(), out_str.end(), '\\', '/'); |
| 110 #endif | 115 #endif |
| 111 EXPECT_EQ(expected_linux, out_str); | 116 EXPECT_EQ(expected_linux, out_str); |
| 112 } | 117 } |
| 113 | 118 |
| 114 // Windows. | 119 // Windows. |
| 115 { | 120 { |
| 116 // Note: we use forward slashes here so that the output will be the same on | 121 // Note: we use forward slashes here so that the output will be the same on |
| 117 // Linux and Windows. | 122 // Linux and Windows. |
| 118 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( | 123 setup.build_settings()->set_python_path(base::FilePath(FILE_PATH_LITERAL( |
| 119 "C:/python/python.exe"))); | 124 "C:/python/python.exe"))); |
| 120 setup.settings()->set_target_os(Settings::WIN); | 125 setup.settings()->set_target_os(Settings::WIN); |
| 121 | 126 |
| 122 std::ostringstream out; | 127 std::ostringstream out; |
| 123 NinjaScriptTargetWriter writer(&target, out); | 128 NinjaScriptTargetWriter writer(&target, out); |
| 124 writer.Run(); | 129 writer.Run(); |
| 125 | 130 |
| 126 // TODO(brettw) I think we'll need to worry about backslashes here | 131 // TODO(brettw) I think we'll need to worry about backslashes here |
| 127 // depending if we're on actual Windows or Linux pretending to be Windows. | 132 // depending if we're on actual Windows or Linux pretending to be Windows. |
| 128 const char expected_win[] = | 133 const char expected_win[] = |
| 129 "rule __foo_bar___rule\n" | 134 "rule __foo_bar___rule\n" |
| 130 " command = C:/python/python.exe gyp-win-tool action-wrapper environmen
t.x86 __foo_bar___rule.$unique_name.rsp\n" | 135 " command = C:/python/python.exe gyp-win-tool action-wrapper " |
| 136 "environment.x86 __foo_bar___rule.$unique_name.rsp\n" |
| 131 " description = CUSTOM //foo:bar()\n" | 137 " description = CUSTOM //foo:bar()\n" |
| 132 " restat = 1\n" | 138 " restat = 1\n" |
| 133 " rspfile = __foo_bar___rule.$unique_name.rsp\n" | 139 " rspfile = __foo_bar___rule.$unique_name.rsp\n" |
| 134 " rspfile_content = C:/python/python.exe ../../foo/script.py -i ${sourc
e} \"--out=foo$ bar${source_name_part}.o\"\n" | 140 " rspfile_content = C:/python/python.exe ../../foo/script.py -i " |
| 141 "${source} \"--out=foo$ bar${source_name_part}.o\"\n" |
| 135 "\n" | 142 "\n" |
| 136 "build input1.out: __foo_bar___rule../../foo/input1.txt | ../../foo/incl
uded.txt\n" | 143 "build input1.out: __foo_bar___rule ../../foo/input1.txt | " |
| 144 "../../foo/included.txt\n" |
| 137 " unique_name = 0\n" | 145 " unique_name = 0\n" |
| 138 " source = ../../foo/input1.txt\n" | 146 " source = ../../foo/input1.txt\n" |
| 139 " source_name_part = input1\n" | 147 " source_name_part = input1\n" |
| 140 "build input2.out: __foo_bar___rule../../foo/input2.txt | ../../foo/incl
uded.txt\n" | 148 "build input2.out: __foo_bar___rule ../../foo/input2.txt | " |
| 149 "../../foo/included.txt\n" |
| 141 " unique_name = 1\n" | 150 " unique_name = 1\n" |
| 142 " source = ../../foo/input2.txt\n" | 151 " source = ../../foo/input2.txt\n" |
| 143 " source_name_part = input2\n" | 152 " source_name_part = input2\n" |
| 144 "\n" | 153 "\n" |
| 145 "build obj/foo/bar.stamp: tc_stamp input1.out input2.out\n"; | 154 "build obj/foo/bar.stamp: tc_stamp input1.out input2.out\n"; |
| 146 std::string out_str = out.str(); | 155 std::string out_str = out.str(); |
| 147 #if defined(OS_WIN) | 156 #if defined(OS_WIN) |
| 148 std::replace(out_str.begin(), out_str.end(), '\\', '/'); | 157 std::replace(out_str.begin(), out_str.end(), '\\', '/'); |
| 149 #endif | 158 #endif |
| 150 EXPECT_EQ(expected_win, out_str); | 159 EXPECT_EQ(expected_win, out_str); |
| 151 } | 160 } |
| 152 } | 161 } |
| OLD | NEW |