@@ -34,16 +34,6 @@ public enum Steps
3434 public const string MetadataXmlSubDir = "metadata" ;
3535 public const string CSharpSourcesSubDir = "csharp" ;
3636
37- public static string [ ] StubPartialSources =>
38- Directory . GetFiles ( Path . Combine ( ThisAssemblyDirectory , "SupportFiles" ) , "*.cs" )
39- . Where ( cs => cs . IndexOf ( "Java_Lang_" , StringComparison . OrdinalIgnoreCase ) < 0 )
40- . Where ( cs => ! string . Equals ( Path . GetFileName ( cs ) , "JavaObject.cs" , StringComparison . OrdinalIgnoreCase ) )
41- . ToArray ( ) ;
42- public static string [ ] StubAllSources =>
43- Directory . GetFiles ( Path . Combine ( ThisAssemblyDirectory , "SupportFiles" ) , "*.cs" ) ;
44-
45- static string ThisAssemblyDirectory => Path . GetDirectoryName ( new Uri ( typeof ( BindingBuilder ) . Assembly . CodeBase ) . LocalPath ) ;
46-
4737 public Steps ProcessSteps { get ; set ; } = Steps . All ;
4838
4939 // entire work (intermediate output) directory
@@ -52,24 +42,7 @@ public enum Steps
5242 // Used to resolve javac and rt.jar
5343 public string JdkPath { get ; set ; }
5444
55- public string GeneratorPath { get ; set ; } = Path . Combine ( ThisAssemblyDirectory , "generator.exe" ) ;
56-
57- public bool UseSystemCsc { get ; set ; } // we don't have to default to csc-dim, but why "not" ?
58-
59- public string CscPath { get ; set ; }
60-
61- static string GetMscorlibPath ( ) => new Uri ( typeof ( object ) . Assembly . CodeBase ) . LocalPath ;
62-
63- static string ProbeCscDimPath ( )
64- {
65- // For Windows, use nuget package. For Mac/Linux, use SYSMONO dim/csc.exe.
66- if ( Environment . OSVersion . Platform == PlatformID . Win32NT )
67- return Path . Combine ( ".." , ".." , ".." , "packages" , "xamarin.android.csc.dim.0.1.2" , "tools" , "csc.exe" ) ;
68- // assume path relative to framework dll in the GAC.
69- return Path . GetFullPath ( Path . Combine ( GetMscorlibPath ( ) , ".." , "dim" , "csc.exe" ) ) ;
70- }
71-
72- static string GetSystemRuntimeDll ( ) => Path . Combine ( Path . GetDirectoryName ( GetMscorlibPath ( ) ) , "Facades" , "System.Runtime.dll" ) ;
45+ public string GeneratorPath { get ; set ; } = Path . Combine ( Path . GetDirectoryName ( new Uri ( typeof ( BindingBuilder ) . Assembly . CodeBase ) . LocalPath ) , "generator.exe" ) ;
7346
7447 static string ProbeJavaHome ( )
7548 {
@@ -81,10 +54,7 @@ static string ProbeJavaHome ()
8154
8255 public static BindingBuilder CreateBestBetDefault ( BindingProject project )
8356 {
84- return new BindingBuilder ( project ) {
85- JdkPath = ProbeJavaHome ( ) ,
86- CscPath = ProbeCscDimPath ( ) ,
87- } ;
57+ return new BindingBuilder ( project ) { JdkPath = ProbeJavaHome ( ) } ;
8858 }
8959
9060 public BindingBuilder ( BindingProject project )
@@ -155,8 +125,8 @@ void Javac ()
155125 project . JavacExecutionOutput = $ "Execute javac as: { psi . FileName } { psi . Arguments } \n ";
156126
157127 var proc = new Process ( ) { StartInfo = psi } ;
158- proc . OutputDataReceived += ( sender , e ) => project . JavacExecutionOutput += e . Data + ' \n ' ;
159- proc . ErrorDataReceived += ( sender , e ) => project . JavacExecutionOutput += e . Data + ' \n ' ;
128+ proc . OutputDataReceived += ( sender , e ) => project . JavacExecutionOutput += e . Data ;
129+ proc . ErrorDataReceived += ( sender , e ) => project . JavacExecutionOutput += e . Data ;
160130 proc . Start ( ) ;
161131 proc . BeginOutputReadLine ( ) ;
162132 proc . BeginErrorReadLine ( ) ;
@@ -190,8 +160,8 @@ void Jar ()
190160 project . JarExecutionOutput = $ "Execute jar as: { psi . FileName } { psi . Arguments } \n ";
191161
192162 var proc = new Process ( ) { StartInfo = psi } ;
193- proc . OutputDataReceived += ( sender , e ) => project . JarExecutionOutput += e . Data + ' \n ' ;
194- proc . ErrorDataReceived += ( sender , e ) => project . JarExecutionOutput += e . Data + ' \n ' ;
163+ proc . OutputDataReceived += ( sender , e ) => project . JarExecutionOutput += e . Data ;
164+ proc . ErrorDataReceived += ( sender , e ) => project . JarExecutionOutput += e . Data ;
195165 proc . Start ( ) ;
196166 proc . BeginOutputReadLine ( ) ;
197167 proc . BeginErrorReadLine ( ) ;
@@ -305,8 +275,8 @@ void GenerateBindingSources ()
305275 project . GeneratorExecutionOutput = $ "Execute generator as: { psi . FileName } { psi . Arguments } \n ";
306276
307277 var proc = new Process ( ) { StartInfo = psi } ;
308- proc . OutputDataReceived += ( sender , e ) => project . GeneratorExecutionOutput += e . Data + ' \n ' ;
309- proc . ErrorDataReceived += ( sender , e ) => project . GeneratorExecutionOutput += e . Data + ' \n ' ;
278+ proc . OutputDataReceived += ( sender , e ) => project . GeneratorExecutionOutput += e . Data ;
279+ proc . ErrorDataReceived += ( sender , e ) => project . GeneratorExecutionOutput += e . Data ;
310280 proc . Start ( ) ;
311281 proc . BeginOutputReadLine ( ) ;
312282 proc . BeginErrorReadLine ( ) ;
@@ -317,63 +287,6 @@ void GenerateBindingSources ()
317287
318288 void CompileBindings ( )
319289 {
320- if ( ( ProcessSteps & Steps . Csc ) == 0 )
321- return ;
322-
323- if ( CscPath == null )
324- throw new InvalidOperationException ( "CscPath is not set." ) ;
325-
326- var objDir = IntermediateOutputPathAbsolute ;
327- EnsureDirectory ( objDir ) ;
328-
329- if ( project . GeneratedCSharpSourceFiles == null )
330- project . GeneratedCSharpSourceDirectory = Path . Combine ( objDir , CSharpSourcesSubDir ) ;
331- if ( ! Directory . GetFiles ( project . GeneratedCSharpSourceDirectory , "*.cs" ) . Any ( ) && ! project . CSharpSourceFiles . Any ( ) && ! project . CSharpSourceStrings . Any ( ) )
332- throw new InvalidOperationException ( "No C# sources exist." ) ;
333- if ( project . GeneratedDllFile == null )
334- project . GeneratedDllFile = Path . Combine ( objDir , project . Id + ".dll" ) ;
335-
336- foreach ( var item in project . CSharpSourceStrings )
337- File . WriteAllText ( Path . Combine ( project . GeneratedCSharpSourceDirectory , item . FileName ) , item . Content ) ;
338- var csFiles = project . CSharpSourceFiles . AsEnumerable ( ) ;
339-
340- switch ( project . CSharpStubUsage ) {
341- case CSharpStubUsage . Partial :
342- csFiles = csFiles . Concat ( StubPartialSources ) ;
343- break ;
344- case CSharpStubUsage . Full :
345- csFiles = csFiles . Concat ( StubAllSources ) ;
346- break ;
347- }
348-
349- string localSystemRuntime = Path . Combine ( ThisAssemblyDirectory , "System.Runtime.dll" ) ;
350- if ( ! File . Exists ( localSystemRuntime ) )
351- File . Copy ( GetSystemRuntimeDll ( ) , localSystemRuntime ) ;
352-
353- var psi = new ProcessStartInfo ( ) {
354- UseShellExecute = false ,
355- FileName = UseSystemCsc ? "csc" : CscPath ,
356- Arguments = $ " -t:library -unsafe" +
357- $ " -out:\" { project . GeneratedDllFile } \" { project . GeneratedCSharpSourceDirectory } { Path . DirectorySeparatorChar } *.cs " +
358- $ " { string . Join ( " " , csFiles . Select ( s => '"' + s + '"' ) ) } " +
359- $ " -r:{ ThisAssemblyDirectory } { Path . DirectorySeparatorChar } System.Runtime.dll" +
360- $ " -r:{ ThisAssemblyDirectory } { Path . DirectorySeparatorChar } Java.Interop.dll" +
361- $ " { string . Join ( " " , project . ReferenceDlls . Select ( s => " -r \" " + s + '"' ) ) } ",
362- RedirectStandardOutput = true ,
363- RedirectStandardError = true ,
364- } ;
365-
366- project . CscExecutionOutput = $ "Execute csc as: { psi . FileName } { psi . Arguments } \n ";
367-
368- var proc = new Process ( ) { StartInfo = psi } ;
369- proc . OutputDataReceived += ( sender , e ) => project . CscExecutionOutput += e . Data + '\n ' ;
370- proc . ErrorDataReceived += ( sender , e ) => project . CscExecutionOutput += e . Data + '\n ' ;
371- proc . Start ( ) ;
372- proc . BeginOutputReadLine ( ) ;
373- proc . BeginErrorReadLine ( ) ;
374- proc . WaitForExit ( ) ;
375- if ( proc . ExitCode != 0 )
376- throw new Exception ( "csc failed: " + project . CscExecutionOutput ) ;
377290 }
378291 }
379292}
0 commit comments