Skip to content

Conversation

@dougbu
Copy link
Contributor

@dougbu dougbu commented Jan 4, 2022

[release/6.0] Work around dotnet/msbuild#3274

Description

nits:

  • add comment about batching w/ a code generator that uses %(OutputPath) as a directory
  • fix %(SourceDocument) metadata
    • primarily for back-tracing in detailed / binary logs
  • remove useless %(OutputPathExtension) metadata; use %(Extension)
  • remove useless ConsoleClient test asset project

Handle symbolic links in TemporaryDirectory

  • e.g. on macOS /var/folders resolves to /private/var/folders

Customer impact

Without this change, customers cannot use OpenAPI code generators that generate multiple files. @darrelmiller reported #38547 for once such code generator but others exist or could exist soon-ish.

Regression

No, this problem wasn't noticed in the past due to inadequate testing i.e. we mainly focused on the NSwag code generator which generates a single file per OpenAPI document.

Risk

Very low. Using the recommended workaround for a known msbuild problem.

Verification

Both manual and automated testing. In fact, added a lot of missing integration tests covering many scenarios that were previously missed. (Previous automated tests mostly ignored our .targets files.)

Packaging changes reviewed?

N/A

- `cherry-pick` of e2707e1

Work around dotnet/msbuild#3274
- #38547
- handle a ApiDescription.Client code generator that uses `%(OutputPath)` as a directory
  - see also <https://stackoverflow.com/questions/48868060/can-a-task-itemgroup-glob-files>
- add tests for Microsoft.Extensions.ApiDescription.Client.targets
  - make `TemporaryCSharpProject` slightly extensible
  - allow project additions to `TemporaryDirectory` after `Create()`

nits:
- add comment about batching w/ a code generator that uses `%(OutputPath)` as a directory
- fix `%(SourceDocument)` metadata
  - primarily for back-tracing in detailed / binary logs
- remove useless `%(OutputPathExtension)` metadata; use `%(Extension)`
- remove useless `ConsoleClient` test asset project

Handle symbolic links in `TemporaryDirectory`
- e.g. on macOS /var/folders resolves to /private/var/folders
@dougbu dougbu added the area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI label Jan 4, 2022
@dougbu dougbu requested a review from Pilchie as a code owner January 4, 2022 01:02
@ghost ghost added this to the 6.0.x milestone Jan 4, 2022
@ghost
Copy link

ghost commented Jan 4, 2022

Hi @dougbu. If this is not a tell-mode PR, please make sure to follow the instructions laid out in the servicing process document.
Otherwise, please add tell-mode label.

Comment on lines -123 to +145
<!-- Otherwise, add all descendant files with the expected extension. -->
<TypeScriptCompile Include="@(_Directories -> '%(Identity)/**/*.ts;%(Identity)/**/*.tsx')"
Exclude="@(TypeScriptCompile)">
<SourceDocument>%(_Directories.FullPath)</SourceDocument>
</TypeScriptCompile>
<!--
Otherwise, add all descendant files with the expected extension. Glob into _Directories before updating
TypeScriptCompile or Compile items. See <https://github.com/dotnet/msbuild/issues/3274> and workaround in
<https://stackoverflow.com/questions/48868060/can-a-task-itemgroup-glob-files>. Unfortunately, this workaround
loses SourceDocument and other metadata.
-->
<PropertyGroup>
<_TypeScriptCompileItemsFromDirectories>@(_Directories -> '%(Identity)/**/*.ts;%(Identity)/**/*.tsx')</_TypeScriptCompileItemsFromDirectories>
<_CompileItemsFromDirectories>@(_Directories -> '%(Identity)/**/*$(DefaultLanguageSourceExtension)')</_CompileItemsFromDirectories>
</PropertyGroup>

<Compile Include="@(_Directories -> '%(Identity)/**/*.$(DefaultLanguageSourceExtension)')"
<ItemGroup>
<TypeScriptCompile Include="$(_TypeScriptCompileItemsFromDirectories)" Exclude="@(TypeScriptCompile)" />

<Compile Include="$(_CompileItemsFromDirectories)"
Exclude="@(Compile)"
Condition="'$(DefaultLanguageSourceExtension)' != '.ts'">
<SourceDocument>%(_Directories.FullPath)</SourceDocument>
</Compile>
Condition="'$(DefaultLanguageSourceExtension)' != '.ts'" />

<FileWrites Exclude="@(FileWrites)"
Include="@(_Files);@(_Directories -> '%(Identity)/**/*.ts;%(Identity)/**/*.tsx;%(Identity)/**/*.$(DefaultLanguageSourceExtension)')" />
<FileWrites Include="@(_Files);$(_TypeScriptCompileItemsFromDirectories);$(_CompileItemsFromDirectories)"
Exclude="@(FileWrites)" />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These lines contain the core fix. Is it necessary to remove fixes for "nits" mentioned in PR description❔ I was hoping to avoid that extra work and lean toward keeping the branches consistent, especially in cases where the changes to src files remain narrow.

Copy link
Member

Choose a reason for hiding this comment

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

I'm cooling with keeping the nits. I think they make this code a little clearer.

@dougbu
Copy link
Contributor Author

dougbu commented Jan 4, 2022

/fyi @wtgodbe since you approved #39146 for 'main'

@dougbu dougbu added the Servicing-consider Shiproom approval is required for the issue label Jan 4, 2022
@ghost
Copy link

ghost commented Jan 4, 2022

Hi @dougbu. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge.

To learn more about how to prepare a servicing PR click here.

@dougbu dougbu added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Jan 4, 2022
@dougbu
Copy link
Contributor Author

dougbu commented Jan 4, 2022

@rafikiassumani-msft could you please review or have someone review this PR❔

Condition="$([System.IO.File]::Exists('%(OpenApiReference.OutputPath)'))">
<OutputPathExtension>$([System.IO.Path]::GetExtension('%(OpenApiReference.OutputPath)'))</OutputPathExtension>
</_Files>
Condition="$([System.IO.File]::Exists('%(OpenApiReference.OutputPath)'))" />
Copy link
Member

Choose a reason for hiding this comment

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

Great cleanup here!

Comment on lines -123 to +145
<!-- Otherwise, add all descendant files with the expected extension. -->
<TypeScriptCompile Include="@(_Directories -> '%(Identity)/**/*.ts;%(Identity)/**/*.tsx')"
Exclude="@(TypeScriptCompile)">
<SourceDocument>%(_Directories.FullPath)</SourceDocument>
</TypeScriptCompile>
<!--
Otherwise, add all descendant files with the expected extension. Glob into _Directories before updating
TypeScriptCompile or Compile items. See <https://github.com/dotnet/msbuild/issues/3274> and workaround in
<https://stackoverflow.com/questions/48868060/can-a-task-itemgroup-glob-files>. Unfortunately, this workaround
loses SourceDocument and other metadata.
-->
<PropertyGroup>
<_TypeScriptCompileItemsFromDirectories>@(_Directories -> '%(Identity)/**/*.ts;%(Identity)/**/*.tsx')</_TypeScriptCompileItemsFromDirectories>
<_CompileItemsFromDirectories>@(_Directories -> '%(Identity)/**/*$(DefaultLanguageSourceExtension)')</_CompileItemsFromDirectories>
</PropertyGroup>

<Compile Include="@(_Directories -> '%(Identity)/**/*.$(DefaultLanguageSourceExtension)')"
<ItemGroup>
<TypeScriptCompile Include="$(_TypeScriptCompileItemsFromDirectories)" Exclude="@(TypeScriptCompile)" />

<Compile Include="$(_CompileItemsFromDirectories)"
Exclude="@(Compile)"
Condition="'$(DefaultLanguageSourceExtension)' != '.ts'">
<SourceDocument>%(_Directories.FullPath)</SourceDocument>
</Compile>
Condition="'$(DefaultLanguageSourceExtension)' != '.ts'" />

<FileWrites Exclude="@(FileWrites)"
Include="@(_Files);@(_Directories -> '%(Identity)/**/*.ts;%(Identity)/**/*.tsx;%(Identity)/**/*.$(DefaultLanguageSourceExtension)')" />
<FileWrites Include="@(_Files);$(_TypeScriptCompileItemsFromDirectories);$(_CompileItemsFromDirectories)"
Exclude="@(FileWrites)" />
Copy link
Member

Choose a reason for hiding this comment

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

I'm cooling with keeping the nits. I think they make this code a little clearer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI Servicing-approved Shiproom has approved the issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants