#!/usr/bin/env python3 """Prepare a unique, locally consented build, then validate and package it.""" import argparse,datetime,pathlib,secrets,subprocess,sys root=pathlib.Path(__file__).resolve().parents[1] p=argparse.ArgumentParser() p.add_argument('target',choices=['apk','aab','ios-simulator','ios','all','distribution']) p.add_argument('--release',action='store_true') args=p.parse_args() if (args.release or args.target == 'distribution') and args.target in ['apk','aab','all','distribution'] and not (root/'android/key.properties').exists(): raise SystemExit('Provide android/key.properties with your release signing identity first.') def run(*command): subprocess.run(command,cwd=root,check=True) run('flutter','pub','get') run(sys.executable,str(root/'tool/notices.py')) build_id='sm-mobile-'+datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%SZ')+'-'+secrets.token_hex(6) import re version=re.search(r'^version:\s*([0-9]+\.[0-9]+\.[0-9]+)\+[0-9]+\s*$',(root/'pubspec.yaml').read_text(),re.M).group(1) (root/'lib/core/build_info.dart').write_text("// Generated by tool/build.py. Never reuse for a different distributed build.\nconst appVersion = '"+version+"';\nconst buildId = '"+build_id+"';\n") run('flutter','analyze') run('flutter','test') mode='--release' if args.release or args.target == 'distribution' else '--debug' if args.target in ['apk','all','distribution']: run('flutter','build','apk',mode) if args.target in ['aab','all','distribution']: run('flutter','build','appbundle',mode) if args.target in ['ios-simulator','all']: run('flutter','build','ios','--simulator') if args.target in ['ios','distribution']: run('flutter','build','ios','--release','--no-codesign') print('Built '+build_id)