never executed always true always false
    1 module GHC.Linker.Windows
    2    ( maybeCreateManifest
    3    )
    4 where
    5 
    6 import GHC.Prelude
    7 import GHC.SysTools
    8 import GHC.Driver.Session
    9 import GHC.Utils.TmpFs
   10 import GHC.Utils.Logger
   11 
   12 import System.FilePath
   13 import System.Directory
   14 
   15 maybeCreateManifest
   16    :: Logger
   17    -> TmpFs
   18    -> DynFlags
   19    -> FilePath      -- ^ filename of executable
   20    -> IO [FilePath] -- ^ extra objects to embed, maybe
   21 maybeCreateManifest logger tmpfs dflags exe_filename = do
   22    let manifest_filename = exe_filename <.> "manifest"
   23        manifest =
   24          "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n\
   25          \  <assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">\n\
   26          \  <assemblyIdentity version=\"1.0.0.0\"\n\
   27          \     processorArchitecture=\"X86\"\n\
   28          \     name=\"" ++ dropExtension exe_filename ++ "\"\n\
   29          \     type=\"win32\"/>\n\n\
   30          \  <trustInfo xmlns=\"urn:schemas-microsoft-com:asm.v3\">\n\
   31          \    <security>\n\
   32          \      <requestedPrivileges>\n\
   33          \        <requestedExecutionLevel level=\"asInvoker\" uiAccess=\"false\"/>\n\
   34          \        </requestedPrivileges>\n\
   35          \       </security>\n\
   36          \  </trustInfo>\n\
   37          \</assembly>\n"
   38 
   39    writeFile manifest_filename manifest
   40 
   41    -- Windows will find the manifest file if it is named
   42    -- foo.exe.manifest. However, for extra robustness, and so that
   43    -- we can move the binary around, we can embed the manifest in
   44    -- the binary itself using windres:
   45    if not (gopt Opt_EmbedManifest dflags)
   46       then return []
   47       else do
   48          rc_filename <- newTempName logger tmpfs (tmpDir dflags) TFL_CurrentModule "rc"
   49          rc_obj_filename <-
   50            newTempName logger tmpfs (tmpDir dflags) TFL_GhcSession (objectSuf dflags)
   51 
   52          writeFile rc_filename $
   53              "1 24 MOVEABLE PURE " ++ show manifest_filename ++ "\n"
   54                -- magic numbers :-)
   55                -- show is a bit hackish above, but we need to escape the
   56                -- backslashes in the path.
   57 
   58          runWindres logger dflags $ map GHC.SysTools.Option $
   59                ["--input="++rc_filename,
   60                 "--output="++rc_obj_filename,
   61                 "--output-format=coff"]
   62                -- no FileOptions here: windres doesn't like seeing
   63                -- backslashes, apparently
   64 
   65          removeFile manifest_filename
   66 
   67          return [rc_obj_filename]