Skip to content

Commit ef36d6b

Browse files
authored
Merge pull request #133 from microsoft/powershell-extract-implicit-models-followup
PS: #132 follow-up
2 parents 43f986c + a2158e2 commit ef36d6b

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

powershell/codeql-extractor.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@ file_types:
77
- name: powershell
88
display_name: powershellscripts
99
extensions:
10-
- .ps1
10+
- .ps1
11+
- .psd1
12+
options:
13+
skip_psmodulepath_files:
14+
title: Skip PSModulePath files.
15+
description: Whether to avoid extracting source files in paths specified by the PSModulePath environment variable.
16+
type: string
17+
pattern: "^(false|true)$"

powershell/extractor/Semmle.Extraction.PowerShell.Standalone/Options.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.IO;
34
using System.Linq;
@@ -120,6 +121,24 @@ private static FileInfo[] GetDefaultFiles()
120121
}
121122
}
122123

124+
/// <summary>
125+
/// Returns true if the extractor should skip files in the PSModulePath because the
126+
/// environment variable CODEQL_EXTRACTOR_POWERSHELL_OPTION_SKIP_PSMODULEPATH_FILES
127+
/// is set to a truthy value.
128+
/// </summary>
129+
private static bool GetDefaultSkipPSModulePathFiles()
130+
{
131+
var skip = System.Environment.GetEnvironmentVariable(
132+
"CODEQL_EXTRACTOR_POWERSHELL_OPTION_SKIP_PSMODULEPATH_FILES"
133+
);
134+
bool b = skip != null && skip.ToLower() != "false";
135+
if (b)
136+
{
137+
System.Console.WriteLine("Skipping files in PSModulePath");
138+
}
139+
return b;
140+
}
141+
123142
/// <summary>
124143
/// The directory or file containing the source code;
125144
/// </summary>
@@ -134,7 +153,7 @@ private static FileInfo[] GetDefaultFiles()
134153
/// Whether to extract files in the paths found in the `PSModulePath`
135154
/// environment variable.
136155
/// </summary>
137-
public bool SkipPSModulePathFiles { get; private set; } = false;
156+
public bool SkipPSModulePathFiles { get; private set; } = GetDefaultSkipPSModulePathFiles();
138157

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

180203
private Options() { }

powershell/tools/qltest.cmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type NUL && "%CODEQL_DIST%\codeql.exe" database index-files ^
66
--size-limit=5m ^
77
--language=powershell ^
88
--working-dir=. ^
9+
--extractor-option="powershell.skip_psmodulepath_files=true" ^
910
"%CODEQL_EXTRACTOR_POWERSHELL_WIP_DATABASE%"
1011

1112
exit /b %ERRORLEVEL%

0 commit comments

Comments
 (0)