Beispiel #1
0
        public override bool Execute()
        {
            var packageArtifacts = Artifacts.Select(ArtifactInfo.Parse)
                                   .OfType <ArtifactInfo.Package>()
                                   .Where(p => !p.IsSymbolsArtifact);

            var factory = new SolutionInfoFactory(Log, BuildEngine5);
            var props   = MSBuildListSplitter.GetNamedProperties(Properties);

            Log.LogMessage(MessageImportance.High, $"Beginning cross-repo analysis on {Solutions.Length} solutions. Hang tight...");

            if (!props.TryGetValue("Configuration", out var defaultConfig))
            {
                defaultConfig = "Debug";
            }

            var solutions = factory.Create(Solutions, props, defaultConfig, _cts.Token);

            Log.LogMessage($"Found {solutions.Count} and {solutions.Sum(p => p.Projects.Count)} projects");

            if (_cts.IsCancellationRequested)
            {
                return(false);
            }

            EnsureConsistentGraph(packageArtifacts, solutions);
            RepositoryBuildOrder = GetRepositoryBuildOrder(packageArtifacts, solutions.Where(s => s.ShouldBuild));

            return(!Log.HasLoggedErrors);
        }
Beispiel #2
0
        public override bool Execute()
        {
            var packageArtifacts = Artifacts.Select(ArtifactInfo.Parse)
                                   .OfType <ArtifactInfo.Package>()
                                   .Where(p => !p.IsSymbolsArtifact)
                                   .ToDictionary(p => p.PackageInfo.Id, p => p, StringComparer.OrdinalIgnoreCase);

            var factory = new SolutionInfoFactory(Log, BuildEngine5);
            var props   = MSBuildListSplitter.GetNamedProperties(Properties);

            Log.LogMessage(MessageImportance.High, $"Beginning cross-repo analysis on {Solutions.Length} solutions. Hang tight...");

            if (!props.TryGetValue("Configuration", out var defaultConfig))
            {
                defaultConfig = "Debug";
            }

            var solutions = factory.Create(Solutions, props, defaultConfig, _cts.Token).OrderBy(f => f.Directory).ToList();

            Log.LogMessage($"Found {solutions.Count} and {solutions.Sum(p => p.Projects.Count)} projects");

            if (_cts.IsCancellationRequested)
            {
                return(false);
            }

            return(GenerateGraph(packageArtifacts, solutions));
        }
        public void ThrowsForBadConfigName()
        {
            File.WriteAllText(_slnFile, @"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
EndGlobal
".Replace('`', '"'));

            Assert.Throws <InvalidOperationException>(() => SolutionInfoFactory.Create(_slnFile, "Release"));
        }
Beispiel #4
0
        public override bool Execute()
        {
            var packageArtifacts = Artifacts.Select(ArtifactInfo.Parse)
                                   .OfType <ArtifactInfo.Package>()
                                   .Where(p => !p.IsSymbolsArtifact);

            var factory = new SolutionInfoFactory(Log, BuildEngine5);
            var props   = MSBuildListSplitter.GetNamedProperties(Properties);

            Log.LogMessage(MessageImportance.High, $"Beginning cross-repo analysis on {Solutions.Length} solutions. Hang tight...");

            if (!props.TryGetValue("Configuration", out var defaultConfig))
            {
                defaultConfig = "Debug";
            }

            var solutions = factory.Create(Solutions, props, defaultConfig, _cts.Token);

            Log.LogMessage($"Found {solutions.Count} and {solutions.Sum(p => p.Projects.Count)} projects");

            var policies = new Dictionary <string, PatchPolicy>();

            foreach (var repo in Repositories)
            {
                policies.Add(repo.ItemSpec, Enum.Parse <PatchPolicy>(repo.GetMetadata("PatchPolicy")));
            }

            foreach (var solution in solutions)
            {
                var repoName = Path.GetFileName(solution.Directory);
                solution.PatchPolicy = policies[repoName];
            }

            if (_cts.IsCancellationRequested)
            {
                return(false);
            }

            EnsureConsistentGraph(packageArtifacts, solutions);
            RepositoryBuildOrder = GetRepositoryBuildOrder(packageArtifacts, solutions.Where(s => s.ShouldBuild));

            return(!Log.HasLoggedErrors);
        }
        public void FindsProjectsByDefaultConfiguration(string config, string[] projects)
        {
            File.WriteAllText(_slnFile, @"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project(`{2150E333-8FDC-42A3-9474-1A3956D46DE8}`) = `src`, `src`, `{6BC8A037-601B-412E-B394-92F55C01C7A6}`
EndProject
Project(`{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}`) = `ClassLib1`, `src\ClassLib1\ClassLib1.csproj`, `{89EF0B05-98D4-4C4D-8870-718571091F79}`
EndProject
Project(`{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}`) = `VsixProject`, `src\VsixProject\VsixProject.csproj`, `{86986537-8DF5-423F-A3A8-0CA568A9FFC4}`
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		DebugNoVSIX|Any CPU = DebugNoVSIX|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{89EF0B05-98D4-4C4D-8870-718571091F79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{89EF0B05-98D4-4C4D-8870-718571091F79}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{86986537-8DF5-423F-A3A8-0CA568A9FFC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{86986537-8DF5-423F-A3A8-0CA568A9FFC4}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{89EF0B05-98D4-4C4D-8870-718571091F79}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU
		{89EF0B05-98D4-4C4D-8870-718571091F79}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU
		{86986537-8DF5-423F-A3A8-0CA568A9FFC4}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU
	EndGlobalSection
	GlobalSection(NestedProjects) = preSolution
		{89EF0B05-98D4-4C4D-8870-718571091F79} = {6BC8A037-601B-412E-B394-92F55C01C7A6}
		{86986537-8DF5-423F-A3A8-0CA568A9FFC4} = {6BC8A037-601B-412E-B394-92F55C01C7A6}
	EndGlobalSection
EndGlobal
".Replace('`', '"'));

            var solution = SolutionInfoFactory.Create(_slnFile, config);

            Assert.Equal(projects.Length, solution.Projects.Count);
            Assert.All(projects, expected => Assert.Contains(solution.Projects, proj => Path.GetFileNameWithoutExtension(proj) == expected));
        }
Beispiel #6
0
        public override bool Execute()
        {
            var packageArtifacts = Artifacts.Select(ArtifactInfo.Parse)
                                   .OfType <ArtifactInfo.Package>()
                                   .Where(p => !p.IsSymbolsArtifact)
                                   .ToDictionary(p => p.PackageInfo.Id, p => p, StringComparer.OrdinalIgnoreCase);

            var factory = new SolutionInfoFactory(Log, BuildEngine5);
            var props   = MSBuildListSplitter.GetNamedProperties(Properties);

            if (!props.TryGetValue("Configuration", out var defaultConfig))
            {
                defaultConfig = "Debug";
            }

            var solutions = factory.Create(Solutions, props, defaultConfig, _cts.Token).OrderBy(f => f.Directory).ToList();

            Log.LogMessage($"Found {solutions.Count} and {solutions.Sum(p => p.Projects.Count)} projects");

            if (_cts.IsCancellationRequested)
            {
                return(false);
            }

            var repoGraph           = new AdjacencyMatrix(solutions.Count);
            var packageToProjectMap = new Dictionary <PackageIdentity, ProjectInfo>();

            for (var i = 0; i < solutions.Count; i++)
            {
                var sln = repoGraph[i] = solutions[i];

                foreach (var proj in sln.Projects)
                {
                    if (!proj.IsPackable ||
                        proj.FullPath.Contains("samples") ||
                        proj.FullPath.Contains("tools/Microsoft.VisualStudio.Web.CodeGeneration.Design"))
                    {
                        continue;
                    }

                    var id = new PackageIdentity(proj.PackageId, new NuGetVersion(proj.PackageVersion));

                    if (packageToProjectMap.TryGetValue(id, out var otherProj))
                    {
                        Log.LogError($"Both {proj.FullPath} and {otherProj.FullPath} produce {id}");
                        continue;
                    }

                    packageToProjectMap.Add(id, proj);
                }

                var sharedSrc = Path.Combine(sln.Directory, "shared");
                if (Directory.Exists(sharedSrc))
                {
                    foreach (var dir in Directory.GetDirectories(sharedSrc, "*.Sources"))
                    {
                        var id            = GetDirectoryName(dir);
                        var artifactInfo  = packageArtifacts[id];
                        var sharedSrcProj = new ProjectInfo(dir,
                                                            Array.Empty <ProjectFrameworkInfo>(),
                                                            Array.Empty <DotNetCliReferenceInfo>(),
                                                            true,
                                                            artifactInfo.PackageInfo.Id,
                                                            artifactInfo.PackageInfo.Version.ToNormalizedString());
                        sharedSrcProj.SolutionInfo = sln;
                        var identity = new PackageIdentity(artifactInfo.PackageInfo.Id, artifactInfo.PackageInfo.Version);
                        packageToProjectMap.Add(identity, sharedSrcProj);
                    }
                }
            }

            if (Log.HasLoggedErrors)
            {
                return(false);
            }

            for (var i = 0; i < solutions.Count; i++)
            {
                var src = repoGraph[i];

                foreach (var proj in src.Projects)
                {
                    if (!proj.IsPackable ||
                        proj.FullPath.Contains("samples"))
                    {
                        continue;
                    }

                    foreach (var dep in proj.Frameworks.SelectMany(f => f.Dependencies.Values))
                    {
                        if (packageToProjectMap.TryGetValue(new PackageIdentity(dep.Id, new NuGetVersion(dep.Version)), out var target))
                        {
                            var j = repoGraph.FindIndex(target.SolutionInfo);
                            repoGraph.SetLink(i, j);
                        }
                    }

                    foreach (var toolDep in proj.Tools)
                    {
                        if (packageToProjectMap.TryGetValue(new PackageIdentity(toolDep.Id, new NuGetVersion(toolDep.Version)), out var target))
                        {
                            var j = repoGraph.FindIndex(target.SolutionInfo);
                            repoGraph.SetLink(i, j);
                        }
                    }
                }
            }

            var repos = Repositories.ToDictionary(i => i.ItemSpec, i => i, StringComparer.OrdinalIgnoreCase);

            for (var i = 0; i < repoGraph.Count; i++)
            {
                var src      = repoGraph[i];
                var repoName = GetDirectoryName(src.Directory);
                var repo     = repos[repoName];

                for (var j = 0; j < repoGraph.Count; j++)
                {
                    if (j == i)
                    {
                        continue;
                    }
                    if (repoGraph.HasLink(i, j))
                    {
                        var target         = repoGraph[j];
                        var targetRepoName = GetDirectoryName(target.Directory);
                        var targetRepo     = repos[targetRepoName];

                        if (src.Shipped && !target.Shipped)
                        {
                            Log.LogError($"{repoName} cannot depend on {targetRepoName}. Repos marked as 'Shipped' cannot depend on repos that are rebuilding. Update the configuration in submodule.props.");
                        }
                    }
                }
            }

            return(!Log.HasLoggedErrors);
        }