[lld] r193145 - [PECOFF] Add /manifestuac command line option.

Rui Ueyama ruiu at google.com
Mon Oct 21 21:21:29 PDT 2013


Author: ruiu
Date: Mon Oct 21 23:21:29 2013
New Revision: 193145

URL: http://llvm.org/viewvc/llvm-project?rev=193145&view=rev
Log:
[PECOFF] Add /manifestuac command line option.

This option is used for the manifest file too.

Modified:
    lld/trunk/lib/Driver/WinLinkDriver.cpp
    lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=193145&r1=193144&r2=193145&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Mon Oct 21 23:21:29 2013
@@ -161,6 +161,38 @@ bool parseManifest(StringRef option, boo
   return true;
 }
 
+// Parse /manifestuac:(level=<string>|uiAccess=<string>).
+//
+// The arguments will be embedded to the manifest XML file with no error check,
+// so the values given via the command line must be valid as XML attributes.
+// This may sound a bit odd, but that's how link.exe works, so we will follow.
+bool parseManifestUac(StringRef option, llvm::Optional<std::string> &level,
+                      llvm::Optional<bool> &uiAccess) {
+  for (;;) {
+    option = option.ltrim();
+    if (option.empty())
+      return true;
+    if (option.startswith("level=")) {
+      option = option.substr(strlen("level="));
+      StringRef value;
+      llvm::tie(value, option) = option.split(" ");
+      level = value.str();
+      continue;
+    }
+    if (option.startswith("uiAccess=true")) {
+      option = option.substr(strlen("uiAccess=true"));
+      uiAccess = true;
+      continue;
+    }
+    if (option.startswith("uiAccess=false")) {
+      option = option.substr(strlen("uiAccess=false"));
+      uiAccess = false;
+      continue;
+    }
+    return false;
+  }
+}
+
 // Handle /failifmismatch option.
 bool handleFailIfMismatchOption(StringRef option,
                                 std::map<StringRef, StringRef> &mustMatch,
@@ -437,6 +469,22 @@ WinLinkDriver::parse(int argc, const cha
       break;
     }
 
+    case OPT_manifestuac: {
+      // Parse /manifestuac.
+      llvm::Optional<std::string> priviledgeLevel;
+      llvm::Optional<bool> uiAccess;
+      if (!parseManifestUac(inputArg->getValue(), priviledgeLevel, uiAccess)) {
+        diagnostics << "Unknown argument for /manifestuac: "
+                    << inputArg->getValue() << "\n";
+        return false;
+      }
+      if (priviledgeLevel.hasValue())
+        ctx.setManifestLevel(priviledgeLevel.getValue());
+      if (uiAccess.hasValue())
+        ctx.setManifestUiAccess(uiAccess.getValue());
+      break;
+    }
+
     case OPT_failifmismatch:
       if (handleFailIfMismatchOption(inputArg->getValue(), failIfMismatchMap,
                                      diagnostics))

Modified: lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp?rev=193145&r1=193144&r2=193145&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp Mon Oct 21 23:21:29 2013
@@ -372,7 +372,7 @@ TEST_F(WinLinkParserTest, FailIfMismatch
 }
 
 //
-// Tests for /manifest.
+// Tests for /manifest and /manifestuac.
 //
 TEST_F(WinLinkParserTest, Manifest_Default) {
   EXPECT_TRUE(parse("link.exe", "/manifest", "a.out", nullptr));
@@ -406,6 +406,27 @@ TEST_F(WinLinkParserTest, Manifest_Embed
   EXPECT_EQ(false, _context.getManifestUiAccess());
 }
 
+TEST_F(WinLinkParserTest, Manifestuac_Level) {
+  EXPECT_TRUE(parse("link.exe", "/manifestuac:level='requireAdministrator'",
+                    "a.out", nullptr));
+  EXPECT_EQ("'requireAdministrator'", _context.getManifestLevel());
+  EXPECT_EQ(false, _context.getManifestUiAccess());
+}
+
+TEST_F(WinLinkParserTest, Manifestuac_UiAccess) {
+  EXPECT_TRUE(parse("link.exe", "/manifestuac:uiAccess=true", "a.out", nullptr));
+  EXPECT_EQ("'asInvoker'", _context.getManifestLevel());
+  EXPECT_EQ(true, _context.getManifestUiAccess());
+}
+
+TEST_F(WinLinkParserTest, Manifestuac_LevelAndUiAccess) {
+  EXPECT_TRUE(parse("link.exe",
+                    "/manifestuac:level='requireAdministrator' uiAccess=true",
+                    "a.out", nullptr));
+  EXPECT_EQ("'requireAdministrator'", _context.getManifestLevel());
+  EXPECT_EQ(true, _context.getManifestUiAccess());
+}
+
 //
 // Test for command line flags that are ignored.
 //





More information about the llvm-commits mailing list