Browse Source

add generic json command executor for external bs
commit_hash:0833419ebee283a1fb0e0a41f615b0bf7b61f548

pg 4 months ago
parent
commit
2a43a3e9b6
1 changed files with 31 additions and 0 deletions
  1. 31 0
      build/scripts/generic_cmd.py

+ 31 - 0
build/scripts/generic_cmd.py

@@ -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)