llvm.org GIT mirror llvm / 6bf104b
Option parsing: recognize the special -- token Everything that comes after -- should be treated as a filename. This enables passing in filenames that would otherwise be conflated with command-line options. This is especially important for clang-cl which supports options starting with /, which are easily conflatable with Unix-style path names. Differential Revision: http://llvm-reviews.chandlerc.com/D1274 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187675 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 6 years ago
2 changed file(s) with 29 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
252252 unsigned Index = 0, End = ArgEnd - ArgBegin;
253253 while (Index < End) {
254254 // Ignore empty arguments (other things may still take them as arguments).
255 if (Args->getArgString(Index)[0] == '\0') {
255 StringRef Str = Args->getArgString(Index);
256 if (Str == "") {
256257 ++Index;
257258 continue;
259 }
260
261 if (Str == "--") {
262 // Everything after -- is a filename.
263 ++Index;
264
265 assert(TheInputOptionID != 0 && "Invalid input option ID.");
266 while (Index < End) {
267 Args->append(new Arg(getOption(TheInputOptionID),
268 Args->getArgString(Index), Index,
269 Args->getArgString(Index)));
270 ++Index;
271 }
272 break;
258273 }
259274
260275 unsigned Prev = Index;
155155 EXPECT_EQ(AL->getAllArgValues(OPT_B)[0], "foo");
156156 EXPECT_EQ(AL->getAllArgValues(OPT_B)[1], "bar");
157157 }
158
159 TEST(Option, DashDash) {
160 TestOptTable T;
161 unsigned MAI, MAC;
162
163 const char *MyArgs[] = { "-A", "--", "-B", "--" };
164 OwningPtr AL(T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
165 EXPECT_TRUE(AL->hasArg(OPT_A));
166 EXPECT_FALSE(AL->hasArg(OPT_B));
167 EXPECT_EQ(AL->getAllArgValues(OPT_INPUT).size(), 2U);
168 EXPECT_EQ(AL->getAllArgValues(OPT_INPUT)[0], "-B");
169 EXPECT_EQ(AL->getAllArgValues(OPT_INPUT)[1], "--");
170 }