-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.py
88 lines (75 loc) · 3.04 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
# coding=utf-8
import os
import sys
import io
import platform
import subprocess
import json
# os.system("chcp 65001")
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8')
def system(command):
retcode = os.system(command)
if retcode != 0:
raise Exception("Error while executing:\n\t %s" % command)
def get_git_tag() -> str:
"""得到当前git的tag文本"""
# stream = os.popen('git tag --sort=-version:refname | head -n1')
# gitTag = stream.read()
# return gitTag.strip()
# if platform.system() == "Windows":
# cmd = 'git tag --sort=-version:refname | Select -First 1'
# 这个subprocess.Popen不能支持上面的句子
process = subprocess.Popen('git tag --sort=-version:refname', shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE, encoding="utf-8")
stdout, stderr = process.communicate()
if stderr:
print("get_git_tag():Error "+stderr)
if stdout.strip():
return stdout.strip().split()[0]
print("git获取tag失败!")
return ""
if __name__ == "__main__":
print(sys.version)
# 删除原先安装的库,它会影响构建
system('conan remove xuexuejson -f')
params = " ".join(sys.argv[1:])
gitTag = get_git_tag()
print("当前git的tag是:" + gitTag)
sys.stdout.flush()
pydir = os.path.split(os.path.realpath(__file__))[0]
tempDir = pydir+os.sep+"temp"
archivedir = tempDir+os.sep+"archive"+os.sep+"xuexuejson"
# 实际上python设置的环境变量没有办法传递到CI那里
os.environ['CUR_GIT_TAG'] = gitTag
print("尝试设置环境变量,当前CUR_GIT_TAG环境变量是:" + os.environ['CUR_GIT_TAG'])
# 设置环境变量,CONAN_REVISIONS_ENABLED
os.environ['CONAN_REVISIONS_ENABLED'] = '1'
# 设置环境变量,拷贝ARCHIVE的文件夹目录
os.environ['CONAN_ARCHIVE_PATH'] = archivedir
print('尝试设置环境变量,设置archivedir:', os.environ['CONAN_ARCHIVE_PATH'])
# 递归创建一下文件夹
os.makedirs(archivedir, exist_ok=True)
# 保存环境变量到json
env_dist = {}
for key in os.environ:
env_dist[key] = os.environ[key]
jsonstr = json.dumps(env_dist)
open(tempDir+os.sep+'env.json', 'w').write(jsonstr)
if gitTag:
open(tempDir+os.sep+'CUR_GIT_TAG', 'w').write(gitTag)
print("当前平台是:"+platform.system())
sys.stdout.flush()
if platform.system() == "Windows":
cmd = 'conan create . daixian/stable -s compiler.version=15 -s compiler.runtime=MD \
-s arch=x86_64 -s build_type=Release --build missing %s' % params
system(cmd)
elif platform.system() == "Linux":
# 使用gcc7
os.environ['CC'] = '/usr/bin/gcc-7'
os.environ['CXX'] = '/usr/bin/g++-7'
system('conan create . daixian/stable -s compiler.version=7.5 -s arch=x86_64 \
-s build_type=Release --build missing')
else:
pass