summary refs log tree commit diff
path: root/pkgs/build-support/dotnetenv/build-solution.nix
blob: 62370d361cd023b39a1bde9b69c4e99fceb2e29c (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{stdenv, dotnetfx}:
{ name
, src
, baseDir ? "."
, slnFile
, targets ? "ReBuild"
, verbosity ? "detailed"
, options ? "/p:Configuration=Debug;Platform=Win32"
, assemblyInputs ? []
, preBuild ? ""
, modifyPublicMain ? false
, mainClassFile ? null
}:

assert modifyPublicMain -> mainClassFile != null;

stdenv.mkDerivation {
  inherit name src;
  
  buildInputs = [ dotnetfx ];  

  preConfigure = ''
    cd ${baseDir}
  '';
  
  preBuild = ''
    ${stdenv.lib.optionalString modifyPublicMain ''
      sed -i -e "s|static void Main|public static void Main|" ${mainClassFile}
    ''}
    ${preBuild}
  '';
  
  installPhase = ''
    addDeps()
    {
	if [ -f $1/nix-support/dotnet-assemblies ]
	then
	    for i in $(cat $1/nix-support/dotnet-assemblies)
	    do
		windowsPath=$(cygpath --windows $i)
		assemblySearchPaths="$assemblySearchPaths;$windowsPath"
		
		addDeps $i
	    done
	fi
    }
    
    for i in ${toString assemblyInputs}
    do
	windowsPath=$(cygpath --windows $i) 
	echo "Using assembly path: $windowsPath"
	
	if [ "$assemblySearchPaths" = "" ]
	then
	    assemblySearchPaths="$windowsPath"
	else
	    assemblySearchPaths="$assemblySearchPaths;$windowsPath"
	fi
	
	addDeps $i
    done
      
    echo "Assembly search paths are: $assemblySearchPaths"
    
    if [ "$assemblySearchPaths" != "" ]
    then
	echo "Using assembly search paths args: $assemblySearchPathsArg"
	export AssemblySearchPaths=$assemblySearchPaths
    fi
    
    mkdir -p $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.
    
    mkdir -p $out/nix-support
    
    for i in ${toString assemblyInputs}
    do
        echo $i >> $out/nix-support/dotnet-assemblies
    done
  '';
}