Improved the wrapper: it is now a separate component invoking the executable's main method through the refelection API

svn path=/nixpkgs/trunk/; revision=29239
This commit is contained in:
Sander van der Burg
2011-09-13 15:47:54 +00:00
parent 15293fa398
commit 06891d3997
7 changed files with 212 additions and 41 deletions
+16 -28
View File
@@ -8,13 +8,11 @@
, options ? "/p:Configuration=Debug;Platform=Win32"
, assemblyInputs ? []
, preBuild ? ""
, wrapMain ? false
, namespace ? null
, mainClassName ? null
, modifyPublicMain ? false
, mainClassFile ? null
}:
assert wrapMain -> namespace != null && mainClassName != null && mainClassFile != null;
assert modifyPublicMain -> mainClassFile != null;
let
wrapperCS = ./Wrapper.cs.in;
@@ -29,31 +27,10 @@ stdenv.mkDerivation {
'';
preBuild = ''
${preBuild}
# Create wrapper class with main method
${stdenv.lib.optionalString wrapMain ''
# Generate assemblySearchPaths string array contents
for path in ${toString assemblyInputs}
do
assemblySearchArray="$assemblySearchPaths @\"$(cygpath --windows $path | sed 's|\\|\\\\|g')\""
done
sed -e "s|@NAMESPACE@|${namespace}|" \
-e "s|@MAINCLASSNAME@|${mainClassName}|" \
-e "s|@ASSEMBLYSEARCHPATHS@|$assemblySearchArray|" \
${wrapperCS} > $(dirname ${mainClassFile})/${mainClassName}Wrapper.cs
# Rename old main method and make it publically accessible
# so that the wrapper can invoke it
sed -i -e "s|static void Main|public static void Main2|g" ${mainClassFile}
# Add the wrapper to the C# project file so that will be build as well
find . -name \*.csproj | while read file
do
sed -i -e "s|$(basename ${mainClassFile})|$(basename ${mainClassFile});${mainClassName}Wrapper.cs|" "$file"
done
${stdenv.lib.optionalString modifyPublicMain ''
sed -i -e "s|static void Main|public static void Main|" ${mainClassFile}
''}
${preBuild}
'';
installPhase = ''
@@ -80,5 +57,16 @@ stdenv.mkDerivation {
ensureDir $out
MSBuild.exe ${toString slnFile} /nologo /t:${targets} /p:IntermediateOutputPath=$(cygpath --windows $out)\\ /p:OutputPath=$(cygpath --windows $out)\\ /verbosity:${verbosity} ${options}
# Because .NET assemblies store strings as UTF-16 internally, we cannot detect
# hashes. Therefore a text files containing the proper paths is created
# We can also use this file the propagate transitive dependencies.
ensureDir $out/nix-support
for i in ${toString assemblyInputs}
do
echo $i >> $out/nix-support/dotnet-assemblies
done
'';
}