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

C#: Introduce extractor mode to identify DBs created with codeql test run #7515

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Jan 5, 2022

Passing --qltest to the extractor when run though codeql test run is not done yet, that will be done on an internal follow-up PR.

@hvitved hvitved requested a review from as a code owner Jan 5, 2022
@github-actions github-actions bot added the C# label Jan 5, 2022
Copy link
Contributor

@michaelnebel michaelnebel left a comment

Looks nice! I have added some questions/comments and suggestions.

{
if (arg == "--verbose")
Copy link
Contributor

@michaelnebel michaelnebel Jan 6, 2022

Choose a reason for hiding this comment

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

The semantics of the --verbose flag has now been changed by using the base.HandleFlag method. Is this intentional?

{
private readonly AssemblyList assemblyList = new AssemblyList();

public ExtractorOptions(string[] args)
{
Verbosity = Verbosity.Info;
Threads = System.Environment.ProcessorCount;
PDB = true;
Copy link
Contributor

@michaelnebel michaelnebel Jan 6, 2022

Choose a reason for hiding this comment

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

In the CommonOptions the logic for the PDB and CIL flags are connected. I suppose it doesn't matter as we didn't use the CIL flag before in the ExtractorOptions.

@@ -25,7 +25,7 @@ public override IEnumerable<IExtractionProduct> Contents
else
Context.TrapWriter.Archive(TransformedPath, text);

yield return Tuples.file_extraction_mode(this, 2);
yield return Tuples.file_extraction_mode(this, Context.Extractor.Mode | ExtractorMode.Pdb);
Copy link
Contributor

@michaelnebel michaelnebel Jan 6, 2022

Choose a reason for hiding this comment

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

Fantastic that we get rid of the magic number and rely on the flag, but shouldn't this only be ExtractorMode.Pdb?

@@ -61,7 +61,7 @@ public override void Populate(TextWriter trapFile)
}
}

trapFile.file_extraction_mode(this, Context.Extractor.Standalone ? 1 : 0);
trapFile.file_extraction_mode(this, Context.Extractor.Mode);
Copy link
Contributor

@michaelnebel michaelnebel Jan 6, 2022

Choose a reason for hiding this comment

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

Now printing the "entire" mode and not only, whether the it is standalone extraction to the trap file. Is this intentional?

private readonly ExtractorMode mode;
public override ExtractorMode Mode => mode;
Copy link
Contributor

@michaelnebel michaelnebel Jan 6, 2022

Choose a reason for hiding this comment

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

Suggested change
private readonly ExtractorMode mode;
public override ExtractorMode Mode => mode;
public override ExtractorMode Mode { get; };

mode = ExtractorMode.Standalone;
if (options.QlTest)
mode |= ExtractorMode.QlTest;
Copy link
Contributor

@michaelnebel michaelnebel Jan 6, 2022

Choose a reason for hiding this comment

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

Are we not strict on always using { } for single line if-statements (sometimes this can be overlooked in code-reviews if more statements are added to the if-block)?

public override bool Standalone => false;

private readonly ExtractorMode mode;
public override ExtractorMode Mode => mode;
Copy link
Contributor

@michaelnebel michaelnebel Jan 6, 2022

Choose a reason for hiding this comment

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

Same comments as for the StandaloneExtractor.

@@ -37,13 +37,18 @@ public abstract class CommonOptions : ICommandLineOptions
/// <summary>
/// Whether to extract PDB information.
/// </summary>
public bool PDB { get; private set; } = false;
public bool PDB { get; set; } = false;
Copy link
Contributor

@michaelnebel michaelnebel Jan 6, 2022

Choose a reason for hiding this comment

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

Maybe consider to use the HandleFlag method to set PDB instead of making PDB mutable (however, this will impact the CIL flag as well - but it seems to be un-unused).

/// <summary>
/// Whether extraction is done using `codeql test run`.
/// </summary>
public bool QlTest { get; private set; } = false;
Copy link
Contributor

@michaelnebel michaelnebel Jan 6, 2022

Choose a reason for hiding this comment

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

Excellent!

predicate isPdbSourceFile() {
exists(int i |
file_extraction_mode(this, i) and
i.bitAnd(2) = 2
Copy link
Contributor

@michaelnebel michaelnebel Jan 6, 2022

Choose a reason for hiding this comment

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

So this is needed because the entire "mode" is now used and you need to ensure that the specific flag (in this "2" which corresponds to PDB) is present?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants