Skip to content

Commit

Permalink
feat: Added Add-on for Grpc.Tools
Browse files Browse the repository at this point in the history
The grpc tools add-on will be built with this package.
By adding this package, grpc.tools will automatically be added to protoc.

Should work with any other protoc compiler package as well, but is untested.

Global Tool is disabled in solution for now

Second contribution for yoheimuta#337
  • Loading branch information
carstencodes authored and Carsten Igel committed Jul 29, 2024
1 parent 7e9cbac commit 8a01676
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 2 deletions.
1 change: 1 addition & 0 deletions bdist/dotnet/ProtocGenPlugin/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Protolint Plug-in Compiler
Empty file.
88 changes: 88 additions & 0 deletions bdist/dotnet/ProtocGenPlugin/protolint-ProtocGenPlugin.msbuildproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<Project Sdk="Microsoft.Build.NoTargets/3.7.56">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<DefaultProjectTypeGuid>{2F08BC15-189B-4804-B644-653F34C968A8}</DefaultProjectTypeGuid>
</PropertyGroup>

<PropertyGroup>
<PackageId>yoheimuta.protolint.protoc-plugin</PackageId>
<PackageVersion></PackageVersion>
<Authors>yoheimuta; carstencodes</Authors>
<Title>Protolint Protoc plug-in</Title>
<Description>A pluggable linter and fixer to enforce Protocol Buffer style and conventions.</Description>
<Copyright>Copyright (c) 2018 yohei yoshimuta</Copyright>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<!--<PackageLicenseFile>$(MsBuildThisFileDirectory)../../../LICENSE</PackageLicenseFile>-->
<PackageProjectUrl>https://github.com/yoheimuta/protolint</PackageProjectUrl>
<PackageReadmeFile>ReadMe.md</PackageReadmeFile>
<PackageTags>protolint;protocol-buffers;protobuf;linter</PackageTags>
<PackageType>Dependency</PackageType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<DevelopmentDependency>true</DevelopmentDependency>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="NuGet.Build.Tasks.Pack" Version="6.9.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<None
Include="ReadMe.md"
Pack="true"
PackagePath="" />
<None
Include="$(PackageId).props"
Pack="true"
PackagePath="build" />
<None
Include="$(PackageId).targets"
Pack="true"
PackagePath="build" />
<None
Include="_._"
Pack="true"
PackagePath="lib/netstandard2.0" />
<None
Include="$(ProtolintGoReleaserDistDir)protoc-gen-protolint_darwin_amd64_v1/protoc-gen-protolint"
Pack="true"
PackagePath="tools/osx-x64/" />
<None
Include="$(ProtolintGoReleaserDistDir)protoc-gen-protolint_darwin_arm64/protoc-gen-protolint"
Pack="true"
PackagePath="tools/osx-arm64/" />
<None
Include="$(ProtolintGoReleaserDistDir)protoc-gen-protolint_linux_amd64_v1/protoc-gen-protolint"
Pack="true"
PackagePath="tools/linux-x64/" />
<None
Include="$(ProtolintGoReleaserDistDir)protoc-gen-protolint_linux_arm_7/protoc-gen-protolint"
Pack="true"
PackagePath="tools/linux-arm/" />
<None
Include="$(ProtolintGoReleaserDistDir)protoc-gen-protolint_linux_arm64/protoc-gen-protolint"
Pack="true"
PackagePath="tools/linux-arm64/" />
<None
Include="$(ProtolintGoReleaserDistDir)protoc-gen-protolint_windows_amd64_v1/protoc-gen-protolint.exe"
Pack="true"
PackagePath="tools/win-x64/" />
<None
Include="$(ProtolintGoReleaserDistDir)protoc-gen-protolint_windows_arm64/protoc-gen-protolint.exe"
Pack="true"
PackagePath="tools/win-arm64/" />
</ItemGroup>

<ItemGroup>
<_FilesToRename Include="$(ProtolintGoReleaserDistDir)/protolint*/protolint" />
<_FilesToRename Include="$(ProtolintGoReleaserDistDir)/protolint*/protolint.exe" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<ProtocGenProtolintOptions></ProtocGenProtolintOptions>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>

<PropertyGroup>
<_SystemPlatform>$( [System.Environment]::OSVersion.PlatformId )</_SystemPlatform>
<_SystemPlatform>$(_SystemPlatform.ToLowerInvariant())</_SystemPlatform>
<_SystemArchitecture>$( [System.Runtime.InteropServices]::Architecture )<_SystemArchitecture>
<ProtocGenProtolintToolPath>$( [System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)../tools) )</ProtocGenProtolintToolPath>
<ProtocGenProtolintOs Condition="'$(ProtocGenProtolintOs)' == '' AND '$( _SystemPlatform.StartsWith('win') )'">win</ProtocGenProtolintOs>
<ProtocGenProtolintOs Condition="'$(ProtocGenProtolintOs)' == '' AND '$( _SystemPlatform.StartsWith('unix') )'">linux</ProtocGenProtolintOs>
<ProtocGenProtolintOs Condition="'$(ProtocGenProtolintOs)' == ''">$(_SystemPlatform)</ProtocGenProtolintOs>
<ProtocGenProtolintCpuArch>$( _SystemArchitecture.ToLowerInvariant() )</ProtocGenProtolintCpuArch>
<ProtocGenProtolintRid>$(ProtocGenProtolintOs)-$(ProtocGenProtolintCpuArch)</ProtocGenProtolintRid>
<ProtocGenProtolintExtension Condition="'$(ProtocGenProtolintOs)' == 'win'">.exe</ProtocGenProtolintExtension>
<ProtocGenProtolintExecutableName>protoc-gen-protolint</ProtocGenProtolintExecutableName>
<ProtocGenProtolintExecutuableFileDir>$(ProtocGenProtolintToolPath)$(ProtocGenProtolintRid)/</ProtocGenProtolintExecutuableFileDir>
<ProtocGenProtolintExecutable>$(ProtocGenProtolintExecutuableFileDir)$(ProtocGenProtolintExecutableName)$(ProtocGenProtolintExtension)</ProtocGenProtolintExecutable>
</PropertyGroup>

<PropertyGroup>
<ProtocGenProtolintEffectiveOptions Condition="'$(ProtocGenProtolintOptions)' != ''">,$(ProtocGenProtolintOptions)</ProtocGenProtolintEffectiveOptions>
</PropertyGroup>

<ItemGroup Condition="Exists('$(ProtocGenProtolintExecutable)')">
<ProtoBuf Update="@(Protobuf->WithMetadata('ProtoRoot',''))">
<AdditionalProtocArguments>--protolint_out=.;--protolint_opt=proto_root=$([System.IO.Path]::GetFullPath(%(RelativeDir))$(ProtocGenProtolintEffectiveOptions)</AdditionalProtocArguments>
<AdditionalProtocArguments Condition=" '$(Protobuf_ProtoRoot)' != '' ">--protolint_out=.;--protolint_opt=proto_root=$(Protobuf_ProtoRoot)$(ProtocGenProtolintEffectiveOptions)</AdditionalProtocArguments>
</ProtoBuf>
<ProtoBuf Update="@(Protobuf->HasMetadata('ProtoRoot'))">
<AdditionalProtocArguments>--protolint_out=.;--protolint_opt=proto_root=%(ProtoRoot)$(ProtocGenProtolintEffectiveOptions)</AdditionalProtocArguments>
</ProtoBuf>
</ItemGroup>

<Target
Name="ProtocGenProtolintVerifyToolExists"
BeforeTargets="Protobuf_PrepareCompile"
Condition="'@(Protobuf)' != ''">
<Error
Text="Cannot locate protoc-gen-protolint executable file at '$(ProtocGenProtolintExecutable)'"
Condition="!Exists('$(ProtocGenProtolintExecutable)')"/>
</Target>

<Target
Name="ProtocGenProtolintUpdatePath"
BeforeTargets="Protobuf_BeforeCompile"
Condition="'@(Protobuf)' != ''">
<PropertyGroup>
<_SystemPath>$( [System.Environment.GetEnvironmentVariable('PATH')] )</_SystemPath>
<_NewSystemPath>$(_SystemPath);$(ProtocGenProtolintExecutuableFileDir)</_NewSystemPath>
</PropertyGroup>

<UpdatePathToProtocGenExecutable Value="$(_NewSystemPath)" />
</Target>

<UsingTask
TaskName="UpdatePathToProtocGenExecutable"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >

<ParameterGroup>
<Value ParameterType="System.String" Required="true" />
</ParameterGroup>

<Task>
<Using Namespace="System" />
<Code Type="Fragment" Language="cs">
<![CDATA[
Environment.SetEnvironmentVariable("PATH", Value);
]]>
</Code>
</Task>

</UsingTask>
</Project>
8 changes: 8 additions & 0 deletions bdist/dotnet/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# protolint dotnet port

The .NET port for protolint consists of

- a .NET global tool. This cannot be fulfilled by .NET SDK yet,
refer to [this issue](https://github.com/dotnet/sdk/issues/9503) for details.
- a simple MsBuild task, that will be added to .NET project and that will validate all items in the `ProtoBuf` item group.
- an MsBuild Task collections that registers protoc-gen-protolint as protoc-plugin for all `ProtoBuf` items.
8 changes: 6 additions & 2 deletions bdist/dotnet/protolint.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2F08BC15-189B-4804-B644-653F34C968A8}") = "protolint-global-tool", "global-tool\protolint-global-tool.msbuildproj", "{9F709A95-B632-4507-83CC-5750BBF2C9CC}"
EndProject
Project("{2F08BC15-189B-4804-B644-653F34C968A8}") = "protolint-ProtocGenPlugin", "ProtocGenPlugin\protolint-ProtocGenPlugin.msbuildproj", "{AFCA57D8-4725-46B2-A574-9A51009F0DE1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,8 +17,10 @@ Global
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9F709A95-B632-4507-83CC-5750BBF2C9CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F709A95-B632-4507-83CC-5750BBF2C9CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F709A95-B632-4507-83CC-5750BBF2C9CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F709A95-B632-4507-83CC-5750BBF2C9CC}.Release|Any CPU.Build.0 = Release|Any CPU
{AFCA57D8-4725-46B2-A574-9A51009F0DE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AFCA57D8-4725-46B2-A574-9A51009F0DE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AFCA57D8-4725-46B2-A574-9A51009F0DE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AFCA57D8-4725-46B2-A574-9A51009F0DE1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

0 comments on commit 8a01676

Please sign in to comment.