-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix MilCodeGen #6135
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
Fix MilCodeGen #6135
Conversation
@@ -21,17 +21,8 @@ pushd %~dp0\.. | |||
|
|||
call %~dp0\SetClrPath.cmd | |||
|
|||
copy %CspExePath%\csp.exe %clrpath% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the context for copying csp to clrpath but it seemed unnecessary.
@@ -1,6 +1 @@ | |||
set clrpath=%MANAGED_TOOLS_ROOT%\%MANAGED_REFS_VERSION% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know how to get clrpath automatically. It's the path used by sn.exe but I couldn't find where to get it.
|
||
:: Revert any generated files which haven't changed | ||
if {%_NoRevertFlag%} EQU {} call %~dp0\tf_GeneratedFiles %OutputDir% %~dp0\GeneratedElements.txt revert -a | ||
call %~dp0\InvokeCSP.cmd %Options% -rsp:main\Elements.rsp -enableCsPrime -r:"System.Xml.dll" -- %_SdFlag% -xmlFile:xml\Elements.xml -dataType:MS.Internal.MilCodeGen.ResourceModel.CG -o:"%OutputDir%" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the argument -clrdir
and the full path in the argument -r
. It works without it and avoids the need of finding the path for .Net Framework reference assemblies.
@@ -0,0 +1,19 @@ | |||
-s:main\SimpleGenerator.cs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created this file and Resources.rsp by hand because they didn't exist. They were probably missed when adding the code in this repo because *.rsp files are excluded in the gitignore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are 3 .rsp files in internal source, Elements Resources and SimpleGenerator.
I am still looking at these and trying to make sense, but in the meanwhile here are the contents of the 3 files :
- Elements.rsp
-rsp:main\SimpleGenerator.rsp
-s:Generators\Elements.cs
-s:Generators\IAnimatableHelper.cs
-s:ResourceModel\Elements.cs
-s:ResourceModel\Generated\Elements.cs
- Resources.rsp
-s:main\ResourceGenerator.cs
-s:main\cmdline\IndentedWriter.cs
-s:main\cmdline\Utility.cs
-s:main\cmdline\CommandLineArguments.cs
-s:Runtime\DelimitedList.cs
-s:Runtime\OrList.cs
-s:Runtime\CodeSink.cs
-s:Runtime\FileCodeSink.cs
-s:Runtime\StringCodeSink.cs
-s:Runtime\ParameterList.cs
-s:Runtime\XmlLoader.cs
-s:Runtime\GeneratorMethods.cs
-s:ResourceModel\Command.cs
-s:ResourceModel\Enum.cs
-s:ResourceModel\Field.cs
-s:ResourceModel\Primitive.cs
-s:ResourceModel\Realization.cs
-s:ResourceModel\RenderData.cs
-s:ResourceModel\Resource.cs
-s:ResourceModel\ResourceModel.cs
-s:ResourceModel\Struct.cs
-s:ResourceModel\Type.cs
-s:ResourceModel\Array.cs
-s:helpers\CodeGenHelpers.cs
-s:helpers\CollectionHelper.cs
-s:helpers\EmptyClassHelper.cs
-s:helpers\ManagedStyle.cs
-s:helpers\PaddedCommand.cs
-s:helpers\StringHelpers.cs
-s:helpers\Style.cs
-s:helpers\EnumHelper.cs
-s:helpers\StructHelper.cs
-s:generators\AnimatableTemplate.cs
-s:generators\AnimationBaseTemplate.cs
-s:generators\AnimationClockResource.cs
-s:generators\AnimationResourceTemplate.cs
-s:generators\AnimationTemplate.cs
-s:generators\AnimationUsingKeyFramesTemplate.cs
-s:generators\CommandProcessMessage.cs
-s:generators\CommandStructure.cs
-s:generators\CommandType.cs
-s:generators\DiscreteKeyFrameTemplate.cs
-s:generators\DuceResource.cs
-s:generators\EasingKeyFrameTemplate.cs
-s:generators\FrameworkElementTemplate.cs
-s:generators\IAnimatableHelper.cs
-s:generators\KeyFrameTemplate.cs
-s:generators\KeyFrameCollectionTemplate.cs
-s:generators\LinearKeyFrameTemplate.cs
-s:generators\ManagedEnum.cs
-s:generators\ManagedResource.cs
-s:generators\ManagedStruct.cs
-s:generators\PolySegmentTemplate.cs
-s:generators\RenderData.cs
-s:generators\ResourceFactory.cs
-s:generators\ResourceType.cs
-s:generators\SplineKeyFrameTemplate.cs
-s:generators\Template.cs
-s:generators\MiscDef.cs
-s:generators\MilRenderTypesGenerated.cs
-s:generators\WincodecPrivateGenerated.cs
- SimpleGenerator.rsp
-s:main\SimpleGenerator.cs
-s:main\cmdline\IndentedWriter.cs
-s:main\cmdline\Utility.cs
-s:main\cmdline\CommandLineArguments.cs
-s:Runtime\DelimitedList.cs
-s:Runtime\OrList.cs
-s:Runtime\CodeSink.cs
-s:Runtime\FileCodeSink.cs
-s:Runtime\StringCodeSink.cs
-s:Runtime\ParameterList.cs
-s:Runtime\GeneratorMethods.cs
-s:ResourceModel\CG.cs
-s:helpers\ManagedStyle.cs
-s:helpers\Style.cs
You stole my next target 😄 |
I pushed a bunch of commit to try to reduce the diff but I couldn't reduce it much further because the bulk of the changes in generated code come from whitespace added because of conditional code which adds an empty line (Example: This code generates these whitespaces). |
With 308 changed files it's almost impossible to understand what has changed :/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think would be worth to keep build changes from style formatting changes separately. I have hopes that this allow speedup of the review, or at least schedule it for testing.
@@ -250,12 +250,15 @@ internal void RemoveAtWithoutFiringPublicEvents(int index) | |||
|
|||
WritePreamble(); | |||
|
|||
if (!Object.ReferenceEquals(_collection[index], value)) | |||
if (!Object.ReferenceEquals(_collection[ index ], value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These kind of changes is against current code style. I assume that it would be hard to convince WPF team on this kind of changes. Also they are reduce ability understand what's going on.
OnFreezablePropertyChanged(oldValue, value); | ||
|
||
_collection[index] = value; | ||
_collection[ index ] = value; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these empty lines needed?
@@ -236,8 +245,11 @@ void DUCE.IResource.ReleaseOnChannel(DUCE.Channel channel) | |||
|
|||
if (_duceResource.ReleaseOnChannel(channel)) | |||
{ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why these two lines? I see these a lot. That's confusing.
@kant2002 @omariom Sorry about the delay, I forgot about this PR. All the files are generated using MilCodeGen without any modifications by hand so all the changes are necessary. It looks like a lot of generated files were formatted when adding the files to this repo. |
3b939e3
to
4fdf462
Compare
I rebased, fixed the conflicts and synced MilCodeGen to the generated code since changes to generated files was merged into main. @dotnet/wpf-developers: Could this be considered for the next test pass ? MilCodeGen is outdated compared to the generated files in the main branch because generated files get changed manually because we cannot run MilCodeGen. |
4fdf462
to
db55009
Compare
I rebased to fix the conflicts. I had to restore a bunch of usings that were removed because they were unused but the problem is that they were removed from files that were generated from the same template and some file didn't need the usings and some did so to keep it unified all files generated from the same template have the same usings. I did remove usings that none of the files generated from the same template needed. |
@ThomasGoulet73, I have started looking at this PR. I was going through the README files in this area, and my general understanding is that MilCodeGen uses the It can basically be divided into three parts I guess :
If my understanding is correct, will it be possible to break the PR into smaller PRs that do the things above. Also regarding fixing the csp.exe tool, there are some unit tests for the Csp tool were you able to get them to run ? I will try to run mcg for .NET Framework codebase, I am guessing there it will be in a running state, as the targets files imported in csp.csproj and other files are present there. |
I tried running MCG of Framework codebase and it works there. I will try to match the steps here with logs that are generated from the run. If possible, I will attach a log file for the run. |
Yes, @h3xds1nz also suggested spliting it here #10310 (comment). What I think I'm going to do is:
The PRs 1 and 2 won't include changes to shipping code so it will be easy to review. The PRs in step 3 will include changes to shipping code but it shouldn't change the behavior of the code, and since it will be 1 PR per project it will be easier to review.
I can't seem to find those tests you're talking about, could you link me those tests ? |
Nevermind, I just found it and I'm working on fixing it. Could you check if you have the file |
@ThomasGoulet73 Here's the content of that file
This sounds like a good division. |
Thanks @dipeshmsft, I was able to reverse engineer the content CspProject.rsp when I was working on #10417 but it helps to validate that what I did was correct.
I opened #10417 as the first part of this work, could you prioritize it ? Realistically it's very low to no risk since it doesn't affect shipping code and worse case scenario we can always revert it. |
I am already on it. There is still some part of MCG that I haven't gone through, but I will be mostly done by tomorrow. |
@dipeshmsft Great to see progress on this one, thanks :) |
@ThomasGoulet73 , I think we can go ahead and close the PR now as most of the other MilCodeGen PRs are already merged in main. |
Yes, thanks a lot for reviewing all of this. |
Description
This PR aims to fix MilCodeGen which seems to be very outdated and it doesn't seem like it ever worked in this repo (It probably worked in the internal repo for Microsoft).
Since it does not seem like it ever worked, I did these changes just by deducing how it's supposed to work so this PR might be totally wrong.
I noticed a couple of changes in the generated code other than white-space and license header where I don't know whether the source of truth is the new generated code or the existing generated code (It's mostly comments that differ between both).
This PR unblocks PRs like this one: #5651.
Customer Impact
None.
Regression
No.
Testing
I tested this fix locally using this command
build -projects "src\Microsoft.DotNet.Wpf\src\WpfGfx\codegen\mcg\mcg.proj"
and by looking at the changes and doing a normal build afterwards.Risk
I think the risk is pretty low since it's only used for development in this repo and the worse that can happen is to be unable to run MilCodeGen (It didn't work before this PR so it can only be an improvement). All the generated code is checked out in Git so it's easier to validate that the generated code is good.