summary refs log tree commit diff
path: root/pkgs/build-support/dotnetenv/wrapper.nix
blob: 4b07fc27dcb00358cc4f73a36d5e0b360ba69425 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{dotnetenv}:

{ name
, src
, baseDir ? "."
, slnFile
, targets ? "ReBuild"
, verbosity ? "detailed"
, options ? "/p:Configuration=Debug;Platform=Win32"
, assemblyInputs ? []
, preBuild ? ""
, namespace
, mainClassName
, mainClassFile
, modifyPublicMain ? true
}:

let
  application = dotnetenv.buildSolution {
    inherit name src baseDir slnFile targets verbosity;
    inherit options assemblyInputs preBuild;
    inherit modifyPublicMain mainClassFile;
  };
in
dotnetenv.buildSolution {
  name = "${name}-wrapper";
  src = ./Wrapper;
  slnFile = "Wrapper.sln";
  assemblyInputs = [ application ];
  preBuild = ''
    addRuntimeDeps()
    {
	if [ -f $1/nix-support/dotnet-assemblies ]
	then
	    for i in $(cat $1/nix-support/dotnet-assemblies)
	    do
		windowsPath=$(cygpath --windows $i | sed 's|\\|\\\\|g')
		assemblySearchArray="$assemblySearchArray @\"$windowsPath\""
		
		addRuntimeDeps $i
	    done
	fi
    }
    
    export exePath=$(cygpath --windows $(find ${application} -name \*.exe) | sed 's|\\|\\\\|g')
    
    # Generate assemblySearchPaths string array contents
    for path in ${toString assemblyInputs}
    do
        assemblySearchArray="$assemblySearchArray @\"$(cygpath --windows $path | sed 's|\\|\\\\|g')\", "
	addRuntimeDeps $path
    done
    
    sed -e "s|@ROOTNAMESPACE@|${namespace}Wrapper|" \
        -e "s|@ASSEMBLYNAME@|${namespace}|" \
        Wrapper/Wrapper.csproj.in > Wrapper/Wrapper.csproj
    
    sed -e "s|@NAMESPACE@|${namespace}|g" \
        -e "s|@MAINCLASSNAME@|${mainClassName}|g" \
	-e "s|@EXEPATH@|$exePath|g" \
	-e "s|@ASSEMBLYSEARCHPATH@|$assemblySearchArray|" \
        Wrapper/Wrapper.cs.in > Wrapper/Wrapper.cs
  '';
}