Exemplo n.º 1
0
        private BuildTargetResult ExecTarget(BuildTarget target)
        {
            var sectionName = $"{target.Name.PadRight(_maxTargetLen + 2).Yellow()} ({target.Source.White()})";

            BuildReporter.BeginSection("TARGET", sectionName);

            BuildTargetResult result;

            // Run the dependencies
            var dependencyResults      = new Dictionary <string, BuildTargetResult>();
            var failedDependencyResult = RunDependencies(target, dependencyResults);

            if (failedDependencyResult != null)
            {
                result = failedDependencyResult;
            }
            else if (target.Body != null)
            {
                try
                {
                    result = target.Body(new BuildTargetContext(this, target, dependencyResults));
                }
                catch (Exception ex)
                {
                    result = new BuildTargetResult(target, success: false, exception: ex);
                }
            }
            else
            {
                result = new BuildTargetResult(target, success: true);
            }
            BuildReporter.EndSection("TARGET", sectionName, result.Success);

            return(result);
        }
Exemplo n.º 2
0
        public int Run(string[] args)
        {
            string[] targets;
            string[] environmentVariables;
            ParseArgs(args, out targets, out environmentVariables);

            foreach (string environmentVariable in environmentVariables)
            {
                int    delimiterIndex = environmentVariable.IndexOf('=');
                string name           = environmentVariable.Substring(0, delimiterIndex);
                string value          = environmentVariable.Substring(delimiterIndex + 1);

                Environment.SetEnvironmentVariable(name, value);
            }

            Reporter.Output.WriteBanner($"Building {ProductName}");

            if (_overrides.Any())
            {
                foreach (var targetOverride in _overrides)
                {
                    Reporter.Verbose.WriteLine($"Target {targetOverride.Name} from {targetOverride.OriginalSource} was overridden in {targetOverride.OverrideSource}".Black());
                }
            }

            var context = new BuildContext(_targets, Directory.GetCurrentDirectory());
            BuildTargetResult result = null;

            try
            {
                foreach (var target in targets)
                {
                    result = context.RunTarget(target);
                    if (!result.Success)
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Reporter.Error.WriteLine(ex.ToString().Red());
                return(1);
            }

            if (result != null && !result.Success)
            {
                Reporter.Error.WriteLine($"Build failed: {result.ErrorMessage}".Red());
                return(1);
            }
            else
            {
                Reporter.Output.WriteLine("Build succeeded".Green());
                return(0);
            }
        }
Exemplo n.º 3
0
        public int Run(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            var targets = new[] { BuildContext.DefaultTarget };

            if (args.Length > 0)
            {
                targets = args;
            }

            Reporter.Output.WriteBanner($"Building {ProductName}");

            if (_overrides.Any())
            {
                foreach (var targetOverride in _overrides)
                {
                    Reporter.Verbose.WriteLine($"Target {targetOverride.Name} from {targetOverride.OriginalSource} was overridden in {targetOverride.OverrideSource}".Black());
                }
            }

            var context = new BuildContext(_targets, Directory.GetCurrentDirectory());
            BuildTargetResult result = null;

            try
            {
                foreach (var target in targets)
                {
                    result = context.RunTarget(target);
                    if (!result.Success)
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Reporter.Error.WriteLine(ex.ToString().Red());
                return(1);
            }

            if (result != null && !result.Success)
            {
                Reporter.Error.WriteLine($"Build failed: {result.ErrorMessage}".Red());
                return(1);
            }
            else
            {
                Reporter.Output.WriteLine("Build succeeded".Green());
                return(0);
            }
        }
Exemplo n.º 4
0
        private BuildTargetResult RunDependencies(BuildTarget target, Dictionary <string, BuildTargetResult> dependencyResults)
        {
            BuildTargetResult result = null;

            foreach (var dependency in target.Dependencies)
            {
                result = RunTarget(dependency);
                dependencyResults[dependency] = result;

                if (!result.Success)
                {
                    return(result);
                }
            }

            return(null);
        }