Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion powershell/codeql-extractor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ file_types:
- name: powershell
display_name: powershellscripts
extensions:
- .ps1
- .ps1
- .psd1
options:
skip_psmodulepath_files:
title: Skip PSModulePath files.
description: Whether to avoid extracting source files in paths specified by the PSModulePath environment variable.
type: string
pattern: "^(false|true)$"
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -120,6 +121,24 @@ private static FileInfo[] GetDefaultFiles()
}
}

/// <summary>
/// Returns true if the extractor should skip files in the PSModulePath because the
/// environment variable CODEQL_EXTRACTOR_POWERSHELL_OPTION_SKIP_PSMODULEPATH_FILES
/// is set to a truthy value.
/// </summary>
private static bool GetDefaultSkipPSModulePathFiles()
{
var skip = System.Environment.GetEnvironmentVariable(
"CODEQL_EXTRACTOR_POWERSHELL_OPTION_SKIP_PSMODULEPATH_FILES"
);
bool b = skip != null && skip.ToLower() != "false";
if (b)
{
System.Console.WriteLine("Skipping files in PSModulePath");
}
return b;
}

/// <summary>
/// The directory or file containing the source code;
/// </summary>
Expand All @@ -134,7 +153,7 @@ private static FileInfo[] GetDefaultFiles()
/// Whether to extract files in the paths found in the `PSModulePath`
/// environment variable.
/// </summary>
public bool SkipPSModulePathFiles { get; private set; } = false;
public bool SkipPSModulePathFiles { get; private set; } = GetDefaultSkipPSModulePathFiles();

/// <summary>
/// Whether errors were encountered parsing the arguments.
Expand Down Expand Up @@ -172,9 +191,13 @@ public static void ShowHelp(System.IO.TextWriter output)
" --exclude:xxx Exclude a file or directory (can be specified multiple times)"
);
output.WriteLine(" --dry-run Stop before extraction");
output.WriteLine(" --threads:nnn Specify number of threads (default=CPU cores)");
output.WriteLine(
" --threads:nnn Specify number of threads (default=CPU cores)"
);
output.WriteLine(" --verbose Produce more output");
output.WriteLine(" --skip-psmodulepath-files Avoid extracting source files in paths specified by the PSModulePath environment variable.");
output.WriteLine(
" --skip-psmodulepath-files Avoid extracting source files in paths specified by the PSModulePath environment variable."
);
}

private Options() { }
Expand Down
1 change: 1 addition & 0 deletions powershell/tools/qltest.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type NUL && "%CODEQL_DIST%\codeql.exe" database index-files ^
--size-limit=5m ^
--language=powershell ^
--working-dir=. ^
--extractor-option="powershell.skip_psmodulepath_files=true" ^
"%CODEQL_EXTRACTOR_POWERSHELL_WIP_DATABASE%"

exit /b %ERRORLEVEL%