/// <exception cref="InvalidPath" /> /// <exception cref="System.Security.SecurityException" /> /// <exception cref="ProjectNotFound" /> public PreviewArguments Resolve(List <string> mutableArgs) { var compileOnly = mutableArgs .Remove("--compile-only"); var directToDevice = mutableArgs .Remove("--direct-to-device"); var quitAfterApkLaunch = mutableArgs .Remove("--quit-after-apk-launch"); var project = mutableArgs .TryRemoveAt(0) .Select(_fileSystem.ResolveAbsolutePath); var defines = mutableArgs .Where(a => a.StartsWith("-D")) .Select(a => a.Substring("-D".Length)) .ToImmutableList(); mutableArgs.RemoveAll(a => a.StartsWith("-D")); return(new PreviewArguments( project: _projects.GetCurrentProject(project), compileOnly: compileOnly, directToDevice: directToDevice, defines: defines, quitAfterApkLaunch: quitAfterApkLaunch)); }
public override void Run(string[] args, CancellationToken ct) { _report.Info("Building with arguments '" + string.Join(" ", args) + "'"); try { using (var client = _daemonSpawner.ConnectOrSpawn( identifier: "Builder", timeout: TimeSpan.FromMinutes(1))) { Func <string, Optional <string> > parseNameArg = s => TryParseArg("n", "name", s); Func <string, Optional <string> > parseTargetArg = s => TryParseArg("t", "target", s); Func <Optional <string>, BuildTarget> targetToTargetEnum = s => { if (!s.HasValue) { return(BuildTarget.Unknown); } try { return((BuildTarget)Enum.Parse(typeof(BuildTarget), s.Value)); } catch (ArgumentException) { return(BuildTarget.Unknown); } }; var nameArgs = args.Select(parseNameArg).NotNone(); var nameArg = nameArgs.FirstOrNone(); var targetArgs = args.Select(parseTargetArg).NotNone(); var targetArg = targetArgs.FirstOrNone(); args = args.Where(s => !parseNameArg(s).HasValue).ToArray(); //uno does not accept name arg so strip it var buildId = Guid.NewGuid(); //_report.Info(string.Format("Calling '{0} {1}', with buildId '{2}'", startInfo.FileName, startInfo.Arguments, buildId)); var maybeFileOrProject = args .FirstOrNone(a => !a.StartsWith("-")) .Select(_fileSystem.ResolveAbsolutePath); var projPath = _projectDetector.GetCurrentProject(maybeFileOrProject); var target = targetToTargetEnum(targetArg); client.Broadcast( new BuildStartedData { BuildId = buildId, Target = target, BuildType = BuildTypeData.FullCompile, ProjectId = ProjectIdComputer.IdFor(projPath), ProjectPath = projPath.NativePath, BuildTag = nameArg.Or("") }); var outputData = new Subject <string>(); var errorData = new Subject <string>(); // ReSharper disable once AccessToDisposedClosure using (Observable.Merge(outputData, errorData).Subscribe(line => BroadCastBuildLog(line, client, buildId))) using (outputData.Select(line => line + "\n").Subscribe(_outWriter.Write)) using (errorData.Select(line => line + "\n").Subscribe(_errorWriter.Write)) { Process proc; try { proc = _uno.Start(new ProcessStartInfo { WindowStyle = ProcessWindowStyle.Hidden, Arguments = "build " + args.Select( s => { if (s.EndsWith("\\")) { return("\"" + s + " \""); } else { return("\"" + s + "\""); } }).Join(" "), RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false }); } catch (Exception e) { throw new FailedToStartBuild(e); } proc.ConsumeOutAndErr(outputData, errorData).Wait(); proc.WaitForExit(); var status = proc.ExitCode == 0 ? BuildStatus.Success : BuildStatus.Error; client.Broadcast( new BuildEndedData { BuildId = buildId, Status = status }); if (status == BuildStatus.Success) { _report.Info("Build " + buildId + " succeeded"); } else { _report.Error("Build " + buildId + " failed"); throw new UserCodeContainsErrors(); } } } } catch (DaemonException e) { throw new ExitWithError(e.Message); } catch (InvalidPath e) { throw new ExitWithError(e.Message); } catch (SecurityException e) { throw new ExitWithError(e.Message); } catch (ProjectNotFound e) { throw new ExitWithError(e.Message); } catch (FailedToStartBuild e) { throw new ExitWithError(e.Message); } catch (UserCodeContainsErrors e) { throw new ExitWithError(e.Message); } }
/// <exception cref="ExitWithError" /> public override void Run(string[] args, CancellationToken ct) { try { var list = false; var type = Optional.None <string>(); var maybeProject = Optional.None <IAbsolutePath>(); var options = CreateOptions( type: s => type = s, project: s => maybeProject = Optional.Some(_fileSystem.ResolveAbsolutePath(s)), list: s => list = (s != null)); var remainingArgs = options.Parse(args); if (remainingArgs.Count < 1) { WriteUsage(Console.Error); return; } var project = _projectDetector.GetCurrentProject(maybeProject); var file = _fileSystem.ResolveAbsolutePath(remainingArgs[0]); if (list) { var supportedOperations = _operations.Where(o => o.CanExecute(file, project)).ToArray(); Console.Out.WriteLine( supportedOperations.Length == 0 ? "This file can not be imported by Fuse" : ListOperations(supportedOperations)); return; } ImportOperation operation; if (type.HasValue) { operation = _operations .FirstOrNone(op => op.Name.Equals(type.Value, StringComparison.InvariantCultureIgnoreCase)) .OrThrow(new ExitWithError("Unknown operation type `" + type.Value + "`")); } else { var supportedOperations = _operations.Where(o => o.CanExecute(file, project)).ToArray(); if (supportedOperations.Length < 1) { throw new ExitWithError("This file can not be imported by Fuse"); } operation = supportedOperations[0]; } operation.Execute(file, project, remainingArgs); } catch (ProjectNotFound) { throw new ExitWithError("Could not find destination project"); } catch (ImportFailed p) { throw new ExitWithError("Import failed: " + p.Message); } catch (InvalidPath p) { throw new ExitWithError("The path specified is invalid: `" + p.Path + "`"); } }