|
12 | 12 |
|
13 | 13 | #include "ScanFixture.h"
|
14 | 14 | #include "swift/Basic/Platform.h"
|
| 15 | +#include "swift/Basic/Defer.h" |
15 | 16 | #include "llvm/ADT/Triple.h"
|
16 | 17 | #include "llvm/Support/Host.h"
|
17 | 18 | #include "llvm/Support/Path.h"
|
18 | 19 | #include "llvm/Support/raw_ostream.h"
|
| 20 | +#include "gtest/gtest.h" |
| 21 | +#include <string> |
19 | 22 |
|
20 | 23 | using namespace swift;
|
21 | 24 | using namespace swift::unittest;
|
@@ -46,19 +49,18 @@ static bool emitFileWithContents(StringRef base, StringRef name,
|
46 | 49 | }
|
47 | 50 |
|
48 | 51 | TEST_F(ScanTest, TestModuleDeps) {
|
49 |
| - // Create test input file |
50 |
| - auto TestFilePath = TemporaryTestWorkspace; |
51 |
| - llvm::sys::path::append(TestFilePath, "foo.swift"); |
52 |
| - std::string TestPathStr = llvm::Twine(TestFilePath).str(); |
| 52 | + SmallString<256> tempDir; |
| 53 | + ASSERT_FALSE(llvm::sys::fs::createUniqueDirectory("ScanTest.TestModuleDeps", tempDir)); |
| 54 | + SWIFT_DEFER { llvm::sys::fs::remove_directories(tempDir); }; |
53 | 55 |
|
54 |
| - ASSERT_FALSE( |
55 |
| - emitFileWithContents(TemporaryTestWorkspace, "foo.swift", "import A\n")); |
| 56 | + // Create test input file |
| 57 | + std::string TestPathStr = createFilename(tempDir, "foo.swift"); |
| 58 | + ASSERT_FALSE(emitFileWithContents(tempDir, "foo.swift", "import A\n")); |
| 59 | + llvm::dbgs() << "Input File: " << TestPathStr << "\n"; |
56 | 60 |
|
57 | 61 | // Create includes
|
58 |
| - std::string IncludeDirPath = |
59 |
| - createFilename(TemporaryTestWorkspace, "include"); |
| 62 | + std::string IncludeDirPath = createFilename(tempDir, "include"); |
60 | 63 | ASSERT_FALSE(llvm::sys::fs::create_directory(IncludeDirPath));
|
61 |
| - |
62 | 64 | std::string CHeadersDirPath = createFilename(IncludeDirPath, "CHeaders");
|
63 | 65 | ASSERT_FALSE(llvm::sys::fs::create_directory(CHeadersDirPath));
|
64 | 66 | std::string SwiftDirPath = createFilename(IncludeDirPath, "Swift");
|
@@ -155,10 +157,27 @@ export *\n\
|
155 | 157 | auto Target = llvm::Triple(llvm::sys::getDefaultTargetTriple());
|
156 | 158 | llvm::sys::path::append(StdLibDir, getPlatformNameForTriple(Target));
|
157 | 159 |
|
158 |
| - std::string Command = TestPathStr + " -I " + SwiftDirPath + " -I " + |
159 |
| - CHeadersDirPath + " -I " + StdLibDir.str().str() + |
160 |
| - " -I " + ShimsLibDir.str().str(); |
161 |
| - auto DependenciesOrErr = ScannerTool.getDependencies(Command.c_str(), {}); |
| 160 | + std::vector<std::string> CommandStrArr = { |
| 161 | + std::string("'") + TestPathStr + std::string("'"), |
| 162 | + std::string("-I ") + std::string("'") + SwiftDirPath + std::string("'"), |
| 163 | + std::string("-I ") + std::string("'") + CHeadersDirPath + std::string("'"), |
| 164 | + std::string("-I ") + std::string("'") + StdLibDir.str().str() + std::string("'"), |
| 165 | + std::string("-I ") + std::string("'") + ShimsLibDir.str().str() + std::string("'") |
| 166 | + }; |
| 167 | + |
| 168 | + // On Windows we need to add an extra escape for path separator characters because otherwise |
| 169 | + // the command line tokenizer will treat them as escape characters. |
| 170 | + for (size_t i = 0; i < CommandStrArr.size(); ++i) { |
| 171 | + std::replace(CommandStrArr[i].begin(), CommandStrArr[i].end(), '\\', '/'); |
| 172 | + } |
| 173 | + |
| 174 | + std::vector<const char*> Command; |
| 175 | + llvm::dbgs() << "Compiler Command: \n"; |
| 176 | + for (auto &command : CommandStrArr) { |
| 177 | + Command.push_back(command.c_str()); |
| 178 | + llvm::dbgs() << command.c_str() << "\n"; |
| 179 | + } |
| 180 | + auto DependenciesOrErr = ScannerTool.getDependencies(Command, {}); |
162 | 181 | ASSERT_FALSE(DependenciesOrErr.getError());
|
163 | 182 | auto Dependencies = DependenciesOrErr.get();
|
164 | 183 | // TODO: Output/verify dependency graph correctness
|
|
0 commit comments