-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
6 changed files
with
292 additions
and
19 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
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 | ||
# preable 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" |
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,99 @@ | ||
#! /usr/bin/env python3 | ||
|
||
import argparse | ||
import os | ||
import platform | ||
import re | ||
import subprocess | ||
import sys | ||
|
||
os.chdir(os.path.join( | ||
os.path.dirname(os.path.abspath(__file__)), '..')) | ||
|
||
# We have docker_build.bat that is a windows-specific version of docker_build.py. | ||
# It exists so that docker build doesn't require python on windows. | ||
# | ||
# But if the user still runs docker_build.py on windows, we redirect call to | ||
# docker_build.bat, as we don't want duplicating windows-specific logic in two scripts. | ||
# | ||
# The rest of the script assumes that we're on a Unix-like system. | ||
if platform.system() == 'Windows': | ||
try: | ||
subprocess.check_call( | ||
['script/docker_build.bat'] + sys.argv[1:], shell=False) | ||
exit(0) | ||
except: | ||
exit(1) | ||
|
||
def project_version(): | ||
with open('pubspec.yaml') as fp: | ||
m = re.search(r'^version:\s*(\S+)\s*$', fp.read(), re.MULTILINE) | ||
return m.group(1) | ||
|
||
def print_msg(msg=''): | ||
print(f'\033[1;34m{msg}\033[0m', file=sys.stderr) | ||
|
||
def run_cmd(cmd): | ||
print(' '.join(cmd), file=sys.stderr) | ||
try: | ||
subprocess.check_call(cmd) | ||
except: | ||
exit(1) | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('target', | ||
nargs='?', | ||
choices=['android'], default='android') | ||
|
||
args = parser.parse_args() | ||
|
||
cwd = os.path.abspath(os.getcwd()) | ||
uid = os.getuid() | ||
gid = os.getgid() | ||
|
||
work_dir = None | ||
cache_dirs = {} | ||
|
||
if args.target == 'android': | ||
work_dir = '/root/build' # container | ||
cache_dirs = { | ||
# host: container | ||
f'{cwd}/build/dockercache/pub': '/root/.pub-cache', | ||
f'{cwd}/build/dockercache/gradle': '/root/.gradle', | ||
f'{cwd}/build/dockercache/android': '/root/.android/cache', | ||
} | ||
|
||
docker_cmd = [ | ||
'docker', 'run', | ||
'--rm', '-t', | ||
'-u', f'{uid}:{gid}', | ||
'-w', work_dir, | ||
'-v', f'{cwd}:{work_dir}', | ||
] | ||
|
||
for host_dir, container_dir in cache_dirs.items(): | ||
os.makedirs(host_dir, exist_ok=True) | ||
docker_cmd += [ | ||
'-v', f'{host_dir}:{container_dir}', | ||
] | ||
|
||
docker_cmd += [ | ||
f'rocstreaming/env-flutter:{args.target}', | ||
] | ||
|
||
if args.target == 'android': | ||
docker_cmd += [ | ||
'flutter', 'build', 'apk', '--release', | ||
] | ||
|
||
print_msg(f'Running {args.target} build in docker') | ||
run_cmd(docker_cmd) | ||
|
||
if args.target == 'android': | ||
app_type = 'apk' | ||
app_file = f'roc-droid-{project_version()}.apk' | ||
|
||
print_msg() | ||
|
||
print_msg(f'Copied {args.target} {app_type} to dist/{args.target}/release/{app_file}') | ||
run_cmd(['ls', '-lh', f'dist/{args.target}/release']) |