diff --git a/.gitignore b/.gitignore index ea82ac5cd..5ed5c1628 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,8 @@ dotnet-install.ps1 # VS auto-generated solution files for project.json solutions *.xproj *.xproj.user +*.suo + # Ignore executables *.exe diff --git a/build.psm1 b/build.psm1 index f830a5d71..a514fa6b8 100644 --- a/build.psm1 +++ b/build.psm1 @@ -670,7 +670,8 @@ function Copy-MappedFiles { [string[]]$Path = "$PSScriptRoot", [Parameter(Mandatory=$true)] [string]$PslMonadRoot, - [switch]$Force + [switch]$Force, + [switch]$WhatIf ) begin @@ -683,6 +684,10 @@ function Copy-MappedFiles { { Write-Warning "$Message : ignoring (-Force)" } + elseif ($WhatIf) + { + Write-Warning "$Message : ignoring (-WhatIf)" + } else { throw "$Message : use -Force to ignore" @@ -745,14 +750,7 @@ function Copy-MappedFiles { $map.GetEnumerator() | % { New-Item -ItemType Directory (Split-Path $_.Value) -ErrorAction SilentlyContinue > $null - if ($PSBoundParameters['Verbose']) - { - Copy-Item $_.Key $_.Value -Verbose - } - else - { - Copy-Item $_.Key $_.Value - } + Copy-Item $_.Key $_.Value -Verbose:([bool]$PSBoundParameters['Verbose']) -WhatIf:$WhatIf } } } @@ -886,21 +884,12 @@ function Start-ResGen "Microsoft.PowerShell.Security", "System.Management.Automation") | % { $module = $_ - Get-ChildItem "$PSScriptRoot/src/$module/resources" | % { + Get-ChildItem "$PSScriptRoot/src/$module/resources" -Filter '*.resx' | % { $className = $_.Name.Replace('.resx', '') $xml = [xml](Get-Content -raw $_.FullName) $fileName = $className - $namespace = '' - - $lastIndexOfDot = $className.LastIndexOf(".") - if ($lastIndexOfDot -ne -1) - { - $namespace = $className.Substring(0, $lastIndexOfDot) - $className = $className.Substring($lastIndexOfDot + 1) - } - - $genSource = Get-StronglyTypeCsFileForResx -xml $xml -ModuleName $module -ClassName $className -NamespaceName $namespace + $genSource = Get-StronglyTypeCsFileForResx -xml $xml -ModuleName $module -ClassName $className $outPath = "$PSScriptRoot/src/$module/gen/$fileName.cs" Write-Verbose "ResGen for $outPath" New-Item -Type Directory -ErrorAction SilentlyContinue (Split-Path $outPath) > $null @@ -998,7 +987,23 @@ function script:Start-NativeExecution([scriptblock]$sb) function script:Get-StronglyTypeCsFileForResx { - param($xml, $ModuleName, $ClassName, $NamespaceName = '') + param($xml, $ModuleName, $ClassName) + + # Example + # + # $ClassName = Full.Name.Of.The.ClassFoo + # $shortClassName = ClassFoo + # $namespaceName = Full.Name.Of.The + + $shortClassName = $ClassName + $namespaceName = $null + + $lastIndexOfDot = $className.LastIndexOf(".") + if ($lastIndexOfDot -ne -1) + { + $namespaceName = $className.Substring(0, $lastIndexOfDot) + $shortClassName = $className.Substring($lastIndexOfDot + 1) + } $banner = @' //------------------------------------------------------------------------------ @@ -1048,7 +1053,7 @@ internal class {0} {{ internal static global::System.Resources.ResourceManager ResourceManager {{ get {{ if (object.ReferenceEquals(resourceMan, null)) {{ - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("{1}.resources.{0}", typeof({0}).GetTypeInfo().Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("{1}.resources.{3}", typeof({0}).GetTypeInfo().Assembly); resourceMan = temp; }} return resourceMan; @@ -1091,9 +1096,9 @@ internal class {0} {{ } } | Out-String - $bodyCode = $body -f $ClassName,$ModuleName,$entries + $bodyCode = $body -f $shortClassName,$ModuleName,$entries,$ClassName - if ($NamespaceName -ne '') + if ($NamespaceName) { $bodyCode = $namespace -f $NamespaceName, $bodyCode } diff --git a/docs/building/internals.md b/docs/building/internals.md new file mode 100644 index 000000000..ca22828a8 --- /dev/null +++ b/docs/building/internals.md @@ -0,0 +1,45 @@ +Internals of build process +========================================= + +The purpose of this document is to explain build process **internals** with subtle nuances. +This document is not by any means complete. +The ultimate source of truth is the code in `.\build.psm1` that's getting executed on the corresponding CI system. + +This document assumes, that you can successfully build PowerShell from sources for your platform. + + +Top directory +----------- + +We are calling `dotnet` tool build for `$Top` directory + +- `src\powershell` for CoreCLR builds (all platforms) +- `src\Microsoft.PowerShell.ConsoleHost` for FullCLR builds (Windows only) + + +### Dummy dependencies + +We use dummy dependencies between project.json files to leverage `dotnet` build functionality. +For example, `src\Microsoft.PowerShell.ConsoleHost\project.json` has dependency on `Microsoft.PowerShell.PSReadLine`, +but in reality, there is no build dependency. + +Dummy dependencies allows us to build just `$Top` folder, instead of building several folders. + +### Dummy dependencies rules + +* If assembly is part of FullCLR build, +it should be listed as a dependency for FullCLR $Top folder (src\Microsoft.PowerShell.ConsoleHost) + +* If assembly is part of CoreCLR build, +it should be listed as a dependency for CoreCLR $Top folder (src\powershell) + + +Modules +---------- + +There are 3 modules directories with the same purpose: they have **content** files (i.e. `*.psm1`, `*.psd1`) +which would be binplaced by `dotnet` + +- `src\Modules` shared between all flavours +- `src\Microsoft.PowerShell.ConsoleHost\Modules` FullCLR (Windows) +- `src\powershell\Modules` CoreCLR (all platforms) diff --git a/src/Microsoft.PowerShell.ConsoleHost/project.json b/src/Microsoft.PowerShell.ConsoleHost/project.json index e2b59dc7d..a64e63859 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/project.json +++ b/src/Microsoft.PowerShell.ConsoleHost/project.json @@ -28,7 +28,7 @@ "dependencies": { "Microsoft.PowerShell.PSReadLine": "1.0.0-*", - "Microsoft.PowerShell.Commands.Diagnostics": "1.0.0-*", + "Microsoft.PowerShell.Commands.Diagnostics": "1.0.0-*", "Microsoft.PowerShell.Commands.Management": "1.0.0-*", "Microsoft.PowerShell.Commands.Utility": "1.0.0-*", "Microsoft.PowerShell.LocalAccounts": "1.0.0-*" diff --git a/src/powershell/Modules/Microsoft.PowerShell.LocalAccounts/LocalAccounts.format.ps1xml b/src/Modules/Microsoft.PowerShell.LocalAccounts/LocalAccounts.format.ps1xml similarity index 100% rename from src/powershell/Modules/Microsoft.PowerShell.LocalAccounts/LocalAccounts.format.ps1xml rename to src/Modules/Microsoft.PowerShell.LocalAccounts/LocalAccounts.format.ps1xml diff --git a/src/powershell/Modules/Microsoft.PowerShell.LocalAccounts/Microsoft.PowerShell.LocalAccounts.psd1 b/src/Modules/Microsoft.PowerShell.LocalAccounts/Microsoft.PowerShell.LocalAccounts.psd1 similarity index 100% rename from src/powershell/Modules/Microsoft.PowerShell.LocalAccounts/Microsoft.PowerShell.LocalAccounts.psd1 rename to src/Modules/Microsoft.PowerShell.LocalAccounts/Microsoft.PowerShell.LocalAccounts.psd1 diff --git a/src/Modules/map.json b/src/Modules/map.json index f6a5fae62..20161971a 100644 --- a/src/Modules/map.json +++ b/src/Modules/map.json @@ -15,5 +15,7 @@ "monad/miscfiles/modules/Microsoft.PowerShell.Host/Microsoft.PowerShell.Host.psd1": "Microsoft.PowerShell.Host/Microsoft.PowerShell.Host.psd1", "monad/miscfiles/modules/AppxProvider/AppxProvider.Resource.psd1": "AppxProvider/AppxProvider.Resource.psd1", "monad/miscfiles/modules/AppxProvider/AppxProvider.psd1": "AppxProvider/AppxProvider.psd1", - "monad/miscfiles/modules/PSGet/PSGet.Resource.psd1": "PSGet/PSGet.Resource.psd1" + "monad/miscfiles/modules/PSGet/PSGet.Resource.psd1": "PSGet/PSGet.Resource.psd1", + "monad/src/LocalAccounts/Microsoft.PowerShell.LocalAccounts.psd1": "Microsoft.PowerShell.LocalAccounts/Microsoft.PowerShell.LocalAccounts.psd1", + "monad/src/LocalAccounts/LocalAccounts.format.ps1xml": "Microsoft.PowerShell.LocalAccounts/LocalAccounts.format.ps1xml" } diff --git a/src/powershell-native/.gitignore b/src/powershell-native/.gitignore index 62f5f82d5..4f159ef0a 100644 --- a/src/powershell-native/.gitignore +++ b/src/powershell-native/.gitignore @@ -4,6 +4,7 @@ CMakeCache.txt CMakeFiles/ PowerShell.sln Win32/ +x64/ ZERO_CHECK.vcxproj ZERO_CHECK.vcxproj.filters cmake_install.cmake diff --git a/src/powershell/map.json b/src/powershell/map.json index 244c3606d..bde38359e 100644 --- a/src/powershell/map.json +++ b/src/powershell/map.json @@ -1,6 +1,4 @@ { "monad/miscfiles/modules/Microsoft.PowerShell.Diagnostics/CoreClr/Microsoft.PowerShell.Diagnostics.psd1": "Modules/Microsoft.PowerShell.Diagnostics/Microsoft.PowerShell.Diagnostics.psd1", - "monad/miscfiles/modules/Microsoft.PowerShell.Utility/CoreClr/Microsoft.PowerShell.Utility.psd1": "Modules/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1", - "monad/src/LocalAccounts/Microsoft.PowerShell.LocalAccounts.psd1": "Modules/Microsoft.PowerShell.LocalAccounts/Microsoft.PowerShell.LocalAccounts.psd1", - "monad/src/LocalAccounts/LocalAccounts.format.ps1xml": "Modules/Microsoft.PowerShell.LocalAccounts/LocalAccounts.format.ps1xml" + "monad/miscfiles/modules/Microsoft.PowerShell.Utility/CoreClr/Microsoft.PowerShell.Utility.psd1": "Modules/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1" }