2using System.Collections.Generic;
3using System.Diagnostics;
6using System.Runtime.InteropServices;
8using System.Threading.Tasks;
24 static readonly
string TOOLNAME =
"ikvmstub";
25 static readonly
string TOOLPATH = typeof(
IkvmExporterLauncher).Assembly.Location is
string s ? Path.GetDirectoryName(s) ??
"" :
"";
33 base(TOOLNAME, toolPath, listener)
43 this(TOOLPATH, listener)
68 throw new ArgumentNullException(nameof(options));
70 var args =
new List<string>();
72 if (options.
Output is not
null)
82 args.Add(
"--reference");
100 args.Add(
"--nostdlib");
103 args.Add(
"--forwarders");
106 args.Add(
"--non-public-types");
109 args.Add(
"--non-public-interfaces");
112 args.Add(
"--non-public-members");
115 args.Add(
"--parameters");
118 args.Add(
"--bootstrap");
120 if (options.
Lib is not
null)
122 foreach (var i
in options.
Lib)
130 args.Add(
"--skiperror");
133 args.Add(
"json,file=stderr");
135 if (options.
Input is not
null)
136 args.Add(options.
Input);
139 var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken,
new CancellationToken());
143 if (options.
Timeout != Timeout.Infinite)
144 ctk = CancellationTokenSource.CreateLinkedTokenSource(ctk,
new CancellationTokenSource(options.
Timeout).Token).Token;
151 if (exe is
null || File.Exists(exe) ==
false)
152 throw new FileNotFoundException($
"Could not locate tool at '{exe}'.");
155 if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
158 if (exe.EndsWith(
".exe"))
168 var psx = Mono.Unix.UnixFileSystemInfo.GetFileSystemEntry(exe);
169 if (psx.FileAccessPermissions.HasFlag(Mono.Unix.FileAccessPermissions.UserExecute) ==
false)
170 psx.FileAccessPermissions |= Mono.Unix.FileAccessPermissions.UserExecute;
174 throw new IkvmToolException($
"Could not set user executable bit on '{exe}'.", e);
183 cli = Cli.Wrap(wrap);
190 cli = cli.WithWorkingDirectory(Environment.CurrentDirectory);
191 cli = cli.WithArguments(args);
192 cli = cli.WithValidation(CommandResultValidation.None);
198 cli = cli.WithStandardErrorPipe(PipeTarget.ToDelegate(l =>
ParseAndLogEventAsync(l, cancellationToken).AsTask()));
201 var pid = cli.ExecuteAsync(ctk);
204 if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
207 if (pid.Task.IsCompleted ==
false)