forked from microsoft/CLRInstrumentationEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verifyCopyrightHeaders.ps1
121 lines (104 loc) · 3.1 KB
/
verifyCopyrightHeaders.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
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
$VerbosePreference = 'Continue'
$ErrorActionPreference = 'Stop'
$copyrightHeader = 'Copyright (c) Microsoft Corporation. All rights reserved.'
$mitLicenseHeader = 'Licensed under the MIT License.'
$xmlHeader = '<?xml'
$shellHeader = '#!/bin/bash'
$excludedDirs = @(
# generated
'.vs'
'.vscode'
'bin'
'Debug'
'obj'
'package'
'Release'
'out'
# external
'atl'
'empty'
'winsdk'
# test-related
'InstrEngineTests\\Baselines'
'InstrEngineTests\\TestScripts'
)
$excludedExtensions = @(
'.filters'
'.htm'
'.log'
'.md'
'.rgs'
'.sln'
'.snk'
'.txt'
'.user'
'.ignore'
)
$excludedFiles = @(
# external
'corprof.h'
'dbgmsg.h'
# used by preinstalled site extension on Azure App Service
'extension.xml'
# generated
'ExtensionsHost_i.c'
'ExtensionsHost_i.h'
'ExtensionsHost_p.c'
'HostExtension_i.c'
'HostExtension_i.h'
'InstrumentationEngine.h'
'InstrumentationEngine_api.cpp'
'RawProfilerHook_i.c'
'RawProfilerHook_i.h'
'dlldata.c'
'build.sem'
'EngineConfiguration.cs'
'InstrumentationConfigurationSources.cs'
# the license itself
'LICENSE'
)
Write-Verbose "OSS Headers require the following lines near the top of the file:"
Write-Verbose ""
Write-Verbose " $copyrightHeader"
Write-Verbose " $mitLicenseHeader"
Write-Verbose ""
Write-Verbose "Checking files under directory '$PSScriptRoot' ..."
Get-ChildItem -Path $PSScriptRoot -Recurse -File |
Where-Object { $_.PSParentPath -notmatch "\\$([String]::Join('|', $excludedDirs))" } |
Where-Object { -not $excludedFiles.Contains($_.Name) } |
Where-Object { -not $excludedExtensions.Contains($_.Extension) } |
ForEach-Object {
# Assume the Copyright headers are within 5 lines of the file.
$lines = Get-Content $_.FullName -First 5
if ($lines)
{
# Skip any whitespace at the beginning of the file.
$i = 0
while ([string]::IsNullOrWhiteSpace($lines[$i]) -and ($i -lt $lines.Length - 2)) { $i++ }
$copyrightIndex = $i
$mitLicenseIndex = $i + 1
if ($lines[$i].ToString().Contains($xmlHeader) -or
$lines[$i].ToString().Contains($shellHeader))
{
$copyrightIndex = $i + 1
$mitLicenseIndex = $i + 2
}
if (!$lines[$copyrightIndex].ToString().Contains($copyrightHeader))
{
Write-Warning "$($_.FullName) is missing OSS header: $copyrightHeader"
Write-Warning "> $($lines[$copyrightIndex])"
}
if (!$lines[$mitLicenseIndex].ToString().Contains($mitLicenseHeader))
{
Write-Warning "$($_.FullName) is missing OSS header: $mitLicenseHeader"
Write-Warning "> $($lines[$mitLicenseIndex])"
}
}
else
{
Write-Warning "$($_.FullName) is empty."
}
}
Write-Verbose "Done."