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

Fix MilCodeGen #6135

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ThomasGoulet73
Copy link
Contributor

@ThomasGoulet73 ThomasGoulet73 commented Feb 16, 2022

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.

@ThomasGoulet73 ThomasGoulet73 requested a review from a team as a code owner February 16, 2022 04:37
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Feb 16, 2022
@ghost ghost requested review from dipeshmsft, singhashish-wpf and SamBent February 16, 2022 04:37
@@ -21,17 +21,8 @@ pushd %~dp0\..

call %~dp0\SetClrPath.cmd

copy %CspExePath%\csp.exe %clrpath%
Copy link
Contributor Author

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%
Copy link
Contributor Author

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%"
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

@@ -96,7 +96,7 @@ Parameters parameters

// Add some implicit referenced assemblies.

referencedAssemblies.Add(Path.Combine(parameters.ClrDir, "System.dll"));
referencedAssemblies.Add(string.IsNullOrEmpty(parameters.ClrDir) ? "System.dll" : Path.Combine(parameters.ClrDir, "System.dll"));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It says in the usage of this project that parameters.ClrDir is optional but it failed here.

@kant2002
Copy link
Contributor

You stole my next target 😄

@ThomasGoulet73
Copy link
Contributor Author

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).

@omariom
Copy link
Contributor

omariom commented Mar 8, 2022

With 308 changed files it's almost impossible to understand what has changed :/

Copy link
Contributor

@kant2002 kant2002 left a 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))
Copy link
Contributor

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;

Copy link
Contributor

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))
{

Copy link
Contributor

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.

@ThomasGoulet73
Copy link
Contributor Author

@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.
For example, TextDecorationCollection from referencesource.microsoft.com is a lot closer to this repo with the changes in this PR than without this PR. TextDecorationCollection in this repo with the changes in this PR vs TextDecorationCollection in this repo without the changes in this PR. TextDecorationCollection did not change since the initial commit of PresentationCore.

@dipeshmsft dipeshmsft self-assigned this Jun 18, 2022
@ghost ghost assigned ThomasGoulet73 Jun 18, 2022
@pchaurasia14 pchaurasia14 added the Community Contribution A label for all community Contributions label Jul 20, 2022
@ThomasGoulet73 ThomasGoulet73 force-pushed the fix-milcodegen-build branch from 3b939e3 to 4fdf462 Compare May 1, 2024 01:21
@ThomasGoulet73
Copy link
Contributor Author

ThomasGoulet73 commented May 1, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants