generic_cmd.py 661 B

12345678910111213141516171819202122232425262728293031
  1. import os
  2. import sys
  3. import json
  4. import base64
  5. import subprocess
  6. if __name__ == '__main__':
  7. p = sys.argv.index('--')
  8. ctx = base64.b64decode(sys.argv[p + 1].encode()).decode()
  9. kv = {}
  10. for x in sys.argv[1:p]:
  11. k, v = x.split('=')
  12. ctx = ctx.replace(f'$({k})', v)
  13. kv[k] = v
  14. cmd = json.loads(ctx)
  15. args = cmd['cmd_args']
  16. cwd = cmd.get('cwd', kv['B'])
  17. env = dict(**os.environ)
  18. env['ARCADIA_ROOT_DISTBUILD'] = kv['S']
  19. env.update(cmd['env'])
  20. out = subprocess.check_output(args, env=env, cwd=cwd)
  21. if stdout := cmd.get('stdout'):
  22. with open(stdout, 'wb') as f:
  23. f.write(out)