Skip to content

Commit

Permalink
add generic json command executor for external bs
Browse files Browse the repository at this point in the history
commit_hash:0833419ebee283a1fb0e0a41f615b0bf7b61f548
  • Loading branch information
pg committed Oct 18, 2024
1 parent 479e425 commit 2fe9813
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions build/scripts/generic_cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
import sys
import json
import base64
import subprocess


if __name__ == '__main__':
p = sys.argv.index('--')
ctx = base64.b64decode(sys.argv[p + 1].encode()).decode()
kv = {}

for x in sys.argv[1:p]:
k, v = x.split('=')
ctx = ctx.replace(f'$({k})', v)
kv[k] = v

cmd = json.loads(ctx)

args = cmd['cmd_args']
cwd = cmd.get('cwd', kv['B'])

env = dict(**os.environ)
env['ARCADIA_ROOT_DISTBUILD'] = kv['S']
env.update(cmd['env'])

out = subprocess.check_output(args, env=env, cwd=cwd)

if stdout := cmd.get('stdout'):
with open(stdout, 'wb') as f:
f.write(out)

0 comments on commit 2fe9813

Please sign in to comment.