提交 55979af7 编写于 作者: J Jared Parsons

Basic form of produces

上级 5e455efc
<?xml version="1.0"?>
<package >
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>Roslyn.VisualStudio.Test.Utilities</id>
<description>Utility methods used to run Roslyn Visual Studio integration tests.</description>
......@@ -19,4 +19,4 @@
<files>
<file src="Roslyn.VisualStudio.Test.Utilities.dll" target="lib\net46" />
</files>
</package>
\ No newline at end of file
</package>
<?xml version="1.0" encoding="utf-8"?>
<package>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>Roslyn.Build.Util</id>
<version>0.9.4-portable</version>
......
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace RepoUtil
{
internal static class NuSpecUtil
{
internal static IEnumerable<FileName> GetNuSpecFiles(string sourcesPath)
{
return Directory
.EnumerateFiles(sourcesPath, "*.nuspec", SearchOption.AllDirectories)
.Select(x => FileName.FromFullPath(sourcesPath, x));
}
internal static string GetId(string nuspecFilePath)
{
var doc = XDocument.Load(nuspecFilePath);
var ns = XNamespace.Get("http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd");
var id = doc
.Element(ns.GetName("package"))
.Element(ns.GetName("metadata"))
.Element(ns.GetName("id"))
.Value;
return id;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RepoUtil
{
internal class ProduceUtil
{
private readonly RepoConfig _repoConfig;
private readonly string _sourcesPath;
internal ProduceUtil(RepoConfig repoConfig, string sourcesPath)
{
_repoConfig = repoConfig;
_sourcesPath = sourcesPath;
}
internal void Go()
{
foreach (var fileName in NuSpecUtil.GetNuSpecFiles(_sourcesPath))
{
if (_repoConfig.NuSpecExcludes.Any(x => x.IsMatch(fileName.RelativePath)))
{
continue;
}
var id = NuSpecUtil.GetId(fileName.FullPath);
Console.WriteLine(id);
}
}
}
}
......@@ -16,6 +16,7 @@ private enum Mode
Verify,
Consumes,
Change,
Produces,
}
internal static readonly string[] ProjectJsonFileRelativeNames = Array.Empty<string>();
......@@ -54,6 +55,12 @@ private static bool Run(string[] args)
util.ChangeAll();
return true;
}
case Mode.Produces:
{
var util = new ProduceUtil(repoConfig, sourcesPath);
util.Go();
return true;
}
default:
throw new Exception("Unrecognized mode");
}
......@@ -69,6 +76,7 @@ private static void Usage()
Console.Write(text);
}
// TODO: don't use dashes here.
private static bool TryParseCommandLine(string[] args, out Mode mode, out string sourcesPath)
{
var allGood = true;
......@@ -94,6 +102,10 @@ private static bool TryParseCommandLine(string[] args, out Mode mode, out string
mode = Mode.Change;
index++;
break;
case "-produces":
mode = Mode.Produces;
index++;
break;
default:
Console.Write($"Option {arg} is unrecognized");
allGood = false;
......
......@@ -40,12 +40,18 @@ internal class RepoConfig
internal ImmutableArray<NuGetPackage> StaticPackages { get; }
internal ImmutableDictionary<string, ImmutableArray<string>> StaticPackagesMap { get; }
internal ImmutableArray<string> ToolsetPackages { get; }
internal ImmutableArray<Regex> NuSpecExcludes { get; }
internal GenerateData? MSBuildGenerateData { get; }
internal RepoConfig(IEnumerable<NuGetPackage> staticPackages, IEnumerable<string> toolsetPackages, GenerateData? msbuildGenerateData)
internal RepoConfig(
IEnumerable<NuGetPackage> staticPackages,
IEnumerable<string> toolsetPackages,
IEnumerable<Regex> nuspecExcludes,
GenerateData? msbuildGenerateData)
{
MSBuildGenerateData = msbuildGenerateData;
StaticPackages = staticPackages.OrderBy(x => x.Name).ToImmutableArray();
NuSpecExcludes = nuspecExcludes.ToImmutableArray();
// TODO: Validate duplicate names in the floating lists
ToolsetPackages = toolsetPackages.OrderBy(x => x).ToImmutableArray();
......@@ -104,9 +110,17 @@ internal static RepoConfig ReadFrom(string jsonFilePath)
msbuildGenerateData = ReadGenerateData(generateObj, "msbuild");
}
var nuspecExcludes = new List<Regex>();
var nuspecExcludesProp = obj.Property("nuspecExcludes");
if (nuspecExcludesProp != null)
{
nuspecExcludes.AddRange(((JArray)nuspecExcludesProp.Value).Values<string>().Select(x => new Regex(x)));
}
return new RepoConfig(
staticPackagesList,
toolsetPackages,
nuspecExcludes,
msbuildGenerateData);
}
......
......@@ -45,7 +45,7 @@
"path": "build\\Targets\\Dependencies.props",
"values": [
"Microsoft.Dia.*",
"System\\.*",
"System.*",
"NETStandardLibraryVersion",
"MicrosoftCodeAnalysisAnalyzersVersion",
"ManagedEsentVersion",
......@@ -53,5 +53,14 @@
"MicrosoftCompositionVersion"
]
}
}
},
"nuspecExcludes": [
"^packages.*",
"^Binaries.*",
"^src\\\\Samples.*",
"^src\\\\Dependencies.*",
".*NuSpec.loc.*",
".*Templates.*"
]
}
......@@ -34,6 +34,8 @@
<Compile Include="JsonTypes.cs" />
<Compile Include="NuGetPackage.cs" />
<Compile Include="NuGetPackageChange.cs" />
<Compile Include="NuSpecUtil.cs" />
<Compile Include="ProduceUtil.cs" />
<Compile Include="Program.cs" />
<Compile Include="ProjectJsonUtil.cs" />
<Compile Include="RepoConfig.cs" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册