diff options
Diffstat (limited to 'recipes-devtools/clang/clang/0008-llvm-Enhance-path-prefix-mapping.patch')
-rw-r--r-- | recipes-devtools/clang/clang/0008-llvm-Enhance-path-prefix-mapping.patch | 172 |
1 files changed, 0 insertions, 172 deletions
diff --git a/recipes-devtools/clang/clang/0008-llvm-Enhance-path-prefix-mapping.patch b/recipes-devtools/clang/clang/0008-llvm-Enhance-path-prefix-mapping.patch deleted file mode 100644 index bc89cfd..0000000 --- a/recipes-devtools/clang/clang/0008-llvm-Enhance-path-prefix-mapping.patch +++ /dev/null | |||
@@ -1,172 +0,0 @@ | |||
1 | From 8fe2337421af15dee7f0d2af7ed27695e2967723 Mon Sep 17 00:00:00 2001 | ||
2 | From: Khem Raj <raj.khem@gmail.com> | ||
3 | Date: Fri, 15 Feb 2019 11:32:09 -0800 | ||
4 | Subject: [PATCH] llvm: Enhance path prefix mapping | ||
5 | |||
6 | Upstream-Status: Submitted [https://reviews.llvm.org/D56769] | ||
7 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | ||
8 | --- | ||
9 | llvm/include/llvm/Support/Path.h | 25 +++++++++++++++--- | ||
10 | llvm/lib/Support/Path.cpp | 44 +++++++++++++++++++++++++------- | ||
11 | llvm/unittests/Support/Path.cpp | 29 +++++++++++++++++++++ | ||
12 | 3 files changed, 85 insertions(+), 13 deletions(-) | ||
13 | |||
14 | diff --git a/llvm/include/llvm/Support/Path.h b/llvm/include/llvm/Support/Path.h | ||
15 | index 5c0bee58f18..20332c09852 100644 | ||
16 | --- a/llvm/include/llvm/Support/Path.h | ||
17 | +++ b/llvm/include/llvm/Support/Path.h | ||
18 | @@ -150,18 +150,35 @@ void replace_extension(SmallVectorImpl<char> &path, const Twine &extension, | ||
19 | /// | ||
20 | /// @code | ||
21 | /// /foo, /old, /new => /foo | ||
22 | +/// /old, /old, /new => /new | ||
23 | +/// /old, /old/, /new, false => /old | ||
24 | +/// /old, /old/, /new, true => /new | ||
25 | /// /old/foo, /old, /new => /new/foo | ||
26 | +/// /old/foo, /old/, /new => /new/foo | ||
27 | +/// /old/foo, /old/, /new/ => /new/foo | ||
28 | +/// /oldfoo, /old, /new => /oldfoo | ||
29 | /// /foo, <empty>, /new => /new/foo | ||
30 | -/// /old/foo, /old, <empty> => /foo | ||
31 | +/// /foo, <empty>, new => new/foo | ||
32 | +/// /old/foo, /old, <empty>, false => /foo | ||
33 | +/// /old/foo, /old, <empty>, true => foo | ||
34 | /// @endcode | ||
35 | /// | ||
36 | /// @param Path If \a Path starts with \a OldPrefix modify to instead | ||
37 | /// start with \a NewPrefix. | ||
38 | -/// @param OldPrefix The path prefix to strip from \a Path. | ||
39 | +/// @param OldPrefix The path prefix to strip from \a Path. Any trailing | ||
40 | +/// path separator is ignored if strict is true. | ||
41 | /// @param NewPrefix The path prefix to replace \a NewPrefix with. | ||
42 | -void replace_path_prefix(SmallVectorImpl<char> &Path, | ||
43 | +/// @param style The path separator style | ||
44 | +/// @param strict Strict prefix path checking | ||
45 | +/// @result true if \a Path begins with OldPrefix | ||
46 | +bool replace_path_prefix(SmallVectorImpl<char> &Path, | ||
47 | const StringRef &OldPrefix, const StringRef &NewPrefix, | ||
48 | - Style style = Style::native); | ||
49 | + Style style = Style::native, bool strict = false); | ||
50 | +static inline bool replace_path_prefix(SmallVectorImpl<char> &Path, | ||
51 | + const StringRef &OldPrefix, const StringRef &NewPrefix, | ||
52 | + bool strict, Style style = Style::native) { | ||
53 | + return replace_path_prefix(Path, OldPrefix, NewPrefix, style, strict); | ||
54 | +} | ||
55 | |||
56 | /// Append to path. | ||
57 | /// | ||
58 | diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp | ||
59 | index c49260125db..89a1c193d14 100644 | ||
60 | --- a/llvm/lib/Support/Path.cpp | ||
61 | +++ b/llvm/lib/Support/Path.cpp | ||
62 | @@ -496,27 +496,53 @@ void replace_extension(SmallVectorImpl<char> &path, const Twine &extension, | ||
63 | path.append(ext.begin(), ext.end()); | ||
64 | } | ||
65 | |||
66 | -void replace_path_prefix(SmallVectorImpl<char> &Path, | ||
67 | +bool replace_path_prefix(SmallVectorImpl<char> &Path, | ||
68 | const StringRef &OldPrefix, const StringRef &NewPrefix, | ||
69 | - Style style) { | ||
70 | + Style style, bool strict) { | ||
71 | if (OldPrefix.empty() && NewPrefix.empty()) | ||
72 | - return; | ||
73 | + return false; | ||
74 | |||
75 | StringRef OrigPath(Path.begin(), Path.size()); | ||
76 | - if (!OrigPath.startswith(OldPrefix)) | ||
77 | - return; | ||
78 | + StringRef OldPrefixDir; | ||
79 | + | ||
80 | + if (!strict && OldPrefix.size() > OrigPath.size()) | ||
81 | + return false; | ||
82 | + | ||
83 | + if (!strict && OldPrefix.size() > OrigPath.size()) | ||
84 | + return false; | ||
85 | + | ||
86 | + // Ensure OldPrefixDir does not have a trailing separator. | ||
87 | + if (!OldPrefix.empty() && is_separator(OldPrefix.back())) | ||
88 | + OldPrefixDir = parent_path(OldPrefix, style); | ||
89 | + else | ||
90 | + OldPrefixDir = OldPrefix; | ||
91 | + | ||
92 | + if (!OrigPath.startswith(OldPrefixDir)) | ||
93 | + return false; | ||
94 | + | ||
95 | + if (OrigPath.size() > OldPrefixDir.size()) | ||
96 | + if (!is_separator(OrigPath[OldPrefixDir.size()], style) && strict) | ||
97 | + return false; | ||
98 | |||
99 | // If prefixes have the same size we can simply copy the new one over. | ||
100 | - if (OldPrefix.size() == NewPrefix.size()) { | ||
101 | + if (OldPrefixDir.size() == NewPrefix.size() && !strict) { | ||
102 | llvm::copy(NewPrefix, Path.begin()); | ||
103 | - return; | ||
104 | + return true; | ||
105 | } | ||
106 | |||
107 | - StringRef RelPath = OrigPath.substr(OldPrefix.size()); | ||
108 | + StringRef RelPath = OrigPath.substr(OldPrefixDir.size()); | ||
109 | SmallString<256> NewPath; | ||
110 | path::append(NewPath, style, NewPrefix); | ||
111 | - path::append(NewPath, style, RelPath); | ||
112 | + if (!RelPath.empty()) { | ||
113 | + if (!is_separator(RelPath[0], style) || !strict) | ||
114 | + path::append(NewPath, style, RelPath); | ||
115 | + else | ||
116 | + path::append(NewPath, style, relative_path(RelPath, style)); | ||
117 | + } | ||
118 | + | ||
119 | Path.swap(NewPath); | ||
120 | + | ||
121 | + return true; | ||
122 | } | ||
123 | |||
124 | void native(const Twine &path, SmallVectorImpl<char> &result, Style style) { | ||
125 | diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp | ||
126 | index ccd72d7f176..13af998d8f8 100644 | ||
127 | --- a/llvm/unittests/Support/Path.cpp | ||
128 | +++ b/llvm/unittests/Support/Path.cpp | ||
129 | @@ -1219,7 +1219,9 @@ TEST(Support, RemoveDots) { | ||
130 | TEST(Support, ReplacePathPrefix) { | ||
131 | SmallString<64> Path1("/foo"); | ||
132 | SmallString<64> Path2("/old/foo"); | ||
133 | + SmallString<64> Path3("/oldnew/foo"); | ||
134 | SmallString<64> OldPrefix("/old"); | ||
135 | + SmallString<64> OldPrefixSep("/old/"); | ||
136 | SmallString<64> NewPrefix("/new"); | ||
137 | SmallString<64> NewPrefix2("/longernew"); | ||
138 | SmallString<64> EmptyPrefix(""); | ||
139 | @@ -1239,6 +1241,33 @@ TEST(Support, ReplacePathPrefix) { | ||
140 | Path = Path2; | ||
141 | path::replace_path_prefix(Path, OldPrefix, EmptyPrefix); | ||
142 | EXPECT_EQ(Path, "/foo"); | ||
143 | + Path = Path2; | ||
144 | + path::replace_path_prefix(Path, OldPrefix, EmptyPrefix, true); | ||
145 | + EXPECT_EQ(Path, "foo"); | ||
146 | + Path = Path3; | ||
147 | + path::replace_path_prefix(Path, OldPrefix, NewPrefix, false); | ||
148 | + EXPECT_EQ(Path, "/newnew/foo"); | ||
149 | + Path = Path3; | ||
150 | + path::replace_path_prefix(Path, OldPrefix, NewPrefix, true); | ||
151 | + EXPECT_EQ(Path, "/oldnew/foo"); | ||
152 | + Path = Path3; | ||
153 | + path::replace_path_prefix(Path, OldPrefixSep, NewPrefix, true); | ||
154 | + EXPECT_EQ(Path, "/oldnew/foo"); | ||
155 | + Path = Path1; | ||
156 | + path::replace_path_prefix(Path, EmptyPrefix, NewPrefix); | ||
157 | + EXPECT_EQ(Path, "/new/foo"); | ||
158 | + Path = OldPrefix; | ||
159 | + path::replace_path_prefix(Path, OldPrefix, NewPrefix); | ||
160 | + EXPECT_EQ(Path, "/new"); | ||
161 | + Path = OldPrefixSep; | ||
162 | + path::replace_path_prefix(Path, OldPrefix, NewPrefix); | ||
163 | + EXPECT_EQ(Path, "/new/"); | ||
164 | + Path = OldPrefix; | ||
165 | + path::replace_path_prefix(Path, OldPrefixSep, NewPrefix, false); | ||
166 | + EXPECT_EQ(Path, "/old"); | ||
167 | + Path = OldPrefix; | ||
168 | + path::replace_path_prefix(Path, OldPrefixSep, NewPrefix, true); | ||
169 | + EXPECT_EQ(Path, "/new"); | ||
170 | } | ||
171 | |||
172 | TEST_F(FileSystemTest, OpenFileForRead) { | ||