-
Notifications
You must be signed in to change notification settings - Fork 166
/
CodeGeneration.targets
99 lines (80 loc) · 8.86 KB
/
CodeGeneration.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<Project>
<PropertyGroup>
<PowerShellExe Condition="'$(PowerShellExe)' == ''">pwsh</PowerShellExe>
<_TypeSpecProjectSyncAndGenerateCommand>npx --no-install --package=@azure-tools/typespec-client-generator-cli --yes tsp-client update --no-prompt --output-dir $(MSBuildProjectDirectory)/../</_TypeSpecProjectSyncAndGenerateCommand>
<_TypeSpecProjectGenerateCommand>npx --no-install --package=@azure-tools/typespec-client-generator-cli --yes tsp-client generate --no-prompt --output-dir $(MSBuildProjectDirectory)/../</_TypeSpecProjectGenerateCommand>
<_DefaultInputName Condition="Exists('$(MSBuildProjectDirectory)/autorest.md')">$(MSBuildProjectDirectory)/autorest.md</_DefaultInputName>
<TypeSpecInput Condition="Exists('$(MSBuildProjectDirectory)/../tsp-location.yaml') and $(MSBuildProjectDirectory.EndsWith('src'))">$(MSBuildProjectDirectory)/../tsp-location.yaml</TypeSpecInput>
<AutoRestInput Condition="'$(AutoRestInput)' == ''">$(_DefaultInputName)</AutoRestInput>
<AutoRestTestsInput Condition="Exists('$(MSBuildProjectDirectory)/autorest.tests.md')">$(MSBuildProjectDirectory)/autorest.tests.md</AutoRestTestsInput>
<AutoRestEntryPoint Condition="'$(AutoRestEntryPoint)' == ''">$(MSBuildThisFileDirectory)../tools/autorest/entrypoints/app.js</AutoRestEntryPoint>
<!--
<AutoRestAdditionalParameters></AutoRestAdditionalParameters>
Allows passing additional AutoRest command line arguments, for example to run in interactive mode
use the following command line (remove the space between minus minus): dotnet msbuild /t:GenerateCode /p:AutoRestAdditionalParameters="- -interactive"
-->
<!--
<TypespecAdditionalOptions></TypespecAdditionalOptions>
Allows passing additional tsp command line arguments, for example to run special emitter
use the following command line: dotnet msbuild /t:GenerateCode /p:TypespecAdditionalOptions="csharpGeneratorPath=/absolute/path/to/artifacts/bin/AutoRest.CSharp/Debug/net8.0/AutoRest.CSharp.dll"
-->
<IncludeAzureCoreSharedCode Condition="'$(IncludeAzureCoreSharedCode)' == ''">true</IncludeAzureCoreSharedCode>
<AzureCoreSharedCodeDirectory Condition="'$(AzureCoreSharedCodeDirectory)' == ''">$(MSBuildThisFileDirectory)../content/Azure.Core.Shared/</AzureCoreSharedCodeDirectory>
<AutoRestSharedCodeDirectory>$(MSBuildThisFileDirectory)../content/Generator.Shared/</AutoRestSharedCodeDirectory>
<ManagementSharedCodeDirectory>$(MSBuildThisFileDirectory)../content/Management.Shared/</ManagementSharedCodeDirectory>
<_GenerateCode Condition="'$(AutoRestInput)' != '' OR '$(TypeSpecInput)' != ''">true</_GenerateCode>
<UseDefaultNamespaceAndOutputFolder Condition="'$(UseDefaultNamespaceAndOutputFolder)' == ''">true</UseDefaultNamespaceAndOutputFolder>
<_AutoRestCommand>npx autorest@$(AutoRestVersion) --max-memory-size=8192 --skip-csproj --skip-upgrade-check --version=$(AutoRestCoreVersion) $(AutoRestInput) $(AutoRestAdditionalParameters) --use=$(MSBuildThisFileDirectory)../tools/net8.0/any/ --clear-output-folder=true --shared-source-folders="$(AzureCoreSharedCodeDirectory);$(AutoRestSharedCodeDirectory)"</_AutoRestCommand>
<_AutoRestCommand Condition="'$(UseDefaultNamespaceAndOutputFolder)' == 'true'">$(_AutoRestCommand) --output-folder=$(MSBuildProjectDirectory)/Generated --namespace=$(RootNamespace)</_AutoRestCommand>
<_SaveInputs Condition="'$(SaveInputs)' == 'true'">--save-inputs</_SaveInputs>
<!-- Here we append the generate-test-project configuration to TypespecAdditionalOptions if it is specified -->
<TypespecAdditionalOptions Condition="'$(GenerateTestProject)' != '' AND '$(TypespecAdditionalOptions)' != ''">$(TypespecAdditionalOptions)%3Bgenerate-test-project=true</TypespecAdditionalOptions>
<TypespecAdditionalOptions Condition="'$(GenerateTestProject)' != '' AND '$(TypespecAdditionalOptions)' == ''">generate-test-project=true</TypespecAdditionalOptions>
<_TypespecAdditionalOptions Condition="'$(TypespecAdditionalOptions)' != ''">--emitter-options "$(TypespecAdditionalOptions)"</_TypespecAdditionalOptions>
<_LocalSpecRepo Condition="'$(LocalSpecRepo)' != ''">--local-spec-repo $(LocalSpecRepo)</_LocalSpecRepo>
<_Debug Condition="'$(Debug)' == 'true'">"--debug"</_Debug>
</PropertyGroup>
<Target Name="GenerateCode" DependsOnTargets="_GenerateCodeForAutorest;_GenerateCodeForTypeSpec"/>
<Target Name="_GenerateCodeForAutorest" Condition="'$(_GenerateCode)' == 'true' AND Exists('$(AutoRestInput)')">
<ReadLinesFromFile File="$(AutoRestInput)">
<Output TaskParameter="Lines" ItemName="AutoRestInputLines"/>
</ReadLinesFromFile>
<ItemGroup>
<GithubUrls Include="$([System.Text.RegularExpressions.Regex]::Match('%(AutoRestInputLines.Identity)', 'https?://(raw.)?github.+'))" />
<GithubUrlsWithoutIssues Include="%(GithubUrls.Identity)" Condition="! ($([System.Text.RegularExpressions.Regex]::IsMatch('%(GithubUrls.Identity)', '/issues/\d+')))" />
<GithubUrlsWithoutHash Include="%(GithubUrlsWithoutIssues.Identity)" Condition="! ($([System.Text.RegularExpressions.Regex]::IsMatch('%(GithubUrlsWithoutIssues.Identity)', '[\w\d]{40}')))" />
</ItemGroup>
<Error Text="Following GitHub URLs do not contain commit hash: @(GithubUrlsWithoutHash) please use permalinks for code generation inputs (see https://help.github.com/en/github/managing-files-in-a-repository/getting-permanent-links-to-files) " Condition="'@(GithubUrlsWithoutHash)' != ''" />
<Error Text="Cannot define both $(AutoRestInput) and $(TypeSpecInput) in the same project" Condition="'$(TypeSpecInput)' != ''" />
<Exec Command="$(_AutoRestCommand)"/>
</Target>
<Target Name="_GenerateCodeForTypeSpec" Condition="'$(_GenerateCode)' == 'true' AND '$(TypeSpecInput)' != ''" >
<Error Text="You used skipped sync but didn't have the TempTypeSpecFiles in your project directory. Please run 'dotnet build /t:GenerateCode /p:SaveInputs=true' without SkipSync first at least once" Condition="'$(SkipSync)' == 'true' AND !Exists('$(MSBuildProjectDirectory)/../TempTypeSpecFiles')" />
<Exec Command="npm install --prefix $(MSBuildProjectDirectory)/../ @azure-tools/typespec-client-generator-cli --no-save" />
<Exec Condition="'$(SkipSync)' == 'true'" Command="$(_TypeSpecProjectGenerateCommand) $(_SaveInputs) $(_TypespecAdditionalOptions) $(_Debug)"/>
<Exec Condition="'$(SkipSync)' != 'true'" Command="$(_TypeSpecProjectSyncAndGenerateCommand) $(_SaveInputs) $(_LocalSpecRepo) $(_TypespecAdditionalOptions) $(_Debug)"/>
</Target>
<Target Name="GenerateTests" DependsOnTargets="GenerateSamples" />
<Target Name="GenerateSamples" Condition="'$(_GenerateCode)' == 'true' AND Exists('$(AutoRestInput)') AND $(IsMgmtLibrary) == 'true'">
<ReadLinesFromFile File="$(AutoRestInput)">
<Output TaskParameter="Lines" ItemName="AutoRestInputLines"/>
</ReadLinesFromFile>
<ItemGroup>
<GithubUrls Include="$([System.Text.RegularExpressions.Regex]::Match('%(AutoRestInputLines.Identity)', 'https?://(raw.)?github.+'))" />
<GithubUrlsWithoutIssues Include="%(GithubUrls.Identity)" Condition="! ($([System.Text.RegularExpressions.Regex]::IsMatch('%(GithubUrls.Identity)', '/issues/\d+')))" />
<GithubUrlsWithoutHash Include="%(GithubUrlsWithoutIssues.Identity)" Condition="! ($([System.Text.RegularExpressions.Regex]::IsMatch('%(GithubUrlsWithoutIssues.Identity)', '[\w\d]{40}')))" />
</ItemGroup>
<Error Text="Following GitHub URLs do not contain commit hash: @(GithubUrlsWithoutHash) please use permalinks for code generation inputs (see https://help.github.com/en/github/managing-files-in-a-repository/getting-permanent-links-to-files) " Condition="'@(GithubUrlsWithoutHash)' != ''" />
<Exec Command="npx autorest@$(AutoRestVersion) --max-memory-size=8192 --skip-csproj --skip-upgrade-check --version=$(AutoRestCoreVersion) $(AutoRestInput) $(AutoRestAdditionalParameters) --use=$(MSBuildThisFileDirectory)../tools/net8.0/any/ --output-folder=$(MSBuildProjectDirectory)/Generated --clear-output-folder=false --shared-source-folders="$(AzureCoreSharedCodeDirectory);$(AutoRestSharedCodeDirectory)" --testmodeler={} --mgmt-debug.skip-codegen=true"/>
</Target>
<PropertyGroup Condition="'$(_GenerateCode)' == 'true'">
<NoWarn>$(NoWarn);CA1812</NoWarn>
</PropertyGroup>
<ItemGroup Condition="'$(_GenerateCode)' == 'true' OR '$(IncludeGeneratorSharedCode)' == 'true'">
<Compile Include="$(AzureCoreSharedCodeDirectory)/**/*.cs" Condition="'$(IncludeAzureCoreSharedCode)' == 'true'" Link="Shared/Core/%(RecursiveDir)/%(Filename)%(Extension)" />
<Compile Include="$(AutoRestSharedCodeDirectory)/**/*.cs" Link="Shared/AutoRest/%(RecursiveDir)/%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup Condition="'$(IncludeManagementSharedCode)' == 'true'">
<Compile Include="$(ManagementSharedCodeDirectory)/**/*.cs" Link="Shared/Management/%(RecursiveDir)/%(Filename)%(Extension)" />
</ItemGroup>
</Project>