Skip to content

C#: Generate source files from cshtml files in standalone #13957

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

Merged
merged 13 commits into from
Aug 22, 2023

Conversation

tamasvajk
Copy link
Contributor

@tamasvajk tamasvajk commented Aug 14, 2023

Supersedes #13722.

This PR adds cshtml/razor file handling to the standalone extractor. We're generating C# files to a temporary location from the view files with csc by running the razor source generators on all the cshtml/razor files in the repo. The generated source files are then extracted as normal source files.

@tamasvajk tamasvajk requested review from a team as code owners August 14, 2023 14:01
@tamasvajk tamasvajk marked this pull request as draft August 14, 2023 14:01
@tamasvajk tamasvajk force-pushed the razor-standalone-2 branch 3 times, most recently from 6a72e79 to 4ce95b9 Compare August 18, 2023 08:58
@tamasvajk tamasvajk removed the request for review from a team August 18, 2023 09:24
@github-actions github-actions bot removed the C++ label Aug 18, 2023
@tamasvajk tamasvajk marked this pull request as ready for review August 18, 2023 11:54
@tamasvajk tamasvajk requested a review from a team August 18, 2023 11:54
@michaelnebel michaelnebel self-assigned this Aug 21, 2023
Comment on lines +112 to +115
catch
{
// Ignore
}

Check notice

Code scanning / CodeQL

Generic catch clause

Generic catch clause.
Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

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

This looks really really good!
It must have taken lots of reading and trial and error to get it to work!
Only some minor comments and questions.

@@ -131,6 +132,40 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
progressMonitor.UnresolvedReference(r.Key, r.Value);
}

var webViewExtractionOption = Environment.GetEnvironmentVariable("CODEQL_EXTRACTOR_CSHARP_STANDALONE_EXTRACT_WEB_VIEWS");
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we consider to add a group of extractor options for buildless or standalone to make it easier for a user to specify this flag (not as a part of this PR)?

Maybe we should add this "option" to the standalone extractor Option and read the environment variable as a part of the creating the options object (and also make it a property on the DependencyOption) to avoid inlining the environment variable read here.

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 think in the long run we'll have a couple of configuration options, so it definitely makes sense to group them. At the same time, we should try to minimize the number of options as the extractor should "just work". I don't have full confidence in this cshtml to C# generation, so I wanted to hide it behind an undocumented feature flag, but eventually I don't think there's any reason to not have this run all the time.

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense!
In any case, we could consider to do the environment variable read in the options class instead (this might make it easier to test the entire DependencyManager class at some point in time), but we don't have to do it now.

Comment on lines +177 to +181
catch (Exception ex)
{
// It's okay, we tried our best to generate source files from cshtml files.
progressMonitor.LogInfo($"Failed to generate source files from cshtml files: {ex.Message}");
}

Check notice

Code scanning / CodeQL

Generic catch clause

Generic catch clause.
Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

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

Really good work @tamasvajk !!

@tamasvajk tamasvajk merged commit afe1e9c into github:main Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants