Skip to content

Commit 1eb9a01

Browse files
JamesWTruherbergmeister
authored andcommitted
Update, simplify, and consolidate build scripts (#1082)
* consolidate build of script analyzer into module Require any 2.1 sdk for building, this way we can build with the same sdk as PowerShell core * Have git ignore vim swap files and the test results file * Only special case linux for the customized rule tests * Update to build scripts. To build for core, simply type ./build, to build all flavors and documentation type ./build -all. You can now run tests as well via ./build -Test. * Modify readme to match new build instructions * Add ubuntu16 docker file to build scripts * change to use psversion rather than analyzerversion because it's really about the version of PS, not the analyzer * Add copyright banners to script and module * Fix repo to point to the official repo * Update appveyor scripts to use new build script * Forcing installation of platyPS if not found when building documentation * Be sure to skip uses of TypeDefinitionAst on both PSV3 and PSV4 * Modified logic to not build full on non-Windows Add additional verbose statements for debugging * fix issue with incorrect build configuration When simplifying to use only psversion, add back the 'PSV' prolog to configuration * reduce build matrix to accellerate CI testing * Revert "reduce build matrix to accellerate CI testing" This reverts commit b3018ea.
1 parent 2df52ab commit 1eb9a01

18 files changed

+460
-361
lines changed

.gitignore

+7-1
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,10 @@ FakesAssemblies/
205205
*.opt
206206

207207
##Our project binplace location
208-
PSScriptAnalyzer/
208+
PSScriptAnalyzer/
209+
210+
# Vim swap files
211+
*.swp
212+
213+
# Test result file
214+
TestResults.xml

Engine/Generic/RuleSuppression.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ public static List<RuleSuppression> GetSuppressions(IEnumerable<AttributeAst> at
360360
targetAsts = scopeAst.FindAll(item => item is FunctionDefinitionAst && reg.IsMatch((item as FunctionDefinitionAst).Name), true);
361361
goto default;
362362

363-
#if !PSV3
363+
#if !(PSV3||PSV4)
364364

365365
case "class":
366366
targetAsts = scopeAst.FindAll(item => item is TypeDefinitionAst && reg.IsMatch((item as TypeDefinitionAst).Name), true);

Engine/Helper.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ public bool IsDscResourceClassBased(ScriptBlockAst ast)
509509
return false;
510510
}
511511

512-
#if !PSV3
512+
#if !(PSV3||PSV4)
513513

514514
List<string> dscResourceFunctionNames = new List<string>(new string[] { "Test", "Get", "Set" });
515515

@@ -1018,7 +1018,7 @@ internal VariableAnalysis InitializeVariableAnalysisHelper(Ast ast, VariableAnal
10181018
/// <param name="scriptAst"></param>
10191019
/// <returns></returns>
10201020

1021-
#if PSV3
1021+
#if (PSV3||PSV4)
10221022

10231023
public string GetTypeFromReturnStatementAst(Ast funcAst, ReturnStatementAst ret)
10241024

@@ -1089,7 +1089,7 @@ public string GetTypeFromReturnStatementAst(Ast funcAst, ReturnStatementAst ret,
10891089
/// <param name="classes"></param>
10901090
/// <returns></returns>
10911091

1092-
#if PSV3
1092+
#if (PSV3||PSV4)
10931093

10941094
public string GetTypeFromMemberExpressionAst(MemberExpressionAst memberAst, Ast scopeAst)
10951095

@@ -1106,7 +1106,7 @@ public string GetTypeFromMemberExpressionAst(MemberExpressionAst memberAst, Ast
11061106

11071107
VariableAnalysisDetails details = null;
11081108

1109-
#if !PSV3
1109+
#if !(PSV3||PSV4)
11101110

11111111
TypeDefinitionAst psClass = null;
11121112

@@ -1149,7 +1149,7 @@ public string GetTypeFromMemberExpressionAst(MemberExpressionAst memberAst, Ast
11491149
/// <param name="analysisDetails"></param>
11501150
/// <returns></returns>
11511151

1152-
#if PSV3
1152+
#if (PSV3||PSV4)
11531153

11541154
internal string GetTypeFromMemberExpressionAstHelper(MemberExpressionAst memberAst, VariableAnalysisDetails analysisDetails)
11551155

@@ -1162,7 +1162,7 @@ internal string GetTypeFromMemberExpressionAstHelper(MemberExpressionAst memberA
11621162
//Try to get the type without using psClass first
11631163
Type result = AssignmentTarget.GetTypeFromMemberExpressionAst(memberAst);
11641164

1165-
#if !PSV3
1165+
#if !(PSV3||PSV4)
11661166

11671167
//If we can't get the type, then it may be that the type of the object being invoked on is a powershell class
11681168
if (result == null && psClass != null && analysisDetails != null)
@@ -1270,7 +1270,7 @@ public Dictionary<string, List<RuleSuppression>> GetRuleSuppression(Ast ast)
12701270
ruleSuppressionList.AddRange(GetSuppressionsFunction(funcAst));
12711271
}
12721272

1273-
#if !PSV3
1273+
#if !(PSV3||PSV4)
12741274
// Get rule suppression from classes
12751275
IEnumerable<TypeDefinitionAst> typeAsts = ast.FindAll(item => item is TypeDefinitionAst, true).Cast<TypeDefinitionAst>();
12761276

@@ -1322,7 +1322,7 @@ internal List<RuleSuppression> GetSuppressionsFunction(FunctionDefinitionAst fun
13221322
return result;
13231323
}
13241324

1325-
#if !PSV3
1325+
#if !(PSV3||PSV4)
13261326
/// <summary>
13271327
/// Returns a list of rule suppression from the class
13281328
/// </summary>
@@ -2039,7 +2039,7 @@ private object VisitStatementHelper(StatementAst statementAst)
20392039
return null;
20402040
}
20412041

2042-
#if PSV3
2042+
#if (PSV3||PSV4)
20432043

20442044
statementAst.Visit(this);
20452045

@@ -2755,7 +2755,7 @@ public class FindPipelineOutput : ICustomAstVisitor
27552755
{
27562756
List<Tuple<string, StatementAst>> outputTypes;
27572757

2758-
#if !PSV3
2758+
#if !(PSV3||PSV4)
27592759

27602760
IEnumerable<TypeDefinitionAst> classes;
27612761

@@ -2797,7 +2797,7 @@ static FindPipelineOutput()
27972797
/// </summary>
27982798
/// <param name="ast"></param>
27992799

2800-
#if PSV3
2800+
#if (PSV3||PSV4)
28012801

28022802
public FindPipelineOutput(FunctionDefinitionAst ast)
28032803

@@ -2828,7 +2828,7 @@ public FindPipelineOutput(FunctionDefinitionAst ast, IEnumerable<TypeDefinitionA
28282828
/// </summary>
28292829
/// <returns></returns>
28302830

2831-
#if PSV3
2831+
#if (PSV3||PSV4)
28322832

28332833
public static List<Tuple<string, StatementAst>> OutputTypes(FunctionDefinitionAst funcAst)
28342834
{

Engine/VariableAnalysis.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public void AnalyzeImpl(Ast ast, VariableAnalysis outerAnalysis)
205205
parent = parent.Parent;
206206
}
207207

208-
#if !PSV3
208+
#if !(PSV3||PSV4)
209209

210210
List<TypeDefinitionAst> classes = parent.FindAll(item =>
211211
item is TypeDefinitionAst && (item as TypeDefinitionAst).IsClass, true)

Engine/VariableAnalysisBase.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ internal void InitializeVariables(Ast ast)
165165
_variables.Add("true", new VariableAnalysisDetails { Name = "true", RealName = "true", Type = typeof(bool) });
166166
_variables.Add("false", new VariableAnalysisDetails { Name = "false", RealName = "true", Type = typeof(bool) });
167167

168-
#if !PSV3
168+
#if !(PSV3||PSV4)
169169

170170
if (ast is FunctionMemberAst)
171171
{
@@ -808,7 +808,7 @@ internal static void InitializeSSA(Dictionary<string, VariableAnalysisDetails> V
808808
/// <param name="Entry"></param>
809809
/// <param name="Classes"></param>
810810
/// <returns></returns>
811-
#if PSV3
811+
#if (PSV3||PSV4)
812812

813813
internal static Tuple<Dictionary<string, VariableAnalysisDetails>, Dictionary<string, VariableAnalysisDetails>> SparseSimpleConstants(
814814
Dictionary<string, VariableAnalysisDetails> Variables, Block Entry)
@@ -989,7 +989,7 @@ internal static Tuple<Dictionary<string, VariableAnalysisDetails>, Dictionary<st
989989
{
990990
VariableAnalysisDetails analysis = VariablesDictionary[VariableAnalysis.AnalysisDictionaryKey(memAst.Expression as VariableExpressionAst)];
991991

992-
#if PSV3
992+
#if (PSV3||PSV4)
993993

994994
Type possibleType = AssignmentTarget.GetTypeFromMemberExpressionAst(memAst, analysis);
995995

@@ -1371,7 +1371,7 @@ public AssignmentTarget(string variableName, Type type)
13711371
/// <param name="psClass"></param>
13721372
/// <returns></returns>
13731373

1374-
#if PSV3
1374+
#if (PSV3||PSV4)
13751375

13761376
internal static Type GetTypeFromMemberExpressionAst(MemberExpressionAst memAst, VariableAnalysisDetails analysis)
13771377

@@ -1460,7 +1460,7 @@ internal static Type GetTypeFromMemberExpressionAst(MemberExpressionAst memberAs
14601460
// isStatic is true
14611461
result = GetTypeFromInvokeMemberAst(type, imeAst, methodName, true);
14621462
}
1463-
#if !PSV3
1463+
#if !(PSV3||PSV4)
14641464
else
14651465
{
14661466
// Check for classes
@@ -1498,7 +1498,7 @@ internal static Type GetTypeFromMemberExpressionAst(MemberExpressionAst memberAs
14981498
{
14991499
result = GetPropertyOrFieldTypeFromMemberExpressionAst(expressionType, fieldName);
15001500
}
1501-
#if !PSV3
1501+
#if !(PSV3||PSV4)
15021502
else
15031503
{
15041504
// check for class type
@@ -1531,7 +1531,7 @@ internal static Type GetTypeFromMemberExpressionAst(MemberExpressionAst memberAs
15311531
if (memberAst.Expression is VariableExpressionAst
15321532
&& String.Equals((memberAst.Expression as VariableExpressionAst).VariablePath.UserPath, "this", StringComparison.OrdinalIgnoreCase))
15331533
{
1534-
#if !PSV3
1534+
#if !(PSV3||PSV4)
15351535

15361536
// Check that we are in a class
15371537
TypeDefinitionAst psClass = FindClassAncestor(memberAst);
@@ -1598,7 +1598,7 @@ internal static Type GetPropertyOrFieldTypeFromMemberExpressionAst(Type type, st
15981598
return result;
15991599
}
16001600

1601-
#if !PSV3
1601+
#if !(PSV3||PSV4)
16021602
/// <summary>
16031603
/// Checks whether a class with the name name exists in the script that contains ast
16041604
/// </summary>

README.md

+32-11
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,33 @@ Note: the PSScriptAnalyzer Chocolatey package is provided and supported by the c
123123
* Building
124124
125125
You can either build using the `Visual Studio` solution `PSScriptAnalyzer.sln` or build using `PowerShell` specifically for your platform as follows:
126-
* Windows PowerShell version 5.0 and greater
126+
* The default build is for PowerShell Core
127127
```powershell
128-
.\buildCoreClr.ps1 -Framework net451 -Configuration Release -Build
128+
.\build.ps1
129+
```
130+
* Windows PowerShell version 5.0
131+
```powershell
132+
.\build.ps1 -Framework full -PSVersion 5 -Configuration Release
129133
```
130134
* Windows PowerShell version 4.0
131135
```powershell
132-
.\buildCoreClr.ps1 -Framework net451 -Configuration PSV4Release -Build
136+
.\build.ps1 -Framework full -PSVersion 4 -Configuration Release
133137
```
134138
* Windows PowerShell version 3.0
135139
```powershell
136-
.\buildCoreClr.ps1 -Framework net451 -Configuration PSV3Release -Build
140+
.\build.ps1 -Framework full -PSVersion 3 -Configuration Release
137141
```
138142
* PowerShell Core
139143
```powershell
140-
.\buildCoreClr.ps1 -Framework netstandard2.0 -Configuration Release -Build
144+
.\buildCoreClr.ps1 -Framework core -Configuration Release -Build
145+
```
146+
* Build documentation
147+
```powershell
148+
.\build.ps1 -Documentation
141149
```
142-
* Build documenatation
150+
* Build all versions (PowerShell v3, v4, v5, and Core) and documentation
143151
```powershell
144-
.\build.ps1 -BuildDocs
152+
.\build.ps1 -All
145153
```
146154
* Import the module
147155
```powershell
@@ -157,12 +165,25 @@ For adding/removing resource strings in the `*.resx` files, it is recommended to
157165
#### Tests
158166
Pester-based ScriptAnalyzer Tests are located in `path/to/PSScriptAnalyzer/Tests` folder.
159167

160-
* Ensure [Pester 4.3.1](https://www.powershellgallery.com/packages/Pester/4.3.1) is installed
161-
* Copy `path/to/PSScriptAnalyzer/out/PSScriptAnalyzer` to a folder in `PSModulePath`
168+
* Ensure [Pester 4.3.1](https://www.powershellgallery.com/packages/Pester/4.3.1) or higher is installed
169+
* Ensure that the documentation has been built (`./build.ps1 -Documentation`)
162170
* In the root folder of your local repository, run:
163171
``` PowerShell
164-
$testScripts = ".\Tests\Engine",".\Tests\Rules",".\Tests\Documentation"
165-
Invoke-Pester -Script $testScripts
172+
./build -Test
173+
```
174+
175+
To retrieve the results of the run, you can use the tools which are part of the build module (`build.psm1`)
176+
177+
```powershell
178+
Import-Module ./build.psm1
179+
Get-TestResults
180+
```
181+
182+
To retrieve only the errors, you can use the following:
183+
184+
```powershell
185+
Import-Module ./build.psm1
186+
Get-TestFailures
166187
```
167188

168189
[Back to ToC](#table-of-contents)

Rules/DscExamplesPresent.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeDSCResource(Ast ast, string fileName
6565
}
6666
}
6767

68-
#if !PSV3
68+
#if !(PSV3||PSV4)
6969

7070
/// <summary>
7171
/// AnalyzeDSCClass: Analyzes given DSC class

Rules/DscTestsPresent.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeDSCResource(Ast ast, string fileName
6565
}
6666
}
6767

68-
#if !PSV3
68+
#if !(PSV3||PSV4)
6969

7070
/// <summary>
7171
/// AnalyzeDSCClass: Analyzes given DSC class

Rules/ReturnCorrectTypesForDSCFunctions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeDSCResource(Ast ast, string fileName
3535

3636
IEnumerable<Ast> functionDefinitionAsts = Helper.Instance.DscResourceFunctions(ast);
3737

38-
#if !PSV3
38+
#if !(PSV3||PSV4)
3939

4040
IEnumerable<TypeDefinitionAst> classes = ast.FindAll(item =>
4141
item is TypeDefinitionAst
@@ -46,7 +46,7 @@ item is TypeDefinitionAst
4646
foreach (FunctionDefinitionAst func in functionDefinitionAsts)
4747
{
4848

49-
#if PSV3
49+
#if PSV3 || PSV4
5050

5151
List<Tuple<string, StatementAst>> outputTypes = FindPipelineOutput.OutputTypes(func);
5252

@@ -93,7 +93,7 @@ item is TypeDefinitionAst
9393
}
9494
}
9595

96-
#if !PSV3
96+
#if !(PSV3||PSV4)
9797

9898
/// <summary>
9999
/// AnalyzeDSCClass: Analyzes given DSC Resource

Rules/UseOutputTypeCorrectly.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
2222
#endif
2323
public class UseOutputTypeCorrectly : SkipTypeDefinition, IScriptRule
2424
{
25-
#if !PSV3
25+
#if !(PSV3||PSV4)
2626

2727
private IEnumerable<TypeDefinitionAst> _classes;
2828

@@ -41,7 +41,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
4141
DiagnosticRecords.Clear();
4242
this.fileName = fileName;
4343

44-
#if !PSV3
44+
#if !(PSV3||PSV4)
4545

4646
_classes = ast.FindAll(item => item is TypeDefinitionAst && ((item as TypeDefinitionAst).IsClass), true).Cast<TypeDefinitionAst>();
4747

Rules/UseStandardDSCFunctionsInResource.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeDSCClass(Ast ast, string fileName)
6464
{
6565
if (ast == null) throw new ArgumentNullException(Strings.NullAstErrorMessage);
6666

67-
#if PSV3
67+
#if (PSV3||PSV4)
6868

6969
return null;
7070

Tests/Engine/CustomizedRule.tests.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Describe "Test importing correct customized rules" {
9797
It "will show the custom rules when given a glob" {
9898
# needs fixing for Linux
9999
$expectedNumRules = 4
100-
if ($IsLinux -or $IsMacOS)
100+
if ($IsLinux)
101101
{
102102
$expectedNumRules = 3
103103
}
@@ -113,7 +113,7 @@ Describe "Test importing correct customized rules" {
113113
It "will show the custom rules when given glob with recurse switch" {
114114
# needs fixing for Linux
115115
$expectedNumRules = 5
116-
if ($IsLinux -or $IsMacOS)
116+
if ($IsLinux)
117117
{
118118
$expectedNumRules = 4
119119
}

0 commit comments

Comments
 (0)