-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathECLSyntaxCheck.ps1
149 lines (132 loc) · 4.76 KB
/
ECLSyntaxCheck.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Script author : Oscar Foley
# Script Description : This script makes a syntax check of all ecl code
# Notes
$Version = "1.2"
function Write-LogMessage($message, $logfile, $isError = $false)
{
if ($isError)
{
$textColour = 'red'
}
else
{
$textColour = 'white'
}
Write-Host $message -ForegroundColor $textColour
Add-Content $logfile $message
}
function DetectPowershellVersion($minVersion=3, $logFile)
{
# Check Powershell version
$PSVersion = $PSVersionTable.PSVersion
Write-LogMessage "Detected PowerShell version: $PSVersion" $logFile
if ( ([int]$PSVersion.Major) -lt $minVersion)
{
throw "ERROR. Script needs Powershell $minVersion or higher."
}
}
function DetectECLCCVersion($logFile)
{
$cmdName = "$eclClientTools\eclcc.exe"
if (Get-Command $cmdName -errorAction SilentlyContinue)
{
Write-LogMessage "$cmdName exists" $logFile
}
else
{
throw "Cannot find eclcc $cmdName. Please install correct version from https://hpccsystems.com/download/developer-tools/client-tools"
}
if (!(Get-Command "eclcc" -errorAction SilentlyContinue))
{
$env:Path += ";$eclClientTools"
}
}
function PrintCompilingErrors($fileName, $stringList, $ignoreWarnings = $false, $logfile)
{
foreach ($element in $stringlist)
{
if ($element.StartsWith($fileName))
{
if ($ignoreWarnings)
{
if (!$element.Contains(': warning C'))
{
Write-LogMessage " $element" $logfile $true
}
}
else
{
Write-LogMessage " $element" $logfile $true
}
}
}
}
function SyntaxCheckAllFilesInDirectory($BASEDirectory, $BASEImportsDirectory, $ignoreWarnings, $logfile)
{
$list = Get-ChildItem -Path $BASEDirectory -Recurse -Filter "*.ecl"
foreach ($item in $list)
{
$fullName = "$($item.DirectoryName)\$($item.Name)"
$directory = $($item.DirectoryName)
$cmdOuput = cmd /c eclcc -legacy -syntax -I="$BASEImportsDirectory" $fullName '2>&1'
PrintCompilingErrors $fullName $cmdOuput $ignoreWarnings $logfile
}
}
# Imports
$scriptsDirectory = Split-Path $MyInvocation.MyCommand.Definition -parent
. $(Join-Path $scriptsDirectory "ECLSyntaxCheck.config.ps1") # Load app.config
cd $scriptsDirectory
# MAIN
try
{
$startTime = Get-Date
cls
Write-LogMessage "ECLSyntaxChecker version $Version started ($startTime)" $logfile
Remove-Item -Force "$scriptsDirectory\$logFile" -ErrorAction SilentlyContinue
Write-LogMessage "Initializing log file: $scriptsDirectory\$logFile" $logFile
DetectPowershellVersion 3 $logfile
Write-LogMessage "Configuration (from ECLSyntaxCheck.config.ps1)" $logfile
Write-LogMessage "- Relative Path to code directory : $relativePathToCODEDirectory" $logfile
Write-LogMessage "- Relative Path to imports directory : $relativePathToImportsDirectory" $logfile
Write-LogMessage "- Log file name : $logfile" $logfile
Write-LogMessage "- Ignore Warnings : $ignoreWarnings" $logfile
Write-LogMessage "- Exclude Directories : $excludedDirectories" $logfile
Write-LogMessage "- HPCC Client Tools path : $eclClientTools" $logfile
Write-LogMessage "Starting ECL SyntaxCheck..." $logfile
DetectECLCCVersion $logfile
$CODEDirectory = (Get-Item -Path $relativePathToCODEDirectory -Verbose).FullName + '\'
$ImportsDirectory = (Get-Item -Path $relativePathToImportsDirectory -Verbose).FullName
Write-LogMessage "Absolute Path to code directory : $CODEDirectory" $logfile
Write-LogMessage "Absolute Path to imports directory : $ImportsDirectory" $logfile
Write-LogMessage "Starting ECL Syntax check in all *.ecl files in $CODEDirectory" $logfile
Write-LogMessage "Checking directories from $CODEDirectory" $logfile
$list = Get-ChildItem -Path $CODEDirectory -Directory
foreach ($dir in $list)
{
if ($excludedDirectories.Contains($dir.Name))
{
Write-LogMessage " -- excluded - $($dir.FullName)" $logfile
}
else
{
Write-LogMessage " $($dir.FullName)" $logfile
SyntaxCheckAllFilesInDirectory $dir.FullName $ImportsDirectory $ignoreWarnings $logfile
}
}
#END
$endTime = Get-Date
Write-LogMessage "Finished ECL SyntaxCheck ($endTime)" $logfile
$elapsedTime = new-timespan $startTime $endTime
Write-LogMessage "Script time = $elapsedTime" $logfile
$exitCode = 0
}
Catch
{
$errorMessage = $_.Exception
Write-LogMessage $errorMessage $logfile
$exitCode = 1
}
finally
{
exit $exitCode
}