-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
6a72e79
to
4ce95b9
Compare
8612891
to
7b6c299
Compare
7b6c299
to
b5cdaa2
Compare
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyManager.cs
Fixed
Show fixed
Hide fixed
catch | ||
{ | ||
// Ignore | ||
} |
Check notice
Code scanning / CodeQL
Generic catch clause
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.
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"); |
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.
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.
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 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.
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.
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.
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyManager.cs
Show resolved
Hide resolved
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Sdk.cs
Outdated
Show resolved
Hide resolved
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyManager.cs
Outdated
Show resolved
Hide resolved
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Razor.cs
Outdated
Show resolved
Hide resolved
csharp/ql/integration-tests/all-platforms/cshtml_standalone/Files.expected
Show resolved
Hide resolved
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
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.
Really good work @tamasvajk !!
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.