Flutter Engine
The Flutter Engine
get_dot_git_folder.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5#
6# This python script is a wrapper around `git rev-parse --resolve-git-dir`.
7# This is used for the build system to work with git worktrees.
8
9import sys
10import subprocess
11import utils
12
13
14def main():
15 try:
16 if len(sys.argv) != 3:
17 raise Exception('Expects exactly 2 arguments.')
18 args = ['git', 'rev-parse', '--resolve-git-dir', sys.argv[1]]
19
20 windows = utils.GuessOS() == 'win32'
21 if windows:
22 process = subprocess.Popen(args,
23 stdout=subprocess.PIPE,
24 stderr=subprocess.PIPE,
25 stdin=subprocess.PIPE,
26 shell=True,
27 universal_newlines=True)
28 else:
29 process = subprocess.Popen(args,
30 stdout=subprocess.PIPE,
31 stderr=subprocess.PIPE,
32 stdin=subprocess.PIPE,
33 shell=False,
34 universal_newlines=True)
35
36 outs, _ = process.communicate()
37
38 if process.returncode != 0:
39 raise Exception('Got non-0 exit code from git.')
40
41 print(outs.strip())
42 except:
43 # Fall back to fall-back path.
44 print(sys.argv[2])
45
46
47if __name__ == '__main__':
48 sys.exit(main())
Definition: main.py:1
def print(*args, **kwargs)
Definition: run_tests.py:49
def GuessOS()
Definition: utils.py:21