Skip to content

C#: Extract compilation DB entity in standalone mode #14351

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 2 commits into from
Oct 3, 2023

Conversation

tamasvajk
Copy link
Contributor

No description provided.

@github-actions github-actions bot added the C# label Oct 2, 2023
@tamasvajk tamasvajk force-pushed the csharp/standalone-compilation branch from 176f4db to de45a9b Compare October 2, 2023 10:55
Comment on lines +244 to +247
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
{
Logger.Log(Severity.Error, " Unhandled exception analyzing {0}: {1}", "compilation", ex);
}

Check notice

Code scanning / CodeQL

Generic catch clause

Generic catch clause.
Comment on lines +70 to +71
catch
{ }

Check notice

Code scanning / CodeQL

Poor error handling: empty catch block

Poor error handling: empty catch block.
Comment on lines +70 to +71
catch
{ }

Check notice

Code scanning / CodeQL

Generic catch clause

Generic catch clause.
@tamasvajk
Copy link
Contributor Author

DCA looks okay: There are differences in the results of cs/diagnostics/extraction-errors on the standalone extracted project. Compiler errors are preferred over extraction errors, so now compiler errors are returned. Also, cs/diagnostics/successfully-extracted-files only lists files without extraction and compiler errors. Previously we had no compiler errors at all.

@tamasvajk tamasvajk marked this pull request as ready for review October 3, 2023 06:25
@tamasvajk tamasvajk requested a review from a team as a code owner October 3, 2023 06:26
@michaelnebel michaelnebel self-requested a review October 3, 2023 07:43
@@ -143,5 +143,37 @@ public static string NestPaths(ILogger logger, string? outerpath, string innerpa
}
return nested;
}

public static string GetTemporaryWorkingDirectory(out bool shouldCleanUp)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it makes sense to put these methods in class that implements IDisposable to ensure that cleanup happens if needed? Could TemporaryDirectory be re-used with some extra exposed methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The cleanup of the temporary directory is somewhat error prone. At the moment we basically expect the temporary directory to be cleaned up only at (or close to) application exit. Putting it in a more reusable class would suggest that you can dispose it any time, but that would break the application, because we currently store generated source files in this folder too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough.

{
progressMonitor.MissingNamespace(type);
}
var output = FileUtils.CreateTemporaryFile(".dll", out var shouldCleanUpContainingFolder);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we risk that anyone relies on us producing a csharp.dll for traced extraction?
Maybe we need a change note.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

csharp.dll was only used for standalone extraction, so I think changing it won't cause any major issue for anyone.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, of course - you are right.

this.options = options;
LogExtractorInfo(Extraction.Extractor.Version);
SetReferencePaths();

Entities.Compilation.Settings = (Directory.GetCurrentDirectory(), Array.Empty<string>());
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency: Can this be put in the Run method for the standalone extractor like it happens in the tracing extractor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't, because the Run method is in Semmle.Extraction.CSharp.Standalone and Compilation is internal.

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.

Looks really good!

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.

Looks good to me!

@tamasvajk tamasvajk merged commit df988e4 into github:main Oct 3, 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