[FileSystem] Move path resolution logic out of FileSpec

This patch removes the logic for resolving paths out of FileSpec and
updates call sites to rely on the FileSystem class instead.

Differential revision: https://reviews.llvm.org/D53915

llvm-svn: 345890
diff --git a/lldb/source/API/SBAttachInfo.cpp b/lldb/source/API/SBAttachInfo.cpp
index d6cb212..a74487a 100644
--- a/lldb/source/API/SBAttachInfo.cpp
+++ b/lldb/source/API/SBAttachInfo.cpp
@@ -26,16 +26,14 @@
 SBAttachInfo::SBAttachInfo(const char *path, bool wait_for)
     : m_opaque_sp(new ProcessAttachInfo()) {
   if (path && path[0])
-    m_opaque_sp->GetExecutableFile().SetFile(path, false,
-                                             FileSpec::Style::native);
+    m_opaque_sp->GetExecutableFile().SetFile(path, FileSpec::Style::native);
   m_opaque_sp->SetWaitForLaunch(wait_for);
 }
 
 SBAttachInfo::SBAttachInfo(const char *path, bool wait_for, bool async)
     : m_opaque_sp(new ProcessAttachInfo()) {
   if (path && path[0])
-    m_opaque_sp->GetExecutableFile().SetFile(path, false,
-                                             FileSpec::Style::native);
+    m_opaque_sp->GetExecutableFile().SetFile(path, FileSpec::Style::native);
   m_opaque_sp->SetWaitForLaunch(wait_for);
   m_opaque_sp->SetAsync(async);
 }
@@ -79,8 +77,7 @@
 
 void SBAttachInfo::SetExecutable(const char *path) {
   if (path && path[0])
-    m_opaque_sp->GetExecutableFile().SetFile(path, false,
-                                             FileSpec::Style::native);
+    m_opaque_sp->GetExecutableFile().SetFile(path, FileSpec::Style::native);
   else
     m_opaque_sp->GetExecutableFile().Clear();
 }
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index ad6147d..c7dc478 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -735,7 +735,7 @@
         m_opaque_sp->GetPlatformList().GetSelectedPlatform().get(), arch_name);
     TargetSP target_sp(
         m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture(
-            FileSpec(filename, false), arch_name ? &arch : nullptr));
+            FileSpec(filename), arch_name ? &arch : nullptr));
     sb_target.SetSP(target_sp);
   }
   return sb_target;
diff --git a/lldb/source/API/SBFileSpec.cpp b/lldb/source/API/SBFileSpec.cpp
index 067db0d..0a8a281 100644
--- a/lldb/source/API/SBFileSpec.cpp
+++ b/lldb/source/API/SBFileSpec.cpp
@@ -32,11 +32,15 @@
     : m_opaque_ap(new lldb_private::FileSpec(fspec)) {}
 
 // Deprecated!!!
-SBFileSpec::SBFileSpec(const char *path)
-    : m_opaque_ap(new FileSpec(path, true)) {}
+SBFileSpec::SBFileSpec(const char *path) : m_opaque_ap(new FileSpec(path)) {
+  FileSystem::Instance().Resolve(*m_opaque_ap);
+}
 
 SBFileSpec::SBFileSpec(const char *path, bool resolve)
-    : m_opaque_ap(new FileSpec(path, resolve)) {}
+    : m_opaque_ap(new FileSpec(path)) {
+  if (resolve)
+    FileSystem::Instance().Resolve(*m_opaque_ap);
+}
 
 SBFileSpec::~SBFileSpec() {}
 
@@ -68,7 +72,7 @@
 int SBFileSpec::ResolvePath(const char *src_path, char *dst_path,
                             size_t dst_len) {
   llvm::SmallString<64> result(src_path);
-  lldb_private::FileSpec::Resolve(result);
+  FileSystem::Instance().Resolve(result);
   ::snprintf(dst_path, dst_len, "%s", result.c_str());
   return std::min(dst_len - 1, result.size());
 }
diff --git a/lldb/source/API/SBHostOS.cpp b/lldb/source/API/SBHostOS.cpp
index e56951d..ac6ab40 100644
--- a/lldb/source/API/SBHostOS.cpp
+++ b/lldb/source/API/SBHostOS.cpp
@@ -11,8 +11,9 @@
 #include "Plugins/ScriptInterpreter/Python/lldb-python.h"
 #endif
 
-#include "lldb/API/SBHostOS.h"
 #include "lldb/API/SBError.h"
+#include "lldb/API/SBHostOS.h"
+#include "lldb/Host/FileSystem.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Host/HostNativeThread.h"
@@ -86,7 +87,8 @@
 
   llvm::SmallString<64> home_dir_path;
   llvm::sys::path::home_directory(home_dir_path);
-  FileSpec homedir(home_dir_path.c_str(), true);
+  FileSpec homedir(home_dir_path.c_str());
+  FileSystem::Instance().Resolve(homedir);
 
   sb_fspec.SetFileSpec(homedir);
   return sb_fspec;
diff --git a/lldb/source/API/SBLaunchInfo.cpp b/lldb/source/API/SBLaunchInfo.cpp
index aa1759a..b1bbfa5 100644
--- a/lldb/source/API/SBLaunchInfo.cpp
+++ b/lldb/source/API/SBLaunchInfo.cpp
@@ -128,7 +128,7 @@
 }
 
 void SBLaunchInfo::SetWorkingDirectory(const char *working_dir) {
-  m_opaque_sp->SetWorkingDirectory(FileSpec{working_dir, false});
+  m_opaque_sp->SetWorkingDirectory(FileSpec(working_dir));
 }
 
 uint32_t SBLaunchInfo::GetLaunchFlags() {
@@ -155,7 +155,7 @@
 }
 
 void SBLaunchInfo::SetShell(const char *path) {
-  m_opaque_sp->SetShell(FileSpec(path, false));
+  m_opaque_sp->SetShell(FileSpec(path));
 }
 
 bool SBLaunchInfo::GetShellExpandArguments() {
@@ -184,8 +184,7 @@
 
 bool SBLaunchInfo::AddOpenFileAction(int fd, const char *path, bool read,
                                      bool write) {
-  return m_opaque_sp->AppendOpenFileAction(fd, FileSpec{path, false}, read,
-                                           write);
+  return m_opaque_sp->AppendOpenFileAction(fd, FileSpec(path), read, write);
 }
 
 bool SBLaunchInfo::AddSuppressFileAction(int fd, bool read, bool write) {
diff --git a/lldb/source/API/SBModuleSpec.cpp b/lldb/source/API/SBModuleSpec.cpp
index afabd9a..65492f5 100644
--- a/lldb/source/API/SBModuleSpec.cpp
+++ b/lldb/source/API/SBModuleSpec.cpp
@@ -114,7 +114,8 @@
 
 SBModuleSpecList SBModuleSpecList::GetModuleSpecifications(const char *path) {
   SBModuleSpecList specs;
-  FileSpec file_spec(path, true);
+  FileSpec file_spec(path);
+  FileSystem::Instance().Resolve(file_spec);
   Host::ResolveExecutableInBundle(file_spec);
   ObjectFile::GetModuleSpecifications(file_spec, 0, 0, *specs.m_opaque_ap);
   return specs;
diff --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp
index bce3fd7..2c254b2 100644
--- a/lldb/source/API/SBPlatform.cpp
+++ b/lldb/source/API/SBPlatform.cpp
@@ -244,9 +244,9 @@
   PlatformSP platform_sp(GetSP());
   if (platform_sp) {
     if (path)
-      platform_sp->SetWorkingDirectory(FileSpec{path, false});
+      platform_sp->SetWorkingDirectory(FileSpec(path));
     else
-      platform_sp->SetWorkingDirectory(FileSpec{});
+      platform_sp->SetWorkingDirectory(FileSpec());
     return true;
   }
   return false;
@@ -406,7 +406,7 @@
       if (working_dir)
         shell_command.SetWorkingDirectory(working_dir);
     }
-    return platform_sp->RunShellCommand(command, FileSpec{working_dir, false},
+    return platform_sp->RunShellCommand(command, FileSpec(working_dir),
                                         &shell_command.m_opaque_ptr->m_status,
                                         &shell_command.m_opaque_ptr->m_signo,
                                         &shell_command.m_opaque_ptr->m_output,
@@ -449,7 +449,7 @@
   PlatformSP platform_sp(GetSP());
   if (platform_sp) {
     sb_error.ref() =
-        platform_sp->MakeDirectory(FileSpec{path, false}, file_permissions);
+        platform_sp->MakeDirectory(FileSpec(path), file_permissions);
   } else {
     sb_error.SetErrorString("invalid platform");
   }
@@ -460,7 +460,7 @@
   PlatformSP platform_sp(GetSP());
   if (platform_sp) {
     uint32_t file_permissions = 0;
-    platform_sp->GetFilePermissions(FileSpec{path, false}, file_permissions);
+    platform_sp->GetFilePermissions(FileSpec(path), file_permissions);
     return file_permissions;
   }
   return 0;
@@ -471,8 +471,8 @@
   SBError sb_error;
   PlatformSP platform_sp(GetSP());
   if (platform_sp) {
-    sb_error.ref() = platform_sp->SetFilePermissions(FileSpec{path, false},
-                                                     file_permissions);
+    sb_error.ref() =
+        platform_sp->SetFilePermissions(FileSpec(path), file_permissions);
   } else {
     sb_error.SetErrorString("invalid platform");
   }
diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp
index e79231d..c8b2943 100644
--- a/lldb/source/API/SBProcess.cpp
+++ b/lldb/source/API/SBProcess.cpp
@@ -130,10 +130,9 @@
     if (process_sp->GetState() == eStateConnected) {
       if (stop_at_entry)
         launch_flags |= eLaunchFlagStopAtEntry;
-      ProcessLaunchInfo launch_info(
-          FileSpec{stdin_path, false}, FileSpec{stdout_path, false},
-          FileSpec{stderr_path, false}, FileSpec{working_directory, false},
-          launch_flags);
+      ProcessLaunchInfo launch_info(FileSpec(stdin_path), FileSpec(stdout_path),
+                                    FileSpec(stderr_path),
+                                    FileSpec(working_directory), launch_flags);
       Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
       if (exe_module)
         launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
@@ -1351,7 +1350,7 @@
     return error;
   }
 
-  FileSpec core_file(file_name, false);
+  FileSpec core_file(file_name);
   error.ref() = PluginManager::SaveCore(process_sp, core_file);
   return error;
 }
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index 8b55927..e25fa31 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -226,7 +226,8 @@
   SBProcess sb_process;
   TargetSP target_sp(GetSP());
   if (target_sp) {
-    FileSpec filespec(core_file, true);
+    FileSpec filespec(core_file);
+    FileSystem::Instance().Resolve(filespec);
     ProcessSP process_sp(target_sp->CreateProcess(
         target_sp->GetDebugger().GetListener(), "", &filespec));
     if (process_sp) {
@@ -325,10 +326,9 @@
     if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
       launch_flags |= eLaunchFlagDisableSTDIO;
 
-    ProcessLaunchInfo launch_info(
-        FileSpec{stdin_path, false}, FileSpec{stdout_path, false},
-        FileSpec{stderr_path, false}, FileSpec{working_directory, false},
-        launch_flags);
+    ProcessLaunchInfo launch_info(FileSpec(stdin_path), FileSpec(stdout_path),
+                                  FileSpec(stderr_path),
+                                  FileSpec(working_directory), launch_flags);
 
     Module *exe_module = target_sp->GetExecutableModulePointer();
     if (exe_module)
@@ -516,8 +516,7 @@
 
   if (name && target_sp) {
     ProcessAttachInfo attach_info;
-    attach_info.GetExecutableFile().SetFile(name, false,
-                                            FileSpec::Style::native);
+    attach_info.GetExecutableFile().SetFile(name, FileSpec::Style::native);
     attach_info.SetWaitForLaunch(wait_for);
     if (listener.IsValid())
       attach_info.SetListener(listener.GetSP());
@@ -766,7 +765,7 @@
     const lldb::addr_t offset = 0;
     if (module_name && module_name[0]) {
       FileSpecList module_spec_list;
-      module_spec_list.Append(FileSpec(module_name, false));
+      module_spec_list.Append(FileSpec(module_name));
       sb_bp = target_sp->CreateBreakpoint(
           &module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto,
           eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
@@ -894,7 +893,7 @@
   SBFileSpecList module_spec_list;
   SBFileSpecList comp_unit_list;
   if (module_name && module_name[0]) {
-    module_spec_list.Append(FileSpec(module_name, false));
+    module_spec_list.Append(FileSpec(module_name));
   }
   return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
                                  module_spec_list, comp_unit_list);
@@ -995,7 +994,7 @@
   SBFileSpecList module_spec_list;
 
   if (module_name && module_name[0]) {
-    module_spec_list.Append(FileSpec(module_name, false));
+    module_spec_list.Append(FileSpec(module_name));
   }
 
   SBFileSpecList source_file_list;
@@ -1549,7 +1548,7 @@
   if (target_sp) {
     ModuleSpec module_spec;
     if (path)
-      module_spec.GetFileSpec().SetFile(path, false, FileSpec::Style::native);
+      module_spec.GetFileSpec().SetFile(path, FileSpec::Style::native);
 
     if (uuid_cstr)
       module_spec.GetUUID().SetFromStringRef(uuid_cstr);
@@ -1561,8 +1560,7 @@
       module_spec.GetArchitecture() = target_sp->GetArchitecture();
 
     if (symfile)
-      module_spec.GetSymbolFileSpec().SetFile(symfile, false,
-                                              FileSpec::Style::native);
+      module_spec.GetSymbolFileSpec().SetFile(symfile, FileSpec::Style::native);
 
     sb_module.SetSP(target_sp->GetSharedModule(module_spec));
   }