Исправил Flutter runtime окружение
Этот коммит содержится в:
@@ -9,6 +9,8 @@ from backend.shell_runner import run_command
|
|||||||
|
|
||||||
router = APIRouter(prefix='/api/runtime', tags=['runtime'])
|
router = APIRouter(prefix='/api/runtime', tags=['runtime'])
|
||||||
|
|
||||||
|
FLUTTER_ENV = 'export HOME=/root PUB_CACHE=/root/.pub-cache PATH=/root/flutter/bin:/root/Android/cmdline-tools/latest/bin:/root/Android/platform-tools:$PATH && '
|
||||||
|
|
||||||
|
|
||||||
class RuntimeCommandRequest(BaseModel):
|
class RuntimeCommandRequest(BaseModel):
|
||||||
workspace: str
|
workspace: str
|
||||||
@@ -25,22 +27,22 @@ RUNTIME_COMMANDS: dict[str, dict] = {
|
|||||||
},
|
},
|
||||||
'flutter_clean': {
|
'flutter_clean': {
|
||||||
'label': 'Flutter Clean',
|
'label': 'Flutter Clean',
|
||||||
'command': 'flutter clean',
|
'command': f'{FLUTTER_ENV}flutter clean',
|
||||||
'timeout': 900,
|
'timeout': 900,
|
||||||
},
|
},
|
||||||
'flutter_pub_get': {
|
'flutter_pub_get': {
|
||||||
'label': 'Flutter Pub Get',
|
'label': 'Flutter Pub Get',
|
||||||
'command': 'flutter pub get',
|
'command': f'{FLUTTER_ENV}flutter pub get',
|
||||||
'timeout': 900,
|
'timeout': 900,
|
||||||
},
|
},
|
||||||
'flutter_build_apk': {
|
'flutter_build_apk': {
|
||||||
'label': 'Flutter Build APK',
|
'label': 'Flutter Build APK',
|
||||||
'command': 'flutter build apk --release',
|
'command': f'{FLUTTER_ENV}flutter build apk --release',
|
||||||
'timeout': 3600,
|
'timeout': 3600,
|
||||||
},
|
},
|
||||||
'flutter_run_profile': {
|
'flutter_run_profile': {
|
||||||
'label': 'Flutter Run Profile',
|
'label': 'Flutter Run Profile',
|
||||||
'command': 'flutter run --profile',
|
'command': f'{FLUTTER_ENV}flutter run --profile',
|
||||||
'timeout': 1800,
|
'timeout': 1800,
|
||||||
'device': True,
|
'device': True,
|
||||||
},
|
},
|
||||||
@@ -48,13 +50,11 @@ RUNTIME_COMMANDS: dict[str, dict] = {
|
|||||||
'label': 'ADB Reconnect',
|
'label': 'ADB Reconnect',
|
||||||
'command': 'adb reconnect',
|
'command': 'adb reconnect',
|
||||||
'timeout': 120,
|
'timeout': 120,
|
||||||
'root_cwd': True,
|
|
||||||
},
|
},
|
||||||
'adb_logcat': {
|
'adb_logcat': {
|
||||||
'label': 'ADB Logcat Snapshot',
|
'label': 'ADB Logcat Snapshot',
|
||||||
'command': 'adb logcat -d -t 300',
|
'command': 'adb logcat -d -t 300',
|
||||||
'timeout': 120,
|
'timeout': 120,
|
||||||
'root_cwd': True,
|
|
||||||
'device': True,
|
'device': True,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -67,14 +67,14 @@ def _workspace_cwd(workspace: str) -> str:
|
|||||||
return path.as_posix()
|
return path.as_posix()
|
||||||
|
|
||||||
|
|
||||||
def _with_device(command: str, device: str | None) -> str:
|
def _with_device(command: str, device: str | None, enabled: bool) -> str:
|
||||||
if not device:
|
if not enabled or not device:
|
||||||
return command
|
return command
|
||||||
|
|
||||||
if command.startswith('adb '):
|
if 'adb ' in command:
|
||||||
return command.replace('adb ', f'adb -s {device} ', 1)
|
return command.replace('adb ', f'adb -s {device} ', 1)
|
||||||
|
|
||||||
if command.startswith('flutter ') and ' -d ' not in command:
|
if 'flutter ' in command and ' -d ' not in command:
|
||||||
return f'{command} -d {device}'
|
return f'{command} -d {device}'
|
||||||
|
|
||||||
return command
|
return command
|
||||||
@@ -106,13 +106,8 @@ async def runtime_commands():
|
|||||||
@router.post('/event')
|
@router.post('/event')
|
||||||
async def runtime_event(payload: dict):
|
async def runtime_event(payload: dict):
|
||||||
message = payload.get('message', 'unknown runtime event')
|
message = payload.get('message', 'unknown runtime event')
|
||||||
|
|
||||||
add_log(message)
|
add_log(message)
|
||||||
|
return {'success': True, 'message': message}
|
||||||
return {
|
|
||||||
'success': True,
|
|
||||||
'message': message,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@router.post('/command')
|
@router.post('/command')
|
||||||
@@ -123,15 +118,15 @@ async def runtime_command(payload: RuntimeCommandRequest):
|
|||||||
raise HTTPException(status_code=400, detail='Runtime command is not allowed')
|
raise HTTPException(status_code=400, detail='Runtime command is not allowed')
|
||||||
|
|
||||||
cwd = _workspace_cwd(payload.workspace)
|
cwd = _workspace_cwd(payload.workspace)
|
||||||
command = _with_device(config['command'], payload.device)
|
command = _with_device(
|
||||||
|
config['command'],
|
||||||
|
payload.device,
|
||||||
|
bool(config.get('device')),
|
||||||
|
)
|
||||||
|
|
||||||
add_log(f"Runtime command started: {config['label']}")
|
add_log(f"Runtime command started: {config['label']}")
|
||||||
|
|
||||||
result = run_command(
|
result = run_command(command, cwd, timeout=int(config.get('timeout', 900)))
|
||||||
command,
|
|
||||||
cwd,
|
|
||||||
timeout=int(config.get('timeout', 900)),
|
|
||||||
)
|
|
||||||
|
|
||||||
add_log(
|
add_log(
|
||||||
f"Runtime command finished: {config['label']} "
|
f"Runtime command finished: {config['label']} "
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user