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));
        }
Beispiel #3
0
        public override bool Execute()
        {
            if (Projects == null || Projects.Length == 0)
            {
                Log.LogMessage(MessageImportance.Low, "No projects or solutions were found. Skipping PackageReference validation.");
                return(true);
            }

            if (!File.Exists(DependenciesFile))
            {
                Log.LogKoreBuildError(KoreBuildErrors.DependenciesFileDoesNotExist, $"Expected the dependencies file to exist at {DependenciesFile}");
                return(false);
            }

            if (!DependencyVersionsFile.TryLoad(DependenciesFile, out var depsFile))
            {
                Log.LogError($"Could not load the dependencies file from {DependenciesFile}");
                return(false);
            }

            if (!depsFile.HasVersionsPropertyGroup())
            {
                Log.LogKoreBuildWarning(KoreBuildErrors.PackageRefPropertyGroupNotFound, $"No PropertyGroup with Label=\"{DependencyVersionsFile.PackageVersionsLabel}\" could be found in {DependenciesFile}");
            }

            foreach (var proj in Projects)
            {
                var ext = Path.GetExtension(proj.ItemSpec);
                if (ext == ".sln")
                {
                    var solutionProps = MSBuildListSplitter.GetNamedProperties(Properties);
                    var projectFiles  = Projects.SelectMany(p => SolutionInfoFactory.GetProjects(p, solutionProps)).Distinct();
                    foreach (var project in projectFiles)
                    {
                        VerifyPackageReferences(project, depsFile.VersionVariables);
                    }
                }
                else
                {
                    VerifyPackageReferences(proj.ItemSpec, depsFile.VersionVariables);
                }
            }

            return(!Log.HasLoggedErrors);
        }
        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 #5
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 #7
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);
        }
Beispiel #8
0
		public async Task<CodeExecutionResult> ExecuteAsync (CodeExecutionRequest request)
		{
			// TODO: Just spawn extra containers?
			if (AvailableContainers.Count <= 0)
			{
				Console.WriteLine ("There are no available contianer runners, try again later");
				return null;
			}

			// get a new SolutionInfo
			var solutionInfo = SolutionInfoFactory.CreateSolutionInfo (request);
			List<TestCaseResult> testResults = new List<TestCaseResult> ();
			bool timedOut = false;

			// get available ContainerRunner
			var containerRunner = AvailableContainers.Pop ();
			BusyContainers.Add (containerRunner);
			try
			{

				// run
				var runResult = await containerRunner.RunAsync (solutionInfo);

				Console.WriteLine ("Exit Code");
				Console.WriteLine (runResult.ExitCode);
				Console.WriteLine ("StandardOutput");
				Console.WriteLine (runResult.StandardOutput);
				Console.WriteLine ("StandardError");
				Console.WriteLine (runResult.StandardError);

				if (runResult.ExitCode != 0)
				{
					Console.WriteLine ("HINDI ZERO EXIT CODE");
					return new CodeExecutionResult ()
					{
						SolutionId = request.SolutionId,
							Passed = false,
							CompilationError = runResult.StandardOutput
					};
				}

				var outputs = runResult.StandardOutput.Split (":")
					.Select (x => Regex.Replace (x, @"\t|\n|\r", "").FromBase64ToString ().Trim ()).ToList ();

				for (int i = 0; i < request.TestCases.Count; i++)
				{
					var testCase = request.TestCases[i];

					var testResult = new TestCaseResult ()
					{
						SampleInput = testCase.SampleInput,
							ExpectedOutput = testCase.ExpectedOutput,
							ActualOutput = outputs[i],
							Status = testCase.ExpectedOutput.Equals (outputs[i]) ?
							TestCaseStatus.Passed : TestCaseStatus.Failed
					};
					testResults.Add (testResult);
				}
			}
			catch (OperationCanceledException op)
			{
				Console.WriteLine ("Code Execution Timed Out");
				Console.WriteLine (op.Message);
				timedOut = true;
			}
			catch (Exception e)
			{
				Console.WriteLine ("MAY EXCEPTION");
				Console.WriteLine (e.Message);
				// TODO: Catch OperationCanceledException
				// add property in result. TimedOut? if timedout, return result. your code timeout after t seconds
				timedOut = true;
			}
			finally
			{
				BusyContainers.Remove (containerRunner);
				AvailableContainers.Push (containerRunner);
			}

			bool passed = testResults.Count > 0 && testResults.All (t => t.Status == TestCaseStatus.Passed);
			return new CodeExecutionResult ()
			{
				SolutionId = request.SolutionId,
					TestCaseResults = testResults,
					Passed = passed,
					TimedOut = timedOut
			};
		}