Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build telemetry to use the local IceRpc packages #4040

Merged
merged 4 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@
"paths": ["examples/slice/Upload"]
}
]
}
}
15 changes: 15 additions & 0 deletions IceRpc.sln
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IceRpc.Protobuf", "src\IceR
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IceRpc.Protobuf.Tests", "tests\IceRpc.Protobuf.Tests\IceRpc.Protobuf.Tests.csproj", "{FA4447E1-09E5-4F0A-B3DD-B0157B62BF0A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IceRpc.BuildTelemetry.Reporter", "tools\IceRpc.BuildTelemetry.Reporter\IceRpc.BuildTelemetry.Reporter.csproj", "{7E0C865A-DE67-43FC-9C42-5B5901D3DB8D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -565,6 +567,18 @@ Global
{FA4447E1-09E5-4F0A-B3DD-B0157B62BF0A}.Release|x64.Build.0 = Release|Any CPU
{FA4447E1-09E5-4F0A-B3DD-B0157B62BF0A}.Release|x86.ActiveCfg = Release|Any CPU
{FA4447E1-09E5-4F0A-B3DD-B0157B62BF0A}.Release|x86.Build.0 = Release|Any CPU
{7E0C865A-DE67-43FC-9C42-5B5901D3DB8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7E0C865A-DE67-43FC-9C42-5B5901D3DB8D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7E0C865A-DE67-43FC-9C42-5B5901D3DB8D}.Debug|x64.ActiveCfg = Debug|Any CPU
{7E0C865A-DE67-43FC-9C42-5B5901D3DB8D}.Debug|x64.Build.0 = Debug|Any CPU
{7E0C865A-DE67-43FC-9C42-5B5901D3DB8D}.Debug|x86.ActiveCfg = Debug|Any CPU
{7E0C865A-DE67-43FC-9C42-5B5901D3DB8D}.Debug|x86.Build.0 = Debug|Any CPU
{7E0C865A-DE67-43FC-9C42-5B5901D3DB8D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E0C865A-DE67-43FC-9C42-5B5901D3DB8D}.Release|Any CPU.Build.0 = Release|Any CPU
{7E0C865A-DE67-43FC-9C42-5B5901D3DB8D}.Release|x64.ActiveCfg = Release|Any CPU
{7E0C865A-DE67-43FC-9C42-5B5901D3DB8D}.Release|x64.Build.0 = Release|Any CPU
{7E0C865A-DE67-43FC-9C42-5B5901D3DB8D}.Release|x86.ActiveCfg = Release|Any CPU
{7E0C865A-DE67-43FC-9C42-5B5901D3DB8D}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -610,6 +624,7 @@ Global
{7C02E2CA-5E40-473D-AA88-5C86752BAF32} = {14BE8958-5499-473F-A45E-46C47EACF7C1}
{927769EA-A3ED-4A46-906A-F82E3583D6E9} = {14BE8958-5499-473F-A45E-46C47EACF7C1}
{FA4447E1-09E5-4F0A-B3DD-B0157B62BF0A} = {8AC71827-78FD-4A6C-97C7-3E4378AFB568}
{7E0C865A-DE67-43FC-9C42-5B5901D3DB8D} = {14BE8958-5499-473F-A45E-46C47EACF7C1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8BB4EF8D-31A9-4DBC-AD9F-164CF6C083B6}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public partial class ServiceProviderExtensionsTests
[Test]
public void Create_protobuf_client_with_no_params()
{
var serviceCollection =
var serviceCollection =
new ServiceCollection()
.AddSingleton(InvalidInvoker.Instance)
.AddSingleton<IMyOperations>(provider => provider.CreateProtobufClient<MyOperationsClient>());
Expand Down
2 changes: 1 addition & 1 deletion tests/ZeroC.Slice.Tests/CustomTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void Decode_class_with_custom_type_fields()
encoder.EncodeTagged(
1,
TagFormat.FSize,
myCustomType,
myCustomType,
(ref SliceEncoder encoder, MyCustomType value) =>
CustomTypeSliceEncoderExtensions.EncodeNullableCustomType(ref encoder, value));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(MSBuildThisFileDirectory)../../build/IceRpc.Version.props" />
<Import Project="../IceRpc.Slice.Tools/IceRpc.Slice.Tools.props" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -10,9 +11,7 @@
<CopyDebugSymbolFilesFromPackages>true</CopyDebugSymbolFilesFromPackages>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IceRpc.Slice.Tools" Version="0.3.*" PrivateAssets="All" />
<PackageReference Include="IceRpc.Slice" Version="0.3.*" />
<PackageReference Include="Microsoft.Build.Framework" Version="17.8.3" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.8.3" />
<ProjectReference Include="../../src/IceRpc.Slice/IceRpc.Slice.csproj" />
</ItemGroup>
<Import Project="../IceRpc.Slice.Tools/IceRpc.Slice.Tools.targets" />
</Project>
22 changes: 19 additions & 3 deletions tools/IceRpc.BuildTelemetry.Reporter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using IceRpc;
using IceRpc.BuildTelemetry;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Reflection;

var timeout = TimeSpan.FromSeconds(3); // The timeout for the complete telemetry upload process.
Expand Down Expand Up @@ -66,8 +65,25 @@

BuildTelemetry buildTelemetry = idl.ToLower() switch
{
"slice" => new BuildTelemetry.Slice(new SliceTelemetryData(version, compilationHash, containsSlice1, containsSlice2, sourceFileCount, referenceFileCount)),
"protobuf" => new BuildTelemetry.Protobuf(new ProtobufTelemetryData(version, compilationHash, sourceFileCount)),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworked the code to use the generated constructor, and remove the other constructor that hardcodes the defaults

"slice" => new BuildTelemetry.Slice(new SliceTelemetryData(
version,
SystemHelpers.GetOperatingSystem(),
SystemHelpers.GetArchitecture(),
SystemHelpers.IsCi(),
new TargetLanguage.CSharp(Environment.Version.ToString()),
compilationHash,
containsSlice1,
containsSlice2,
sourceFileCount,
referenceFileCount)),
"protobuf" => new BuildTelemetry.Protobuf(new ProtobufTelemetryData(
version,
SystemHelpers.GetOperatingSystem(),
SystemHelpers.GetArchitecture(),
SystemHelpers.IsCi(),
new TargetLanguage.CSharp(Environment.Version.ToString()),
sourceFileCount,
compilationHash)),
_ => throw new ArgumentException($"Unknown IDL: {idl}") // This should never happen
};

Expand Down
25 changes: 0 additions & 25 deletions tools/IceRpc.BuildTelemetry.Reporter/ProtobufTelemetryData.cs

This file was deleted.

31 changes: 0 additions & 31 deletions tools/IceRpc.BuildTelemetry.Reporter/SliceTelemetryData.cs

This file was deleted.

57 changes: 57 additions & 0 deletions tools/IceRpc.Protobuf.Tools/BuildTelemetryTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) ZeroC, Inc.

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace IceRpc.Protobuf.Tools;

/// <summary>
/// A MSBuild task that reports Protobuf build telemetry data to the IceRPC build telemetry service.
/// </summary>
public class BuildTelemetryTask : ToolTask
{
/// <summary>
/// Gets or sets the compilation hash.
/// </summary>
[Required]
public string CompilationHash { get; set; } = "";

/// <summary>
/// Gets or sets the number of source files in the Slice compilation.
/// </summary>
public int SourceFileCount { get; set; }
Comment on lines +19 to +22

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should say protobuf instead of Slice compilation.
Also, I'm not sure whether making a distinction of "source" files is meaningful/correct with Protobuf,
unlike in Slice.


/// <summary>
/// Gets or sets the working directory.
/// </summary>
[Required]
public string WorkingDirectory { get; set; } = "";

/// <inheritdoc/>
protected override string ToolName => "dotnet";

/// <inheritdoc/>
protected override string GetWorkingDirectory() => WorkingDirectory;

/// <inheritdoc/>
protected override string GenerateFullPathToTool() => ToolName;

/// <inheritdoc/>
protected override string GenerateCommandLineCommands()
{
var commandLine = new CommandLineBuilder();
commandLine.AppendFileNameIfNotNull("IceRpc.BuildTelemetry.Reporter.dll");
commandLine.AppendSwitch("--hash");
commandLine.AppendSwitch(CompilationHash);
commandLine.AppendSwitch("--idl");
commandLine.AppendSwitch("protobuf");
commandLine.AppendSwitch("--src-file-count");
commandLine.AppendSwitch(SourceFileCount.ToString());
return commandLine.ToString();
}

/// <summary>
/// Overriding this method to suppress any warnings or errors.
/// </summary>
protected override void LogEventsFromTextOutput(string singleLine, MessageImportance messageImportance) { }
}
7 changes: 4 additions & 3 deletions tools/IceRpc.Protobuf.Tools/IceRpc.Protobuf.Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
</ItemGroup>
<ItemGroup>
<Compile Include="../Common/IceRpc.CaseConverter.Internal/Converter.cs" />
<Compile Include="../Common/IceRpc.BuildTelemetry/TelemetryTask.cs" />
<None
Include="../IceRpc.BuildTelemetry.Reporter/bin/$(Configuration)/net8.0/*"
Exclude="../IceRpc.BuildTelemetry.Reporter/bin/$(Configuration)/net8.0/*.exe"
Visible="false"
>
<PackagePath>tools/</PackagePath>
<Pack>true</Pack>
Expand Down Expand Up @@ -76,11 +76,12 @@
<None
Include="../IceRpc.ProtocGen/bin/$(Configuration)/net8.0/*"
Exclude="../IceRpc.ProtocGen/bin/$(Configuration)/net8.0/*.exe"
Visible="false"
>
<PackagePath>tools/</PackagePath>
<Pack>true</Pack>
</None>
<None Include="$(MSBuildThisFileDirectory)obj/tools/**">
<None Include="$(MSBuildThisFileDirectory)obj/tools/**" Visible="false">
<PackagePath>tools/</PackagePath>
<Pack>true</Pack>
</None>
Expand Down Expand Up @@ -116,7 +117,7 @@
/>

<!-- We cannot use MSBuild Unzip task because it doesn't preserve the executable permissions, we use our custom
extract task instead. -->
extract task instead. -->
<ExtractTask
SourceFiles="$(MSBuildThisFileDirectory)obj/protoc-$(ProtobufVersion)-osx-aarch_64.zip"
DestinationFolder="$(MSBuildThisFileDirectory)obj/protoc-$(ProtobufVersion)-osx-aarch_64"
Expand Down
6 changes: 3 additions & 3 deletions tools/IceRpc.Protobuf.Tools/IceRpc.Protobuf.Tools.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
<IceRpcProtocPath>$(MSBuildThisFileDirectory)obj/tools/</IceRpcProtocPath>
<IceRpcProtocGenPath
>$(MSBuildThisFileDirectory)../IceRpc.ProtocGen/bin/$(Configuration)/net8.0/</IceRpcProtocGenPath>
<IceRpcBuildTelemetryScriptPath
>$(MSBuildThisFileDirectory)../IceRpc.BuildTelemetry.Reporter/bin/$(Configuration)/net8.0/</IceRpcBuildTelemetryScriptPath>
<!-- Disable build telemetry when using an IceRPC source builds -->
<IceRpcBuildTelemetry>false</IceRpcBuildTelemetry>
</PropertyGroup>
</When>
<Otherwise>
<!-- Use the protoc compiler and the IceRpc.ProtocGen assembly in this NuGet package -->
<!-- Use the protoc compiler, the IceRpc.ProtocGen assembly, and the build telemetry script in this NuGet package -->
<PropertyGroup>
<IceRpcProtocPath>$(MSBuildThisFileDirectory)../tools/</IceRpcProtocPath>
<IceRpcProtocGenPath>$(MSBuildThisFileDirectory)../tools/</IceRpcProtocGenPath>
Expand Down
27 changes: 13 additions & 14 deletions tools/IceRpc.Protobuf.Tools/IceRpc.Protobuf.Tools.targets
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
AssemblyFile="$(IceRpcProtobufToolsTaskAssembliesPath)IceRpc.Protobuf.Tools.dll"
/>
<UsingTask
TaskName="IceRpc.BuildTelemetry.TelemetryTask"
TaskName="IceRpc.Protobuf.Tools.BuildTelemetryTask"
AssemblyFile="$(IceRpcProtobufToolsTaskAssembliesPath)IceRpc.Protobuf.Tools.dll"
/>
<ItemGroup>
Expand All @@ -36,9 +36,9 @@
</ItemGroup>

<!--
When EnableDefaultItems property is true, *.proto files are included as "None" items. We remove them here, to
include them as "ProtoFile" items later.
-->
When EnableDefaultItems property is true, *.proto files are included as "None" items. We remove them here, to
include them as "ProtoFile" items later.
-->
<ItemGroup Condition="'$(EnableDefaultItems)' == 'true'">
<None Remove="**/*.proto" />
</ItemGroup>
Expand All @@ -55,11 +55,11 @@
<Output ItemName="_ProtoFile" TaskParameter="ComputedSources" />
</UpToDateCheckTask>
<!-- Compile the Proto files
The search path determines where protoc compiler locates import files, we add:
- $(IceRpcProtocPath) to import google well-known files from IceRpc.Protobuf.Tools.
- $(MSBuildProjectDirectory) to import the project own files.
- @(ProtoSearchPath) additional search paths specified by the user.
-->
The search path determines where protoc compiler locates import files, we add:
- $(IceRpcProtocPath) to import google well-known files from IceRpc.Protobuf.Tools.
- $(MSBuildProjectDirectory) to import the project own files.
- @(ProtoSearchPath) additional search paths specified by the user.
-->
<ProtocTask
WorkingDirectory="$(MSBuildProjectDirectory)"
OutputDir="@(_ProtoFile->'%(OutputDir)')"
Expand All @@ -75,19 +75,18 @@
</OutputHashTask>

<!-- Run build telemetry -->
<TelemetryTask
<BuildTelemetryTask
WorkingDirectory="$(IceRpcBuildTelemetryScriptPath)"
CompilationHash="$(Hash)"
SourceFileCount="$(FileCount)"
Condition="'$(IceRpcBuildTelemetry)' != 'false'"
Idl="protobuf"
ContinueOnError="true"
/>

<!--
Include all C# generated source items that have not been already included. We delay this until we are
running the ProtoCompile target so that default includes are already processed.
-->
Include all C# generated source items that have not been already included. We delay this until we are
running the ProtoCompile target so that default includes are already processed.
-->
<ItemGroup>
<Compile
Include="@(_ProtoFile->'%(OutputDir)/%(OutputFileName).cs')"
Expand Down
Loading
Loading