未验证 提交 03992630 编写于 作者: Y Yu Yang 提交者: GitHub

fix(py): set `cwd` when get commit sha in setup.py (#14299)

`cwd` was not set before when get commit SHA. The default `cwd` is the current build directory. However, the build directory might not be the subdirectory of source. The `git` command will fail when that happened.

test=develop
上级 c28beb8a
...@@ -14,7 +14,8 @@ RC = 0 ...@@ -14,7 +14,8 @@ RC = 0
def git_commit(): def git_commit():
try: try:
cmd = ['git', 'rev-parse', 'HEAD'] cmd = ['git', 'rev-parse', 'HEAD']
git_commit = subprocess.Popen(cmd, stdout = subprocess.PIPE).communicate()[0].strip() git_commit = subprocess.Popen(cmd, stdout = subprocess.PIPE,
cwd="@PADDLE_SOURCE_DIR@").communicate()[0].strip()
except: except:
git_commit = 'Unknown' git_commit = 'Unknown'
git_commit = git_commit.decode() git_commit = git_commit.decode()
...@@ -44,7 +45,7 @@ def get_patch(): ...@@ -44,7 +45,7 @@ def get_patch():
def is_taged(): def is_taged():
try: try:
cmd = ['git', 'describe', '--exact-match', '--tags', 'HEAD', '2>/dev/null'] cmd = ['git', 'describe', '--exact-match', '--tags', 'HEAD', '2>/dev/null']
git_tag = subprocess.Popen(cmd, stdout = subprocess.PIPE).communicate()[0].strip() git_tag = subprocess.Popen(cmd, stdout = subprocess.PIPE, cwd="@PADDLE_SOURCE_DIR@").communicate()[0].strip()
git_tag = git_tag.decode() git_tag = git_tag.decode()
except: except:
return False return False
...@@ -55,8 +56,7 @@ def is_taged(): ...@@ -55,8 +56,7 @@ def is_taged():
return False return False
def write_version_py(filename='paddle/version.py'): def write_version_py(filename='paddle/version.py'):
cnt = ''' cnt = '''# THIS FILE IS GENERATED FROM PADDLEPADDLE SETUP.PY
# THIS FILE IS GENERATED FROM PADDLEPADDLE SETUP.PY
# #
full_version = '%(major)d.%(minor)d.%(patch)s' full_version = '%(major)d.%(minor)d.%(patch)s'
major = '%(major)d' major = '%(major)d'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册