Skip to content

Commit

Permalink
Implement SourceLink support
Browse files Browse the repository at this point in the history
Fixes googleapis#923.

(Generated project files in next commit.)
  • Loading branch information
jskeet committed Jul 17, 2017
1 parent b9af573 commit c0e505d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
6 changes: 3 additions & 3 deletions buildrelease.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ git fetch -v --dry-run --tags upstream 2>&1 \
cd $(dirname $0)

rm -rf releasebuild
git clone https://github.com/GoogleCloudPlatform/google-cloud-dotnet.git releasebuild
git clone https://github.com/GoogleCloudPlatform/google-cloud-dotnet.git releasebuild -c core.autocrlf=input
cd releasebuild
export CI=true # Forces SourceLink in the main build.
git checkout $tag
./build.sh
dotnet pack AllProjects.sln --no-build -o $PWD/nuget -c Release
Expand All @@ -40,5 +41,4 @@ echo "- Upload new docs to gh-pages branch"
echo "- Push packages to nuget:"
echo " - cd releasebuild/nuget"
echo " - Remove any packages you don't want to push"
echo " - for pkg in *[^s].nupkg; do nuget push -Source https://api.nuget.org/v3/index.json -ApiKey API_KEY_HERE \$pkg; done"
echo " (The [^s] avoids matching the symbols packages)"
echo " - for pkg in *.nupkg; do nuget push -Source nuget.org -ApiKey API_KEY_HERE \$pkg; done"
29 changes: 22 additions & 7 deletions tools/Google.Cloud.Tools.ProjectGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public class Program
private const string GrpcVersion = "1.4.0";
private const string StableGaxVersion = "2.0.0";
private const string PrereleaseGaxVersion = "2.1.0-beta01";
private const string DotnetPackInstructionsLabel = "dotnet pack instructions";

private const string ConfigureAwaitAnalyzer = "ConfigureAwaitChecker.Analyzer";
private const string SourceLinkPackage = "SourceLink.Create.CommandLine";
private static readonly HashSet<string> PrivateAssetPackages = new HashSet<string> { ConfigureAwaitAnalyzer, SourceLinkPackage };

private const string AnalyzersPath = @"..\..\..\tools\Google.Cloud.Tools.Analyzers\bin\$(Configuration)\netstandard1.3\publish\Google.Cloud.Tools.Analyzers.dll";
private const string StripDesktopOnNonWindows = @"..\..\..\StripDesktopOnNonWindows.xml";
Expand Down Expand Up @@ -157,7 +162,8 @@ private static void GenerateMainProject(ApiMetadata api, string directory)
string targetFrameworks = api.TargetFrameworks;
var dependencies = new SortedList<string, string>(api.Dependencies)
{
{ "ConfigureAwaitChecker.Analyzer", "1.0.0-beta4" }
{ ConfigureAwaitAnalyzer, "1.0.0-beta4" },
{ SourceLinkPackage, "2.1.2" }
};
// If Grpc.Core is ever specified explicitly (e.g. for "other" projects),
// but without a version number, fill it in.
Expand Down Expand Up @@ -192,8 +198,6 @@ private static void GenerateMainProject(ApiMetadata api, string directory)
// Package-related properties
new XElement("Description", api.Description),
new XElement("PackageTags", string.Join(";", api.Tags.Concat(new[] { "Google", "Cloud" }))),
new XElement("IncludeSymbols", true),
new XElement("IncludeSource", true),
new XElement("Copyright", "Copyright 2017 Google Inc."),
new XElement("Authors", "Google Inc."),
new XElement("IconUrl", "https://cloud.google.com/images/gcp-icon-64x64.png"), // TODO: Check element name
Expand All @@ -202,7 +206,15 @@ private static void GenerateMainProject(ApiMetadata api, string directory)
new XElement("RepositoryType", "git"),
new XElement("RepositoryUrl", "https://github.com/GoogleCloudPlatform/google-cloud-dotnet")
);
WriteProjectFile(api, directory, propertyGroup, CreateDependenciesElement(dependencies, api.IsReleaseVersion));
var packingElement = new XElement("ItemGroup",
new XAttribute("Label", DotnetPackInstructionsLabel),
targetFrameworks.Split(';').Select(tfm => new XElement("Content",
new XAttribute("Include", $@"$(OutputPath){tfm}\$(PackageId).pdb"),
new XElement("Pack", true),
new XElement("PackagePath", $"lib/{tfm}")
))
);
WriteProjectFile(api, directory, propertyGroup, CreateDependenciesElement(dependencies, api.IsReleaseVersion), packingElement);
}

private static void GenerateTestProject(ApiMetadata api, string directory)
Expand Down Expand Up @@ -236,11 +248,11 @@ private static void GenerateTestProject(ApiMetadata api, string directory)
new XAttribute("Include", "Microsoft.CSharp")));
// Test service... it keeps on getting added by Visual Studio, so let's just include it everywhere.
itemGroup.Add(new XElement("Service", new XAttribute("Include", "{82a7f48d-3b50-4b1e-b82e-3ada8210c358}")));
WriteProjectFile(api, directory, propertyGroup, itemGroup);
WriteProjectFile(api, directory, propertyGroup, itemGroup, null);
}

private static void WriteProjectFile(
ApiMetadata api, string directory, XElement propertyGroup, XElement dependenciesItemGroup)
ApiMetadata api, string directory, XElement propertyGroup, XElement dependenciesItemGroup, XElement packingElement)
{
var file = Path.Combine(directory, $"{Path.GetFileName(directory)}.csproj");
XElement doc;
Expand All @@ -252,6 +264,8 @@ private static void WriteProjectFile(
doc.Elements("Import").Where(x => (string)x.Attribute("Project") == @"..\..\StripDesktopOnNonWindows.xml").Remove();
doc.Elements("PropertyGroup").First().ReplaceWith(propertyGroup);
doc.Elements("ItemGroup").First().ReplaceWith(dependenciesItemGroup);
doc.Elements("ItemGroup").Where(x => (string)x.Attribute("Label") == DotnetPackInstructionsLabel).Remove();
doc.Elements("ItemGroup").First().AddAfterSelf(packingElement);

if (!doc.Elements("Import").Any(x => (string)x.Attribute("Project") == StripDesktopOnNonWindows))
{
Expand All @@ -264,6 +278,7 @@ private static void WriteProjectFile(
doc = new XElement("Project",
new XAttribute("Sdk", "Microsoft.NET.Sdk"),
propertyGroup,
packingElement,
dependenciesItemGroup,
new XElement("Import", new XAttribute("Project", StripDesktopOnNonWindows))
);
Expand Down Expand Up @@ -313,7 +328,7 @@ private static XElement CreateDependenciesElement(IDictionary<string, string> de
// See https://github.com/GoogleCloudPlatform/google-cloud-dotnet/issues/1066
d.Key == "Grpc.Core" ? new XAttribute("PrivateAssets", "None") : null,
// Make references to ConfigureAwaitChecker effectively private
d.Key == "ConfigureAwaitChecker.Analyzer" ? new XAttribute("PrivateAssets", "All") : null)
PrivateAssetPackages.Contains(d.Key) ? new XAttribute("PrivateAssets", "All") : null)
),
new XElement("Analyzer",
new XAttribute("Condition", $"Exists('{AnalyzersPath}')"),
Expand Down

0 comments on commit c0e505d

Please sign in to comment.