-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuilddeps.py
executable file
·171 lines (140 loc) · 4.9 KB
/
builddeps.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
#
# builddeps.py
#
# Created by Ruibin.Chow on 2022/01/26.
# Copyright (c) 2022年 Ruibin.Chow All rights reserved.
#
"""
"""
import os, re, json, sys, platform
import subprocess, shutil
import datetime
homeDir = ""
sourceDir = ""
outputDir = ""
sourceDirName = "depsSource"
outputDirName = "deps"
slash = "/"
if(platform.system()=='Windows'):
slash = "\\"
logList = []
def logRecord():
with open('builddeps.log', 'w') as fileHandle:
for logStr in logList:
fileHandle.write(str(logStr))
def log(string="", newline=True):
if newline:
logList.append(str(string) + "\n")
print(string, end="\n")
else:
logList.append(str(string))
print(string, end="")
pass
def operator(cmdString, newline=True):
log(cmdString)
output = os.popen(cmdString)
for line in output.readlines():
log(line, newline)
def operatorCMD(parameterList, newline=True):
cmdString = " ".join(parameterList)
operator(cmdString, newline)
pass
def buildDeps(dirStr, gitUrl, cloneList, cmdList, genBuilding=True, preCmdList=[]):
if len(dirStr) == 0 and len(gitUrl) == 0 and len(cloneList) == 0 and len(cmakeList) == 0:
log("Building Deps Was Error!")
return
log("-"*80)
log("Start Building Deps: " + dirStr)
os.chdir(sourceDir) #进入到源代码存放的目录
operatorCMD(cloneList)
os.chdir(dirStr)
if genBuilding:
buildDir = "build"
if os.path.exists(buildDir):
shutil.rmtree(buildDir)
os.makedirs(buildDir)
os.chdir(buildDir)
log("当前编译路径:" + os.getcwd())
if len(preCmdList) > 0:
operatorCMD(preCmdList, False)
operatorCMD(cmdList, False)
operator("make", False)
operator("make install", False)
pass
def buildDepsByList(buildDepsList, genBuilding=True, preCmdList=[]):
if len(buildDepsList) < 4:
log("Building Deps List Was Error!")
return
buildDeps(buildDepsList[0], buildDepsList[1], buildDepsList[2], buildDepsList[3], genBuilding, preCmdList)
pass
def genDepsCmakeList():
log("-"*80)
log("Generate Deps CmakeList in Path: " + homeDir)
os.chdir(homeDir)
depsCamke = "deps.cmake"
depsContent = """
message("This is deps.cmake")
set(deps_list SQLiteCpp sqlite3 pthread dl)
set(DEPS_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/"""+outputDirName+"""/include")
set(DEPS_LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/"""+outputDirName+"""/lib")
message("Deps Include Directory: ${DEPS_INCLUDE_DIR}")
message("Deps Lib Directory: ${DEPS_LIB_DIR}")
include_directories("${DEPS_INCLUDE_DIR}")
link_directories("${DEPS_LIB_DIR}")
"""
log("Deps CmakeList content: " + depsContent)
with open(depsCamke, "w") as fileHandler:
fileHandler.write(depsContent)
pass
if __name__ == '__main__':
begin = datetime.datetime.now()
log("更新时间:" + str(begin))
if not os.path.exists(sourceDirName):
os.makedirs(sourceDirName)
if not os.path.exists(outputDirName):
os.makedirs(outputDirName)
homeDir = sys.path[0]
log("Home Directory: " + homeDir)
sourceDir = homeDir + slash + sourceDirName
log("Deps Directory: " + sourceDir)
outputDir = homeDir + slash + outputDirName
log("Install Directory: " + outputDir)
abseilList = [
"abseil",
"https://github.com/abseil/abseil-cpp",
["git", "clone", "-b", "20211102.0", "--depth=1", "https://github.com/abseil/abseil-cpp", "abseil"],
["cmake", "-D CMAKE_BUILD_TYPE=RELEASE",
"-DABSL_BUILD_TESTING=ON -DABSL_USE_GOOGLETEST_HEAD=OFF -DCMAKE_CXX_STANDARD=11",
"-D", "CMAKE_INSTALL_PREFIX="+outputDir, ".."]
]
buildDepsByList(abseilList)
hiredisList = [
"hiredis",
"https://github.com/redis/hiredis",
["git", "clone", "-b", "v1.0.2", "--depth=1", "https://github.com/redis/hiredis", "hiredis"],
["cmake", "-D CMAKE_BUILD_TYPE=RELEASE",
"-D", "CMAKE_INSTALL_PREFIX="+outputDir, ".."]
]
buildDepsByList(hiredisList)
sqliteCppList = [
"SQLiteCpp",
"https://github.com/SRombauts/SQLiteCpp",
["git", "clone", "-b", "3.1.1", "--depth=1", "https://github.com/SRombauts/SQLiteCpp", "SQLiteCpp"],
["cmake", "-D CMAKE_BUILD_TYPE=RELEASE",
"-D", "CMAKE_INSTALL_PREFIX="+outputDir, ".."]
]
buildDepsByList(sqliteCppList)
# libconfiniList = [
# "libconfini",
# "https://github.com/madmurphy/libconfini",
# ["git", "clone", "-b", "1.16.3", "--depth=1", "https://github.com/madmurphy/libconfini", "libconfini"],
# ["./configure", "--prefix="+outputDir]
# ]
# buildDepsByList(libconfiniList, genBuilding=False, preCmdList=["./bootstrap"])
genDepsCmakeList()
end = datetime.datetime.now()
log(('花费时间: %.3f 秒' % (end - begin).seconds))
logRecord()
pass