@@ -17,6 +17,7 @@ function GetBuildInfo {
17
17
Write-Debug " Load Build Manifest $BuildManifest "
18
18
Import-Metadata - Path $BuildManifest
19
19
} else {
20
+ Write-Debug " Use SourcePath $BuildManifest "
20
21
@ { SourcePath = $BuildManifest }
21
22
}
22
23
} else {
@@ -48,11 +49,9 @@ function GetBuildInfo {
48
49
$null = $BuildInfo.Remove ($k )
49
50
}
50
51
}
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
56
55
if ($null -ne ($value = Get-Variable - Name $key - ValueOnly - ErrorAction Ignore )) {
57
56
if ($value -ne ($null -as $parameter.Value.ParameterType )) {
58
57
$ParameterValues [$key ] = $value
@@ -68,17 +67,25 @@ function GetBuildInfo {
68
67
}
69
68
}
70
69
}
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
+ }
71
78
Write-Debug " Finished parsing Build Manifest $BuildManifest "
72
79
73
80
$BuildInfo = $BuildInfo | Update-Object $ParameterValues
81
+ Write-Debug " Using Module Manifest $ ( $BuildInfo.SourcePath ) "
74
82
75
83
$BuildManifestParent = if ($BuildManifest ) {
76
84
Split-Path - Parent $BuildManifest
77
85
} else {
78
86
Get-Location - PSProvider FileSystem
79
87
}
80
88
81
- # Resolve Module manifest if not defined in Build.psd1 or there's no Build.psd1
82
89
if (-Not $BuildInfo.SourcePath ) {
83
90
# Find a module manifest (or maybe several)
84
91
$ModuleInfo = Get-ChildItem $BuildManifestParent - Recurse - Filter * .psd1 - ErrorAction SilentlyContinue |
@@ -94,21 +101,20 @@ function GetBuildInfo {
94
101
$ModuleInfo = @ ($ModuleInfo ).Where { $_.Name -eq $ModuleName }
95
102
}
96
103
if (@ ($ModuleInfo ).Count -eq 1 ) {
97
- Write-Debug " Updating BuildInfo SourcePath to $SourcePath "
104
+ Write-Debug " Updating BuildInfo SourcePath to $ ( $ModuleInfo .Path ) "
98
105
$BuildInfo = $BuildInfo | Update-Object @ { SourcePath = $ModuleInfo.Path }
99
106
}
100
107
if (-Not $BuildInfo.SourcePath ) {
101
108
throw " Can't find a module manifest in $BuildManifestParent "
102
109
}
103
110
}
104
111
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
106
113
if (! (Split-Path - IsAbsolute $BuildInfo.SourcePath ) -and $BuildManifestParent ) {
107
114
$BuildInfo.SourcePath = Join-Path $BuildManifestParent $BuildInfo.SourcePath | Convert-Path
108
115
} else {
109
116
$BuildInfo.SourcePath = Convert-Path $BuildInfo.SourcePath
110
117
}
111
-
112
118
if (! (Test-Path $BuildInfo.SourcePath )) {
113
119
throw " Can't find module manifest at the specified SourcePath: $ ( $BuildInfo.SourcePath ) "
114
120
}
0 commit comments