forked from roc-streaming/roc-droid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
305 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
@rem -*- coding: utf-8; mode: powershell -*- | ||
@powershell -ExecutionPolicy Unrestricted -Command ^ | ||
"$Self = '%~f0'; $Target = '%~1'; iex ((gc $Self | out-string) -replace '(?s).*:start\r?\n', '')" | ||
@exit /b | ||
:start | ||
|
||
# On fresh Windows installation, there may be problems with running .ps1 file as is: | ||
# .\script\docker_build.ps1 <target> | ||
# | ||
# We may instead need: | ||
# powershell -ExecutionPolicy Unrestricted -File .\script\docker_build.ps1 <target> | ||
# | ||
# It would work, but is cumbersome. | ||
# | ||
# For convenience, we name file as .bat file (so that it can be invoked as is), but in the | ||
# preamble above we evaluate contents of the file after :start marker as a powershell script | ||
# (so that we don't have to deal with batch programming madness). | ||
|
||
$ErrorActionPreference = "Stop" | ||
|
||
function Project-Version { | ||
$content = Get-Content -Path "pubspec.yaml" -Raw | ||
$match = [regex]::Match($content, "^version:\s*(\S+)\s*$", "Multiline") | ||
return $match.Groups[1].Value | ||
} | ||
|
||
function Print-Msg ($msg) { | ||
Write-Host "$msg" -ForegroundColor Blue | ||
} | ||
|
||
function Print-Err ($msg) { | ||
Write-Host "$msg" -ForegroundColor Red | ||
} | ||
|
||
function Run-Cmd ($cmd) { | ||
Write-Host ($cmd -join " ") | ||
|
||
$proc = Start-Process -FilePath $cmd[0] -ArgumentList $cmd[1..$cmd.Length] ` | ||
-PassThru -Wait -NoNewWindow | ||
|
||
if ($proc.ExitCode -ne 0) { | ||
Print-Err "Command failed with code $($proc.ExitCode)" | ||
exit 1 | ||
} | ||
} | ||
|
||
if ($Target -eq "") { | ||
$Target = "android" | ||
} | ||
if (-not (@("android") -contains $Target)) { | ||
Print-Err "usage: .\script\docker_build.bat [android]" | ||
exit 1 | ||
} | ||
|
||
Set-Location -Path ( | ||
Split-Path -Parent (Split-Path -Parent (Resolve-Path $Self))) | ||
|
||
$cwd = Get-Location | ||
|
||
if ($Target -eq "android") { | ||
$workDir = "/root/build" # container | ||
$cacheDirs = @{ | ||
# host: container | ||
"${cwd}\build\dockercache\pub" = "/root/.pub-cache" | ||
"${cwd}\build\dockercache\gradle" = "/root/.gradle" | ||
"${cwd}\build\dockercache\android" = "/root/.android/cache" | ||
} | ||
} | ||
|
||
$dockerCmd = @( | ||
"docker", "run", | ||
"--rm", "-t", | ||
"-w", $workDir, | ||
"-v", "${cwd}:${workDir}" | ||
) | ||
|
||
foreach ($pair in $cacheDirs.GetEnumerator()) { | ||
$hostDir = $pair.Key | ||
$containerDir = $pair.Value | ||
New-Item -Path $hostDir -ItemType Directory -Force | Out-Null | ||
$dockerCmd += @( | ||
"-v", "${hostDir}:${containerDir}" | ||
) | ||
} | ||
|
||
$dockerCmd += @( | ||
"rocstreaming/env-flutter:${Target}" | ||
) | ||
|
||
if ($Target -eq "android") { | ||
$dockerCmd += @( | ||
"flutter", "build", "apk", "--release" | ||
) | ||
} | ||
|
||
Print-Msg "Running ${Target} build in docker" | ||
Run-Cmd $dockerCmd | ||
|
||
if ($Target -eq "android") { | ||
$appType = "apk" | ||
$appFile = "roc-droid-$(Project-Version).apk" | ||
} | ||
|
||
Print-Msg | ||
Print-Msg "Copied ${Target} ${appType} to dist\${Target}\release\${appFile}" | ||
Get-ChildItem "dist\${Target}\release" |
Oops, something went wrong.