Skip to content

Commit 0a8a42f

Browse files
committed
Fix the normalization / guessing of SourcePath
1 parent 2aa4c4f commit 0a8a42f

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

Source/Private/GetBuildInfo.ps1

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function GetBuildInfo {
1717
Write-Debug "Load Build Manifest $BuildManifest"
1818
Import-Metadata -Path $BuildManifest
1919
} else {
20+
Write-Debug "Use SourcePath $BuildManifest"
2021
@{ SourcePath = $BuildManifest }
2122
}
2223
} else {
@@ -48,11 +49,9 @@ function GetBuildInfo {
4849
$null = $BuildInfo.Remove($k)
4950
}
5051
}
51-
# !$BuildInfo.ContainsKey($key) -or $BoundParameters.ContainsKey($key)
52-
53-
# The SourcePath is special: we overwrite the parameter value with the Build.psd1 value
54-
# Otherwise, we overwrite build.psd1 values with bound parameters values
55-
if (($key -ne "SourcePath" -or -not $BuildInfo.SourcePath) -and (-not $BuildInfo.ContainsKey($key) -or $BoundParameters.ContainsKey($key))) {
52+
# Bound parameter values > build.psd1 values > default parameters values
53+
if (-not $BuildInfo.ContainsKey($key) -or $BoundParameters.ContainsKey($key)) {
54+
# Reading the current value of the $key variable returns either the bound parameter or the default
5655
if ($null -ne ($value = Get-Variable -Name $key -ValueOnly -ErrorAction Ignore )) {
5756
if ($value -ne ($null -as $parameter.Value.ParameterType)) {
5857
$ParameterValues[$key] = $value
@@ -68,17 +67,25 @@ function GetBuildInfo {
6867
}
6968
}
7069
}
70+
# BuildInfo.SourcePath should point to a module manifest
71+
if ($BuildInfo.SourcePath -and $BuildInfo.SourcePath -ne $BuildManifest) {
72+
$ParameterValues["SourcePath"] = $BuildInfo.SourcePath
73+
}
74+
# If SourcePath point to build.psd1, we should clear it
75+
if ($ParameterValues["SourcePath"] -eq $BuildManifest) {
76+
$ParameterValues.Remove("SourcePath")
77+
}
7178
Write-Debug "Finished parsing Build Manifest $BuildManifest"
7279

7380
$BuildInfo = $BuildInfo | Update-Object $ParameterValues
81+
Write-Debug "Using Module Manifest $($BuildInfo.SourcePath)"
7482

7583
$BuildManifestParent = if ($BuildManifest) {
7684
Split-Path -Parent $BuildManifest
7785
} else {
7886
Get-Location -PSProvider FileSystem
7987
}
8088

81-
# Resolve Module manifest if not defined in Build.psd1 or there's no Build.psd1
8289
if (-Not $BuildInfo.SourcePath) {
8390
# Find a module manifest (or maybe several)
8491
$ModuleInfo = Get-ChildItem $BuildManifestParent -Recurse -Filter *.psd1 -ErrorAction SilentlyContinue |
@@ -94,21 +101,20 @@ function GetBuildInfo {
94101
$ModuleInfo = @($ModuleInfo).Where{ $_.Name -eq $ModuleName }
95102
}
96103
if (@($ModuleInfo).Count -eq 1) {
97-
Write-Debug "Updating BuildInfo SourcePath to $SourcePath"
104+
Write-Debug "Updating BuildInfo SourcePath to $($ModuleInfo.Path)"
98105
$BuildInfo = $BuildInfo | Update-Object @{ SourcePath = $ModuleInfo.Path }
99106
}
100107
if (-Not $BuildInfo.SourcePath) {
101108
throw "Can't find a module manifest in $BuildManifestParent"
102109
}
103110
}
104111

105-
# Make sure the Path is set and points at the actual manifest, relative to Build.psd1 or absolute
112+
# Make sure the SourcePath is absolute and points at an actual file
106113
if (!(Split-Path -IsAbsolute $BuildInfo.SourcePath) -and $BuildManifestParent) {
107114
$BuildInfo.SourcePath = Join-Path $BuildManifestParent $BuildInfo.SourcePath | Convert-Path
108115
} else {
109116
$BuildInfo.SourcePath = Convert-Path $BuildInfo.SourcePath
110117
}
111-
112118
if (!(Test-Path $BuildInfo.SourcePath)) {
113119
throw "Can't find module manifest at the specified SourcePath: $($BuildInfo.SourcePath)"
114120
}

0 commit comments

Comments
 (0)