Consolidate code that computes resource dir relative to swift executable.

This commit is contained in:
Tony Allevato
2019-11-05 16:03:29 -08:00
parent 3c45041b17
commit 2c7b518460
3 changed files with 19 additions and 11 deletions

View File

@@ -38,11 +38,17 @@ swift::CompilerInvocation::CompilerInvocation() {
setTargetTriple(llvm::sys::getDefaultTargetTriple());
}
void CompilerInvocation::computeRuntimeResourcePathFromExecutablePath(
StringRef mainExecutablePath, llvm::SmallString<128> &runtimeResourcePath) {
runtimeResourcePath.assign(mainExecutablePath);
llvm::sys::path::remove_filename(runtimeResourcePath); // Remove /swift
llvm::sys::path::remove_filename(runtimeResourcePath); // Remove /bin
llvm::sys::path::append(runtimeResourcePath, "lib", "swift");
}
void CompilerInvocation::setMainExecutablePath(StringRef Path) {
llvm::SmallString<128> LibPath(Path);
llvm::sys::path::remove_filename(LibPath); // Remove /swift
llvm::sys::path::remove_filename(LibPath); // Remove /bin
llvm::sys::path::append(LibPath, "lib", "swift");
llvm::SmallString<128> LibPath;
computeRuntimeResourcePathFromExecutablePath(Path, LibPath);
setRuntimeResourcePath(LibPath.str());
llvm::SmallString<128> DiagnosticDocsPath(Path);