1 //===- MCLDDirectory.cpp --------------------------------------------------===// 2 // 3 // The MCLinker Project 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 #include <mcld/MC/MCLDDirectory.h> 10 #include <mcld/Support/FileSystem.h> 11 12 using namespace mcld; 13 using namespace mcld::sys::fs; 14 15 //===----------------------------------------------------------------------===// 16 // MCLDDirectory 17 //===----------------------------------------------------------------------===// 18 MCLDDirectory::MCLDDirectory() 19 : Directory(), m_Name(), m_bInSysroot(false) { 20 } 21 22 MCLDDirectory::MCLDDirectory(const char* pName) 23 : Directory(), m_Name(pName) { 24 Directory::m_Path.assign(pName); 25 26 if (!Directory::m_Path.empty()) 27 m_bInSysroot = ('=' == Directory::m_Path.native()[0]); 28 29 Directory::m_Path.m_append_separator_if_needed(); 30 if (m_bInSysroot) 31 Directory::m_Path.native().erase(Directory::m_Path.native().begin()); 32 else 33 detail::open_dir(*this); 34 } 35 36 MCLDDirectory::MCLDDirectory(const std::string &pName) 37 : Directory(), m_Name(pName) { 38 Directory::m_Path.assign(pName); 39 40 if (!Directory::m_Path.empty()) 41 m_bInSysroot = ('=' == Directory::m_Path.native()[0]); 42 43 Directory::m_Path.m_append_separator_if_needed(); 44 if (m_bInSysroot) 45 Directory::m_Path.native().erase(Directory::m_Path.native().begin()); 46 else 47 detail::open_dir(*this); 48 } 49 50 MCLDDirectory::MCLDDirectory(llvm::StringRef pName) 51 : Directory(), m_Name(pName.data(), pName.size()) { 52 Directory::m_Path.assign(pName.str()); 53 54 if (!Directory::m_Path.empty()) 55 m_bInSysroot = ('=' == Directory::m_Path.native()[0]); 56 57 Directory::m_Path.m_append_separator_if_needed(); 58 if (m_bInSysroot) 59 Directory::m_Path.native().erase(Directory::m_Path.native().begin()); 60 else 61 detail::open_dir(*this); 62 } 63 64 MCLDDirectory &MCLDDirectory::assign(llvm::StringRef pName) 65 { 66 m_Name.assign(pName.data(), pName.size()); 67 Directory::m_Path.assign(pName.str()); 68 69 if (!Directory::m_Path.empty()) 70 m_bInSysroot = ('=' == Directory::m_Path.native()[0]); 71 72 Directory::m_Path.m_append_separator_if_needed(); 73 if (m_bInSysroot) 74 Directory::m_Path.native().erase(Directory::m_Path.native().begin()); 75 else 76 detail::open_dir(*this); 77 Directory::m_FileStatus = FileStatus(); 78 Directory::m_SymLinkStatus = FileStatus(); 79 Directory::m_Cache.clear(); 80 Directory::m_Handler = 0; 81 return (*this); 82 } 83 84 MCLDDirectory::~MCLDDirectory() 85 { 86 } 87 88 bool MCLDDirectory::isInSysroot() const 89 { 90 return m_bInSysroot; 91 } 92 93 void MCLDDirectory::setSysroot(const sys::fs::Path& pSysroot) 94 { 95 if (m_bInSysroot) { 96 std::string old_path = Directory::m_Path.native(); 97 Directory::m_Path.native() = pSysroot.native(); 98 Directory::m_Path.m_append_separator_if_needed(); 99 Directory::m_Path.native() += old_path; 100 detail::canonicalize(Directory::m_Path.native()); 101 detail::open_dir(*this); 102 } 103 } 104 105