From d1fb7f9772ec1a4fafb39c75a52ef064b6467398 Mon Sep 17 00:00:00 2001
From: Patrick Lehmann <Patrick.Lehmann@tu-dresden.de>
Date: Fri, 14 Oct 2016 14:17:13 +0200
Subject: Windows Build Flow: Fixed error of premature module unload.

---
 dist/mcode/winbuild.ps1                  |  3 ++-
 dist/mcode/windows/compile-ghdl.ps1      | 22 +++++++++++-----------
 dist/mcode/windows/compile-libraries.ps1 | 13 +------------
 dist/mcode/windows/shared.psm1           | 19 +++++++++----------
 4 files changed, 23 insertions(+), 34 deletions(-)

(limited to 'dist')

diff --git a/dist/mcode/winbuild.ps1 b/dist/mcode/winbuild.ps1
index 6f6a49375..83a3085c5 100644
--- a/dist/mcode/winbuild.ps1
+++ b/dist/mcode/winbuild.ps1
@@ -92,12 +92,13 @@ $GHDLRootDir =				Convert-Path (Resolve-Path ($PSScriptRoot + "\" + $RelPathToRo
 # set default values
 $EnableVerbose =			$PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent
 $EnableDebug =				$PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent
+$Hosting =						$true
 
 # Write-Host ("--> " + $Verbose + " value: " +$PSCmdlet.MyInvocation.BoundParameters["Verbose"] + " IsPresent: " + $PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent)
 # Write-Host ("--> " + $PSCommandPath + "  " + $PSBoundParameters + "  " + $PSCmdlet + "  " + $PSDefaultParameterValues)
 
 # load modules from GHDL's 'libraries' directory
-Import-Module $PSScriptRoot\windows\shared.psm1 -Verbose:$false -ArgumentList "$Script_WorkingDir"
+Import-Module $PSScriptRoot\windows\shared.psm1  -Verbose:$false -ArgumentList "$Script_WorkingDir", $Hosting
 Import-Module $PSScriptRoot\windows\targets.psm1 -Verbose:$false
 
 # Display help if no command was selected
diff --git a/dist/mcode/windows/compile-ghdl.ps1 b/dist/mcode/windows/compile-ghdl.ps1
index 5017b1fee..657023d03 100644
--- a/dist/mcode/windows/compile-ghdl.ps1
+++ b/dist/mcode/windows/compile-ghdl.ps1
@@ -46,29 +46,29 @@
 [CmdletBinding()]
 param(
 	# Display this help"
-	[switch]$Help =			$false,
+	[switch]$Help =							$false,
 	
 	# Slean up all files and directories
-	[switch]$Clean =					$false,
-		[switch]$Clean_GHDL =		$false,
+	[switch]$Clean =						$false,
+		[switch]$Clean_GHDL =			$false,
 	
 	# Compile all targets
-	[switch]$All =						$false,
+	[switch]$All =							$false,
 	
 	# Compile main targets
-	[switch]$Compile =				$false,
+	[switch]$Compile =					$false,
 		# Compile GHDL (simulator)
-		[switch]$Compile_GHDL =	$false,
+		[switch]$Compile_GHDL =		$false,
 	# Undocumented
-	[switch]$Test =						$false,
+	[switch]$Test =							$false,
 		# Undocumented
-		[switch]$Test_GHDL =		$false,
+		[switch]$Test_GHDL =			$false,
 	
 	# Build options
 	# Build a release version
-	[switch]$Release =	$false,
+	[switch]$Release =					$false,
 	# Set the back-end
-	[string]$Backend =	"mcode",
+	[string]$Backend =					"mcode",
 	
 	# Reduced messages
 	[switch]$Quiet =						$false,
@@ -97,7 +97,7 @@ $EnableDebug =		$PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent
 # Write-Host ("--> " + $PSCommandPath + "  " + $PSBoundParameters + "  " + $PSCmdlet + "  " + $PSDefaultParameterValues)
 
 # load modules from GHDL's 'libraries' directory
-Import-Module $PSScriptRoot\shared.psm1 -Verbose:$false -ArgumentList "$Script_WorkingDir"
+Import-Module $PSScriptRoot\shared.psm1  -Verbose:$false -ArgumentList "$Script_WorkingDir", $Hosted
 Import-Module $PSScriptRoot\targets.psm1 -Verbose:$false
 
 # Display help if no command was selected
diff --git a/dist/mcode/windows/compile-libraries.ps1 b/dist/mcode/windows/compile-libraries.ps1
index 01ab7712b..73e1cf766 100644
--- a/dist/mcode/windows/compile-libraries.ps1
+++ b/dist/mcode/windows/compile-libraries.ps1
@@ -91,22 +91,11 @@ $EnableVerbose =			$PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent
 $EnableDebug =				$PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent
 
 # load modules from GHDL's 'libraries' directory
-Import-Module $PSScriptRoot\shared.psm1 -Verbose:$false -ArgumentList "$Script_WorkingDir"
+Import-Module $PSScriptRoot\shared.psm1 -Verbose:$false -ArgumentList "$Script_WorkingDir", $Hosted
 
 # Display help if no command was selected
 $Help = $Help -or (-not ($Compile -or $VHDL87 -or $VHDL93 -or $VHDL2008 -or $Clean))
 
-function Exit-CompileScript
-{	[CmdletBinding()]
-	param(
-		[int]$ExitCode = 0
-	)
-	cd $Script_WorkingDir
-	# unload modules
-	Remove-Module shared -Verbose:$false
-	exit $ExitCode
-}
-
 if ($Help)
 {	Get-Help $MYINVOCATION.InvocationName -Detailed
 	Exit-CompileScript
diff --git a/dist/mcode/windows/shared.psm1 b/dist/mcode/windows/shared.psm1
index e39ce67ce..81a11be82 100644
--- a/dist/mcode/windows/shared.psm1
+++ b/dist/mcode/windows/shared.psm1
@@ -32,19 +32,19 @@
 
 [CmdletBinding()]
 param(
-	[Parameter(Mandatory=$true)][string]$WorkingDir
+	[Parameter(Mandatory=$true)][string]$WorkingDir,
+	[Parameter(Mandatory=$true)][Switch]$Hosted
 )
 
-$Module_WorkingDir =			$WorkingDir
+$Module_WorkingDir =	$WorkingDir
+$Module_Hosted =			$Hosted
 
 function Exit-CompileScript
-{		<#
+{	<#
 		.SYNOPSIS
 		Undocumented
-		
 		.DESCRIPTION
 		Undocumented
-		
 		.PARAMETER ExitCode
 		ExitCode of this script run
 	#>
@@ -52,13 +52,12 @@ function Exit-CompileScript
 	param(
 		[int]$ExitCode = 0
 	)
-	
 	cd $Module_WorkingDir
-	
 	# unload modules
-	Remove-Module shared -Verbose:$false
-	Remove-Module targets -Verbose:$false
-	
+	if (-not $Module_Hosted)
+	{	Remove-Module shared  -Verbose:$false
+		Remove-Module targets -Verbose:$false
+	}
 	exit $ExitCode
 }
 
-- 
cgit v1.2.3