Example #1
0
        public void TestFailure1()
        {
            var p1 = new Project {
                Filename = @"C:\1"
            };
            var p2 = new Project {
                Filename = @"C:\2"
            };

            _graph.Add(p1, new BuildEnvironment());
            _graph.Add(p2, new BuildEnvironment());
            _graph.AddDependency(p2, p1);

            Project          next;
            BuildEnvironment unused;

            _graph.TryGetNextProject(out next, out unused).Should().BeTrue();
            next.Should().Be(p1);

            _graph.MarkAsFailed(p1);
            _graph.FailedCount.Should().Be(1);
            _graph.TryGetNextProject(out next, out unused)
            .Should()
            .BeFalse("because p2 depends on p1 and because the latter has failed, the former may not be build next");

            _graph.FinishedEvent.Wait(TimeSpan.Zero).Should().BeTrue("Because no more projects can be build");
        }
Example #2
0
        private ProjectDependencyGraph Evaluate(List <Project> rootProjects, BuildEnvironment environment)
        {
            var projectStack = new Stack <Tmp>(rootProjects.Count);

            foreach (var project in rootProjects)
            {
                projectStack.Push(new Tmp {
                    Project = project
                });
            }

            var graph = new ProjectDependencyGraph();

            while (projectStack.Count > 0)
            {
                var pair        = projectStack.Pop();
                var rootProject = pair.Project;

                // Evaluating a project means determining the values of properties, the
                // presence of nodes, etc...
                // Properties of a project (for example $(Configuration)) are written
                // back to the environment, but we don't want to one project's enviroment
                // to interfere with the next one, thus we create one environment for each
                // project.
                var projectEnvironment = new BuildEnvironment(environment);
                var evaluated          = _expressionEngine.Evaluate(rootProject.Merged(_buildScript), projectEnvironment);
                graph.Add(evaluated, projectEnvironment);

                if (pair.NeededBy != null)
                {
                    graph.AddDependency(pair.NeededBy, evaluated);
                }

                // Now that we've evaluated the project it's time to find out if it references
                // any other projects. This is done afterwards because dependencies might be conditional
                // and thus we won't know the dependencies until after evaluating them against the
                // current build environment.
                // Anyways, we'll simply add any referenced project to the list of projects so that
                // we can build all the things!
                var references = projectEnvironment.Items.Where(x => x.Type == Items.ProjectReference);
                foreach (var reference in references)
                {
                    var path = reference.Include;
                    if (!Path.IsPathRooted(path))
                    {
                        path = Path.Combine(projectEnvironment.Properties[Properties.MSBuildProjectDirectory], path);
                    }
                    path = Path.Normalize(path);

                    if (!graph.Contains(path))
                    {
                        var project = _csharpProjectParser.Parse(path);
                        projectStack.Push(new Tmp
                        {
                            Project  = project,
                            NeededBy = evaluated
                        });
                    }
                }
            }

            return(graph);
        }