Hi!

I wanted to update the recently introduced first mono application KeePass2 from 2.57 to 2.58. Unfortunately there have been a lot of changes in the build scripts done by the KeePass2 project, so it's not totally straight forward.

I've updated the package definition:

```scheme
(define-public keepass
  (package
    (name "keepass")
    (version "2.58")
    (source
     (origin
       (method url-fetch)
       (uri
        (string-append "mirror://sourceforge/keepass/KeePass%202.x/" version
         "/KeePass-" version "-Source.zip"))
       (sha256 (base32 "1i7dqihvavllfb781r9mvbn8jqq5w8vhs8h36nmx6sgamgd32cgh"))))
    (build-system gnu-build-system)
    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (replace 'unpack
           (lambda* (#:key source #:allow-other-keys)
             (mkdir "source")
             (chdir "source")
             (invoke "unzip" source)))
         (replace 'configure
           (lambda* (#:key inputs #:allow-other-keys)
             ;; Make reproducible by setting build number to 0.
             (substitute* "KeePass/Properties/AssemblyInfo.cs"
              (("AssemblyVersion[(]\"2.58.*\"[)]")
               "AssemblyVersion(\"2.58.0\")"))
             (substitute* "KeePassLib/Native/NativeMethods.Unix.cs"
              (("libgcrypt.so.20" all)
               (string-append (search-input-file inputs (string-append "/lib/" all))))
              (("libglib-2.0.so.0" all)
               (string-append (search-input-file inputs (string-append "/lib/" all))))
              (("libgtk-3.so.0" all)
               (string-append (search-input-file inputs (string-append "/lib/" all)))))
             (substitute* "KeePass_2.sln"
(("GlobalSection\\(ExtensibilityGlobals\\).*?EndGlobalSection")
                "")
(("GlobalSection\\(ExtensibilityGlobals\\).*?EndGlobalSection"
                 all)
                "")
               (("Format Version 10\\.0")
                "Format Version 11.00"))
             (substitute* "KeePass/KeePass_2.csproj"
               ((" ToolsVersion=\\\"3\\.5\\\"")
                " ToolsVersion=\"4.0\"")
               (("<SignAssembly>true</SignAssembly>")
                "<SignAssembly>false</SignAssembly>")
               ;; XML Serializer AOT compiler doesn't work here.
               ;; mono will just fall back to the runtime compiler.
               (("[$][(]FrameworkSDKDir[)]bin.sgen[.]exe")
                "echo")
(("<TargetFrameworkVersion>v4\\.8</TargetFrameworkVersion>")
"<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>")
              (("[$]\\(SDK40ToolsPath\\)sgen.exe")
                "sgen"))
             (copy-file
              "Ext/Icons_15_VA/LowResIcons/KeePass_LR.ico"
              "KeePass/KeePass.ico")
             (copy-file
              "Ext/Icons_15_VA/LowResIcons/KeePass_LR.ico"
              "KeePass/IconsKeePass.ico")
             (copy-file
              "Ext/Icons_15_VA/LowResIcons/KeePass_LR_G.ico"
              "KeePass/IconsKeePass_G.ico")
             (copy-file
              "Ext/Icons_15_VA/LowResIcons/KeePass_LR_R.ico"
              "KeePass/IconsKeePass_R.ico")
             (copy-file
              "Ext/Icons_15_VA/LowResIcons/KeePass_LR_Y.ico"
              "KeePass/IconsKeePass_Y.ico")
             (substitute* "KeePassLib/KeePassLib_2.csproj"
               ((" ToolsVersion=\\\"3\\.5\\\"")
                " ToolsVersion=\"4.0\"")
               (("<SignAssembly>true</SignAssembly>")
                "<SignAssembly>false</SignAssembly>"))
             (substitute* "Translation/TrlUtil/TrlUtil_2.csproj"
               ((" ToolsVersion=\\\"3\\.5\\\"") " ToolsVersion=\"4.0\""))
             (copy-file
              "Ext/Icons_15_VA/LowResIcons/KeePass_LR.ico"
              "KeePass/Resources/KeePass.ico")))
         (delete 'patch-source)
         (replace 'build
           (lambda* (#:key outputs #:allow-other-keys)
             (setenv "MONO_REGISTRY_PATH" "/dev/null")
             (setenv "LANG" "C")
             (setenv "LC_ALL" "C")
             (invoke
              "xbuild"
              "/target:KeePass_2"
              "/property:Configuration=Release"
              "/property:CscToolExe=mcs"
              "/verbosity:diagnostic"
              "KeePass_2.sln")))
         (replace 'install
           (lambda* (#:key inputs outputs #:allow-other-keys)
             (let* ((out (assoc-ref outputs "out"))
                    (script (string-append out "/bin/keepass"))
                    (mono (assoc-ref inputs "mono"))
                    (lib (string-append out "/lib/keepass")))
               (install-file "KeePass/obj/Release/KeePass.exe" lib)
               (install-file "Ext/KeePass.config.xml" lib)
               (mkdir (string-append out "/bin"))
               (call-with-output-file script
                   (lambda (port)
                     (format port "#!/bin/sh
exec ~s/bin/mono ~s/lib/keepass/KeePass.exe \"$@\"
"
                             mono out)))
               (chmod script #o755)
               (patch-shebang script)))))
       #:tests? #f)) ;no tests
    (native-inputs (list unzip icoutils))
    (inputs (list mono libgdiplus libgcrypt glib gtk+))
    (home-page "https://keepass.info/";)
    (synopsis
     "Light-weight and easy-to-use password manager")
    (description
     "KeePass is a light-weight and easy-to-use password manager that helps
you manage your passwords in a secure way.  All passwords are stored
in an encrypted database, which is locked with a master key or key file.")
    (license license:gpl2)))
```

And it already looks quite promising.
The build is now using `sgen.exe` and I introduced an additional substitute to fix that, as in the guix package the executable is just called `sgen` and can be found in the path.

In the PostBuildEvent stage however it fails with this error:

```plaintext

                Building target "PostBuildEvent" in project "/tmp/guix-build-keepass-2.58.drv-0/source/KeePass/KeePass_2.csproj" ("/gnu/store/8nrx7iks6sn415fy40gjk1sgvvq2h4ss-mono-6.12.0.206/lib/mono/xbuild/14.0/bin/Microsoft.Common.targets"); "CoreBuild" depends on it.
                        Target PostBuildEvent:
                        Task "Exec"
                                Using task Exec from Microsoft.Build.Tasks.Exec, Microsoft.Build.Tasks.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a                                 Executing: "sgen" /assembly:"/tmp/guix-build-keepass-2.58.drv-0/source/Build/KeePass/Release//KeePass.exe" /force /nologo /compiler:/keycontainer:VS_KEY_8C26407DBC890166 /compiler:/delaysign-                                 Environment variables being passed to the tool:
                                Unhandled Exception:
                                System.NullReferenceException: Object reference not set to an instance of an object                                   at System.Xml.Serialization.XmlSerializationWriterCodeGen.FindXmlnsIndex (System.Xml.Serialization.MemberMapping[] members) [0x0001f] in <53b00ac7466842619b1a7d5e3f1d13ef>:0                                   at System.Xml.Serialization.XmlSerializationWriterCodeGen.WriteStructMethod (System.Xml.Serialization.StructMapping mapping) [0x0036c] in <53b00ac7466842619b1a7d5e3f1d13ef>:0                                   at System.Xml.Serialization.XmlSerializationWriterCodeGen.GenerateMethod (System.Xml.Serialization.TypeMapping mapping) [0x0002a] in <53b00ac7466842619b1a7d5e3f1d13ef>:0                                   at System.Xml.Serialization.XmlSerializationCodeGen.GenerateReferencedMethods () [0x0001e] in <53b00ac7466842619b1a7d5e3f1d13ef>:0                                   at System.Xml.Serialization.XmlSerializationWriterCodeGen.GenerateEnd () [0x00000] in <53b00ac7466842619b1a7d5e3f1d13ef>:0                                   at System.Xml.Serialization.TempAssembly.GenerateAssembly (System.Xml.Serialization.XmlMapping[] xmlMappings, System.Type[] types, System.String defaultNamespace, System.Security.Policy.Evidence evidence, System.Xml.Serialization.XmlSerializerCompilerParameters parameters, System.Reflection.Assembly assembly, System.Collections.Hashtable assemblies) [0x003fd] in <53b00ac7466842619b1a7d5e3f1d13ef>:0                                   at System.Xml.Serialization.XmlSerializer.GenerateSerializer (System.Type[] types, System.Xml.Serialization.XmlMapping[] mappings, System.CodeDom.Compiler.CompilerParameters parameters) [0x000e7] in <53b00ac7466842619b1a7d5e3f1d13ef>:0                                   at Driver.Run (System.String[] args) [0x0049a] in <d7689402766846c7b7cb017fea07820e>:0                                   at Driver.Main (System.String[] args) [0x00006] in <d7689402766846c7b7cb017fea07820e>:0                                 [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object                                   at System.Xml.Serialization.XmlSerializationWriterCodeGen.FindXmlnsIndex (System.Xml.Serialization.MemberMapping[] members) [0x0001f] in <53b00ac7466842619b1a7d5e3f1d13ef>:0                                   at System.Xml.Serialization.XmlSerializationWriterCodeGen.WriteStructMethod (System.Xml.Serialization.StructMapping mapping) [0x0036c] in <53b00ac7466842619b1a7d5e3f1d13ef>:0                                   at System.Xml.Serialization.XmlSerializationWriterCodeGen.GenerateMethod (System.Xml.Serialization.TypeMapping mapping) [0x0002a] in <53b00ac7466842619b1a7d5e3f1d13ef>:0                                   at System.Xml.Serialization.XmlSerializationCodeGen.GenerateReferencedMethods () [0x0001e] in <53b00ac7466842619b1a7d5e3f1d13ef>:0                                   at System.Xml.Serialization.XmlSerializationWriterCodeGen.GenerateEnd () [0x00000] in <53b00ac7466842619b1a7d5e3f1d13ef>:0                                   at System.Xml.Serialization.TempAssembly.GenerateAssembly (System.Xml.Serialization.XmlMapping[] xmlMappings, System.Type[] types, System.String defaultNamespace, System.Security.Policy.Evidence evidence, System.Xml.Serialization.XmlSerializerCompilerParameters parameters, System.Reflection.Assembly assembly, System.Collections.Hashtable assemblies) [0x003fd] in <53b00ac7466842619b1a7d5e3f1d13ef>:0                                   at System.Xml.Serialization.XmlSerializer.GenerateSerializer (System.Type[] types, System.Xml.Serialization.XmlMapping[] mappings, System.CodeDom.Compiler.CompilerParameters parameters) [0x000e7] in <53b00ac7466842619b1a7d5e3f1d13ef>:0                                   at Driver.Run (System.String[] args) [0x0049a] in <d7689402766846c7b7cb017fea07820e>:0                                   at Driver.Main (System.String[] args) [0x00006] in <d7689402766846c7b7cb017fea07820e>:0
                                Tool sh execution finished.
/gnu/store/8nrx7iks6sn415fy40gjk1sgvvq2h4ss-mono-6.12.0.206/lib/mono/xbuild/14.0/bin/Microsoft.Common.targets: error : Command '"sgen" /assembly:"/tmp/guix-build-keepass-2.58.drv-0/source/Build/KeePass/Release//KeePass.exe" /force /nologo /compiler:/keycontainer:VS_KEY_8C26407DBC890166 /compiler:/delaysign-' exited with code: 1.
                        Task "Exec" execution -- FAILED
                        Done building target "PostBuildEvent" in project "/tmp/guix-build-keepass-2.58.drv-0/source/KeePass/KeePass_2.csproj".-- FAILED                 Done building target "PostBuildEvent" in project "/tmp/guix-build-keepass-2.58.drv-0/source/KeePass/KeePass_2.csproj" ("/gnu/store/8nrx7iks6sn415fy40gjk1sgvvq2h4ss-mono
```

does anyone have clue about that?

Thanks,

nomike



Reply via email to