Esempio n. 1
0
        public Optional <ProjectBuild> TryBuild(BuildProject args, Log logger)
        {
            try
            {
                var project = _simulatorBuilder.CreateSimulatorProject(args);

                var libraryBuilder = new LibraryBuilder(new Disk(logger), BuildTargets.Package)
                {
                    Express = true
                };
                var projectBuilder = new ProjectBuilder(logger, new LocalSimulatorTarget(), project.Options);

                if (project.IsVerboseBuild)
                {
                    logger.Level = Uno.Logging.LogLevel.Verbose;
                }

                if (project.BuildLibraries)
                {
                    libraryBuilder.Build();
                }

                var buildResult = projectBuilder.Build(project.Project);

                if (buildResult.ErrorCount != 0)
                {
                    return(Optional.None());
                }

                var b = new LocalBuild(buildResult, AbsoluteFilePath.Parse(args.ProjectPath));
                return(new ProjectBuild(b.Path.NativePath, b.SaveSimulatorMetadata(_fileSystem).NativePath, b.GetTypeInformation()));
            }
            catch (ThreadAbortException)
            {
            }
            catch (SourceException e)
            {
                logger.Error(e.Source, null, e.Message);
            }
            catch (Exception e)
            {
                logger.Error(e.Message);
            }
            return(Optional.None());
        }
Esempio n. 2
0
        /// <exception cref="BuildFailed"></exception>
        /// <exception cref="FailedToCreateOutputDir"></exception>
        public System.Threading.Tasks.Task <BuildResult> BuildUno(Guid id, BuildProject args, PreviewTarget previewTarget, bool driectToDevice, CancellationToken cancellationToken, bool quitAfterApkLaunch)
        {
            args.Id = id;

            var loggedEvents = new AccumulatingProgress <IBinaryMessage>(_buildEvents);
            var errorList    = new ErrorListAdapter(id, loggedEvents);
            var textWriter   = new TextWriterAdapter(id, loggedEvents);

            var tcs = new TaskCompletionSource <BuildResult>();

            var project = _simulatorBuilder.CreateSimulatorProject(args, previewTarget, driectToDevice, quitAfterApkLaunch);

            var thread = new Thread(
                () =>
            {
                var logger = new Log(errorList, textWriter);
                if (project.IsVerboseBuild)
                {
                    logger.Level = Uno.Logging.LogLevel.Verbose;
                }

                if (project.BuildLibraries)
                {
                    new LibraryBuilder(new Disk(logger), BuildTargets.Package)
                    {
                        Express = true
                    }
                }
                .Build();

                var buildTarget = GetBuildTarget(previewTarget);

                //BuildTarget target;
                //Enum.TryParse(buildTarget.Identifier, true, out target);

                _buildEvents.Report(
                    new Started
                {
                    Command = args
                });

                var faulty = false;
                try
                {
                    var buildResult =
                        new ProjectBuilder(
                            logger,
                            buildTarget,
                            project.Options)
                        .Build(project.Project);

                    if (buildResult.ErrorCount != 0)
                    {
                        _errorHelpers.OnBuildFailed(buildResult);

                        tcs.SetException(new UserCodeContainsErrors());
                    }
                    else
                    {
                        tcs.SetResult(buildResult);
                    }
                }
                catch (Exception e)
                {
                    if (e is ThreadAbortException)
                    {
                        return;
                    }

                    tcs.TrySetException(new InternalBuildError(e));
                    faulty = true;
                }
                finally
                {
                    _buildEvents.Report(
                        new Ended
                    {
                        Command        = args,
                        Success        = !faulty,
                        BuildDirectory = AbsoluteDirectoryPath.Parse(project.Project.OutputDirectory)
                    });
                }
            })