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
6 changed files
with
269 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,83 @@ | ||
REM -*- coding: utf-8; mode: powershell -*- | ||
|
||
@powershell -ExecutionPolicy Unrestricted -Command ^ | ||
"$me = '%~f0'; $arg = '%~1'; iex ((gc $me | out-string) -replace '(?s).*:start\r?\n', '')" | ||
@exit /b | ||
:start | ||
|
||
param ( | ||
[ValidateSet("android")] | ||
[string]$Target = "android" | ||
) | ||
|
||
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 Run-Cmd ($cmd) { | ||
Write-Host ($cmd -join " ") -ForegroundColor Yellow | ||
try { | ||
& $cmd[0] $cmd[1..$cmd.Length] | ||
} catch { | ||
exit 1 | ||
} | ||
} | ||
|
||
Set-Location -Path ` | ||
(Join-Path (Split-Path -parent $MyInvocation.MyCommand.Definition) "..") | ||
|
||
$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.ps1 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.ps1, 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']) |