• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
MCLDDirectory()17 MCLDDirectory::MCLDDirectory()
18   : Directory(), m_Name(), m_bInSysroot(false) {
19 }
20 
MCLDDirectory(const char * pName)21 MCLDDirectory::MCLDDirectory(const char* pName)
22   : Directory(), m_Name(pName) {
23   Directory::m_Path.assign(pName);
24 
25   if (!Directory::m_Path.empty())
26     m_bInSysroot = ('=' == Directory::m_Path.native()[0]);
27 
28   Directory::m_Path.m_append_separator_if_needed();
29   if (m_bInSysroot)
30     Directory::m_Path.native().erase(Directory::m_Path.native().begin());
31   else
32     detail::open_dir(*this);
33 }
34 
MCLDDirectory(const std::string & pName)35 MCLDDirectory::MCLDDirectory(const std::string &pName)
36   : Directory(), m_Name(pName) {
37   Directory::m_Path.assign(pName);
38 
39   if (!Directory::m_Path.empty())
40     m_bInSysroot = ('=' == Directory::m_Path.native()[0]);
41 
42   Directory::m_Path.m_append_separator_if_needed();
43   if (m_bInSysroot)
44     Directory::m_Path.native().erase(Directory::m_Path.native().begin());
45   else
46     detail::open_dir(*this);
47 }
48 
MCLDDirectory(llvm::StringRef pName)49 MCLDDirectory::MCLDDirectory(llvm::StringRef pName)
50   : Directory(), m_Name(pName.data(), pName.size()) {
51   Directory::m_Path.assign(pName.str());
52 
53   if (!Directory::m_Path.empty())
54     m_bInSysroot = ('=' == Directory::m_Path.native()[0]);
55 
56   Directory::m_Path.m_append_separator_if_needed();
57   if (m_bInSysroot)
58     Directory::m_Path.native().erase(Directory::m_Path.native().begin());
59   else
60     detail::open_dir(*this);
61 }
62 
assign(llvm::StringRef pName)63 MCLDDirectory &MCLDDirectory::assign(llvm::StringRef pName)
64 {
65   m_Name.assign(pName.data(), pName.size());
66   Directory::m_Path.assign(pName.str());
67 
68   if (!Directory::m_Path.empty())
69     m_bInSysroot = ('=' == Directory::m_Path.native()[0]);
70 
71   Directory::m_Path.m_append_separator_if_needed();
72   if (m_bInSysroot)
73     Directory::m_Path.native().erase(Directory::m_Path.native().begin());
74   else
75     detail::open_dir(*this);
76   Directory::m_FileStatus = FileStatus();
77   Directory::m_SymLinkStatus = FileStatus();
78   Directory::m_Cache.clear();
79   Directory::m_Handler = 0;
80   return (*this);
81 }
82 
~MCLDDirectory()83 MCLDDirectory::~MCLDDirectory()
84 {
85 }
86 
isInSysroot() const87 bool MCLDDirectory::isInSysroot() const
88 {
89   return m_bInSysroot;
90 }
91 
setSysroot(const sys::fs::Path & pSysroot)92 void MCLDDirectory::setSysroot(const sys::fs::Path& pSysroot)
93 {
94   if (m_bInSysroot) {
95     std::string old_path = Directory::m_Path.native();
96     Directory::m_Path.native() = pSysroot.native();
97     Directory::m_Path.m_append_separator_if_needed();
98     Directory::m_Path.native() += old_path;
99     detail::canonicalize(Directory::m_Path.native());
100     detail::open_dir(*this);
101   }
102 }
103 
104