Skip to content

Commit 8da5087

Browse files
author
Philip Sampaio
committed
Adaptations to fix the build
1 parent e8f5eef commit 8da5087

File tree

4 files changed

+60
-23
lines changed

4 files changed

+60
-23
lines changed

bin/elixir.ps1

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env pwsh
22

3-
$MinPowerShellVersion = [semver]::new(7, 2, 0)
3+
$MinPowerShellVersion = [version]"7.2.0"
44

5-
if ($MinPowerShellVersion.CompareTo($PSVersionTable.PSVersion) -eq 1) {
5+
if ($MinPowerShellVersion.CompareTo([version]$PSVersionTable.PSVersion) -eq 1) {
66
Write-Error "This script requires PowerShell version 7.2 or above. Running on $($PSVersionTable.PSVersion)"
77
}
88

@@ -79,7 +79,30 @@ if (($Args.Count -eq 1) -and ($Args[0] -eq "--short-version")) {
7979

8080
if (($Args.Count -eq 0) -or (($Args.Count -eq 1) -and ($Args[0] -in @("-h", "--help")))) {
8181
PrintElixirHelp
82-
exit
82+
exit 1
83+
}
84+
85+
function NormalizeArg {
86+
param(
87+
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
88+
[string[]] $Items
89+
)
90+
[string]::Join(",", $Items)
91+
}
92+
93+
function QuotedString {
94+
param(
95+
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
96+
[string] $Item
97+
)
98+
99+
# We surround the string with double quotes, in order to preserve its contents.
100+
if (-not $Item.StartsWith("`"") -and $Item.Contains(" ")) {
101+
"`"$Item`""
102+
}
103+
else {
104+
$Item
105+
}
83106
}
84107

85108
$ElixirParams = New-Object Collections.Generic.List[String]
@@ -92,11 +115,25 @@ for ($i = 0; $i -lt $Args.Count; $i++) {
92115

93116
switch ($Arg) {
94117
{ $_ -in @("-e", "-r", "-pr", "-pa", "-pz", "--eval", "--remsh", "--dot-iex", "--dbg") } {
95-
$ElixirParams.Add("$Arg $($Args[++$i])")
118+
$private:NextArg = $Args[++$i] | NormalizeArg | QuotedString
119+
120+
$ElixirParams.Add("$Arg $NextArg")
121+
122+
break
123+
}
124+
125+
{ $_ -in @("-v", "--version", "--help", "-h") } {
126+
# Standalone options goes only once in the Elixir params, when they are empty.
127+
if ($ElixirParams.Count -eq 0) {
128+
$ElixirParams.Add($Arg)
129+
}
130+
else {
131+
$AllOtherParams.Add($Arg)
132+
}
96133
break
97134
}
98135

99-
{ $_ -in @("-v", "--version", "--no-halt") } {
136+
"--no-halt" {
100137
$ElixirParams.Add($Arg)
101138
break
102139
}
@@ -189,7 +226,7 @@ for ($i = 0; $i -lt $Args.Count; $i++) {
189226
exit
190227
}
191228

192-
$ElixirParams.Add("--rpc-eval $Key $Value")
229+
$ElixirParams.Add("--rpc-eval $Key $(QuotedString $Value)")
193230
break
194231
}
195232

@@ -207,7 +244,7 @@ for ($i = 0; $i -lt $Args.Count; $i++) {
207244
exit
208245
}
209246

210-
$ErlangParams.Add("-boot_var $Key $Value")
247+
$ErlangParams.Add("-boot_var $Key $(QuotedString $Value)")
211248
break
212249
}
213250

@@ -220,11 +257,13 @@ for ($i = 0; $i -lt $Args.Count; $i++) {
220257
}
221258

222259
Default {
223-
if ($Arg -is [string]) {
224-
$AllOtherParams.Add($Arg)
260+
$private:Normalized = NormalizeArg $Arg
261+
if ($Normalized.StartsWith("-")) {
262+
$AllOtherParams.Add($Normalized)
225263
}
226264
else {
227-
$AllOtherParams.Add([string]::Join(",", $Arg))
265+
# We add quotes to preserve contents, since the quotes are removed by Powershell.
266+
$AllOtherParams.Add("$(QuotedString $Normalized)")
228267
}
229268
break
230269
}
@@ -234,7 +273,10 @@ for ($i = 0; $i -lt $Args.Count; $i++) {
234273
# Support for ANSI is only disable if TERM or NO_COLOR env vars are set.
235274
# This will change the $PSStyle.OutputRendering property.
236275
if ($PSStyle.OutputRendering -ne "PlainText") {
237-
$BeforeExtras.Insert(0, "-elixir ansi_enabled true")
276+
# TODO: find a way to detect if the term is interactive on Windows.
277+
if ($IsWindows -or (test -t 1 -a -t 2)) {
278+
$BeforeExtras.Insert(0, "-elixir ansi_enabled true")
279+
}
238280
}
239281

240282
if ($null -eq $UseIEx) {
@@ -261,7 +303,7 @@ $AllParams.Add("-extra")
261303
$AllParams.AddRange($ElixirParams)
262304
$AllParams.AddRange($AllOtherParams)
263305

264-
$ParamsPart = [string]::Join(" ", ($AllParams | Where-Object { $_ -ne "" }))
306+
$ParamsPart = [string]::Join(" ", $AllParams)
265307

266308
$BinSuffix = ""
267309

@@ -275,15 +317,10 @@ if ($ERTS_BIN) {
275317
$BinPath = Join-Path -Path $ERTS_BIN -ChildPath $BinPath
276318
}
277319

278-
$Command = "$BinPath $ParamsPart"
279-
280-
if ($ErlExec -eq "werl") {
281-
$Command = "start `"`" $Command"
282-
}
283-
284320
if ($Env:ELIXIR_CLI_DRY_RUN) {
285-
Write-Host $Command
321+
Write-Host "$BinPath $ParamsPart"
286322
}
287323
else {
288-
Invoke-Expression $Command
324+
$Output = Start-Process -FilePath $BinPath -ArgumentList $ParamsPart -NoNewWindow -Wait -PassThru
325+
exit $Output.ExitCode
289326
}

bin/elixirc.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ for ($i = 0; $i -lt $Args.Count; $i++) {
4141
}
4242
}
4343

44-
Invoke-Expression "$Command $([string]::Join(" ", $NewArgs))"
44+
& $Command $NewArgs

bin/iex.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ for ($i = 0; $i -lt $Args.Count; $i++) {
3535
}
3636
}
3737

38-
Invoke-Expression "$Command $([string]::Join(" ", $NewArgs))"
38+
& $Command $NewArgs

bin/mix.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ for ($i = 0; $i -lt $Args.Count; $i++) {
1717
}
1818
}
1919

20-
Invoke-Expression "$Command $([string]::Join(" ", $NewArgs))"
20+
& $Command $NewArgs

0 commit comments

Comments
 (0)