Skip to content

Commit 22f002a

Browse files
committed
Add script to build that validates modules have necessary dlls in RequiredAssemblies
1 parent f03bf83 commit 22f002a

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

build.proj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@
245245

246246
<Message Importance="high" Text="Running Static Analyser" />
247247
<CallTarget targets="DependencyAnalysis" ContinueOnError="ErrorAndContinue" />
248+
<Exec Command="&quot;$(PowerShellCommand)&quot; -NonInteractive -NoLogo -NoProfile -Command &quot;. $(LibraryToolsFolder)\CheckAssemblies.ps1 &quot;" />
248249
<Exec Command="&quot;$(PowerShellCommand)&quot; -NonInteractive -NoLogo -NoProfile -Command &quot;. $(LibraryToolsFolder)\CleanupBuild.ps1 -BuildConfig $(Configuration) &quot;" />
249250
</Target>
250251

tools/CheckAssemblies.ps1

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# ----------------------------------------------------------------------------------
2+
# Copyright Microsoft Corporation
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
# ----------------------------------------------------------------------------------
13+
14+
$ProjectPaths = @( "$PSScriptRoot\..\src\ResourceManager" )
15+
$DependencyMapPath = "$PSScriptRoot\..\src\Package\DependencyMap.csv"
16+
17+
$DependencyMap = Import-Csv -Path $DependencyMapPath
18+
19+
$ModuleManifestFiles = $ProjectPaths | % { Get-ChildItem -Path $_ -Filter "*.psd1" -Recurse | where { $_.FullName -notlike "*Debug*" -and `
20+
$_.FullName -notlike "*Netcore*" -and `
21+
$_.FullName -notlike "*dll-Help.psd1*" -and `
22+
$_.FullName -notlike "*Stack*" } }
23+
24+
foreach ($ModuleManifest in $ModuleManifestFiles)
25+
{
26+
$ModuleName = $ModuleManifest.Name.Replace(".psd1", "")
27+
$Assemblies = $DependencyMap | where { $_.Directory.EndsWith($ModuleName) }
28+
Import-LocalizedData -BindingVariable ModuleMetadata -BaseDirectory $ModuleManifest.DirectoryName -FileName $ModuleManifest.Name
29+
30+
$LoadedAssemblies = @()
31+
if ($ModuleMetadata.RequiredAssemblies.Count -gt 0)
32+
{
33+
$LoadedAssemblies += $ModuleMetadata.RequiredAssemblies
34+
}
35+
36+
$LoadedAssemblies += $ModuleMetadata.NestedModules
37+
38+
if ($ModuleMetadata.RequiredModules)
39+
{
40+
$RequiredModules = $ModuleMetadata.RequiredModules | % { $_["ModuleName"] }
41+
foreach ($RequiredModule in $RequiredModules)
42+
{
43+
$RequiredModuleManifest = $ModuleManifestFiles | where { $_.Name.Replace(".psd1", "") -eq $RequiredModule }
44+
if (-not $RequiredModuleManifest)
45+
{
46+
continue
47+
}
48+
Import-LocalizedData -BindingVariable ModuleMetadata -BaseDirectory $RequiredModuleManifest.DirectoryName -FileName $RequiredModuleManifest.Name
49+
50+
if ($ModuleMetadata.RequiredAssemblies.Count -gt 0)
51+
{
52+
$LoadedAssemblies += $ModuleMetadata.RequiredAssemblies
53+
}
54+
55+
$LoadedAssemblies += $ModuleMetadata.NestedModules
56+
}
57+
}
58+
59+
$LoadedAssemblies = $LoadedAssemblies | % { $_.Substring(2) }
60+
$LoadedAssemblies = $LoadedAssemblies | % { $_.Replace(".dll", "") }
61+
62+
$Found = @()
63+
foreach ($Assembly in $Assemblies)
64+
{
65+
if ($Found -notcontains $Assembly.AssemblyName -and $LoadedAssemblies -notcontains $Assembly.AssemblyName)
66+
{
67+
$Found += $Assembly.AssemblyName
68+
Write-Error "ERROR: Assembly $($Assembly.AssemblyName) was not included in the required assemblies field for module $ModuleName"
69+
}
70+
}
71+
72+
if ($Found.Count -gt 0)
73+
{
74+
throw
75+
}
76+
}

0 commit comments

Comments
 (0)