Ejemplo n.º 1
0
        public void Clean(Project project)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            if (_cleanedProjects.Contains(project.FullPath))
            {
                return;
            }

            _cleanedProjects.Add(project.FullPath);

            if (_target != null)
            {
                using (var driver = new BuildDriver(Log.GetQuieterLog(), _target,
                                                    new BuildOptions {
                    Configuration = _configuration
                },
                                                    project, project.Config))
                    driver.Clean();
            }
            else
            {
                Disk.DeleteDirectory(project.BuildDirectory);
                Disk.DeleteDirectory(project.CacheDirectory);

                // Remove files installed by stuff
                Installer.CleanAll(Log,
                                   project.StuffFiles.Select(
                                       x => Path.Combine(project.RootDirectory, x.NativePath)));

                foreach (var pref in project.ProjectReferences)
                {
                    Clean(Project.Load(Path.Combine(project.RootDirectory, pref.ProjectPath)));
                }
            }
        }
Ejemplo n.º 2
0
        public BuildResult Build(Project project)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            var config = project.Config;

            if (_options.UpdateLibrary ?? config.GetBool("IsSourceTree"))
            {
                new LibraryBuilder(Log).Build(config);
            }

            try
            {
                var startTime = Log.Time;
                using (var driver = new BuildDriver(Log, _target, _options, project, config))
                {
                    BackendResult result = null;
                    if (driver.IsUpToDate)
                    {
                        driver.StopAnim();
                        if (Log.IsVerbose)
                        {
                            Log.Skip();
                        }
                        Log.WriteLine("Target is up-to-date -- stopping build (pass --force to override)");
                    }
                    else
                    {
                        result = driver.Build();
                    }

                    if (!Log.HasErrors && driver.CanBuildNative)
                    {
                        driver.BuildNative();
                    }

                    var product = driver.ProductPath;
                    if (!Log.HasErrors && !string.IsNullOrEmpty(product) && (
                            File.Exists(product) || Directory.Exists(product)
                            ))
                    {
                        Log.Skip(true);
                        Log.WriteLine($"  {project.Name} -> {product.ToRelativePath()}");
                    }

                    Log.BuildCompleted(startTime);

                    if (_options.PrintInternals)
                    {
                        driver.PrintInternals();
                    }

                    return(driver.GetResult(result));
                }
            }
            catch (ThreadAbortException e)
            {
                Log.Trace(e);
                Log.Skip();
                Log.WriteLine("Aborted!");
                return(BuildResult.Error(Log, project, _target, true));
            }
            catch (MaxErrorException e)
            {
                Log.Trace(e);
                Log.WriteErrorLine("FATAL ERROR: Max error count (" + Log.ErrorCount + ") reached -- stopping build");
                return(BuildResult.Error(Log, project, _target));
            }
            catch (FatalException e)
            {
                Log.Trace(e);
                Log.FatalError(e.Source, e.ErrorCode, e.Message);
                return(BuildResult.Error(Log, project, _target));
            }
            catch (SourceException e)
            {
                Log.Trace(e);
                Log.FatalError(e.Source, null, "Exception: " + e.Message + " (pass --trace for stack trace)");
                return(BuildResult.Error(Log, project, _target));
            }
            catch (TargetInvocationException e)
            {
                Log.Trace(e);
                Log.Skip();
                Log.WriteErrorLine("FATAL ERROR: " + e.InnerException.Message + " (pass --trace for stack trace)");
                return(BuildResult.Error(Log, project, _target));
            }
            catch (Exception e)
            {
                Log.Trace(e);
                Log.Skip();
                Log.WriteErrorLine("FATAL ERROR: " + e.Message + " (pass --trace for stack trace)");
                return(BuildResult.Error(Log, project, _target));
            }
        }