Skip to content

Commit f50a098

Browse files
authored
Merge pull request #49 from gutjuri/fix-build-script
build.py: replace `os.system` with `subprocess.run`
2 parents 461650e + 7d5fff7 commit f50a098

File tree

5 files changed

+34
-32
lines changed

5 files changed

+34
-32
lines changed

build.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import platform
33
import sys
44
import multiprocessing
5+
import subprocess
56

67
if __name__ == "__main__":
78
import thirdparty.getEigen as getEigen
@@ -78,9 +79,9 @@ def Build(mainArgs, cmakeArgs,install, prefix, par):
7879

7980

8081

81-
mkDirCmd = "mkdir -p {0}".format(buildDir);
82-
CMakeCmd = "cmake -S . -B {0} {1}".format(buildDir, argStr)
83-
BuildCmd = "cmake --build {0} {1} {2} ".format(buildDir, config, parallel)
82+
mkDirCmd = "mkdir -p {0}".format(buildDir).split()
83+
CMakeCmd = "cmake -S . -B {0} {1}".format(buildDir, argStr).split()
84+
BuildCmd = "cmake --build {0} {1} {2} ".format(buildDir, config, parallel).split()
8485

8586

8687
#InstallCmd = ""
@@ -104,13 +105,13 @@ def Build(mainArgs, cmakeArgs,install, prefix, par):
104105
# print(InstallCmd)
105106
print("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n")
106107

107-
os.system(mkDirCmd)
108-
os.system(CMakeCmd)
109-
os.system(BuildCmd)
108+
subprocess.run(mkDirCmd, check=True)
109+
subprocess.run(CMakeCmd, check=True)
110+
subprocess.run(BuildCmd, check=True)
110111
#if len(sudo) > 0:
111112
# print("installing libraries: {0}".format(InstallCmd))
112113
#
113-
#os.system(InstallCmd)
114+
#subprocess.run(InstallCmd, check=True)
114115

115116

116117
def getInstallArgs(args):

thirdparty/getEigen.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,16 @@ def getEigen(install, prefix, par):
7777
if install and len(prefix) == 0:
7878
prefix = "/usr/local"
7979

80-
mkdirCmd = sudo + "mkdir -p " + prefix + "/include/Eigen/"
81-
InstallCmd = sudo + "cp -rf ./Eigen " + prefix + "/include"
80+
mkdirCmd = (sudo + "mkdir -p " + prefix + "/include/Eigen/").split()
81+
InstallCmd = (sudo + "cp -rf ./Eigen " + prefix + "/include").split()
8282

8383
print("\n=========== getEigen.py =============")
8484
print(mkdirCmd)
8585
print(InstallCmd)
8686
print("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n")
8787

88-
os.system(mkdirCmd)
89-
os.system(InstallCmd)
88+
subprocess.run(mkdirCmd, check=True)
89+
subprocess.run(InstallCmd, check=True)
9090

9191
#buildDir = "out/unix"
9292

thirdparty/getFunction2.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def getFunction2(install, prefix, par):
1919
url = "https://github.com/Naios/function2.git"
2020

2121
if os.path.exists(folder) == False:
22-
os.system("git clone --depth 1 " + url)
22+
subprocess.run(("git clone --depth 1 " + url).split(), check=True)
2323
os.chdir(folder)
24-
os.system("git checkout 3a0746bf5f601dfed05330aefcb6854354fce07d")
24+
subprocess.run("git checkout 3a0746bf5f601dfed05330aefcb6854354fce07d".split(), check=True)
2525

2626
sudo = ""
2727
if(osStr == "Windows"):
@@ -59,16 +59,16 @@ def getFunction2(install, prefix, par):
5959
if install and len(prefix) == 0:
6060
prefix = "/usr/local"
6161

62-
mkdirCmd = sudo + "mkdir -p " + prefix + "/include/function2/"
63-
InstallCmd = sudo + "cp -rf ./include/function2 " + prefix + "/include"
62+
mkdirCmd = (sudo + "mkdir -p " + prefix + "/include/function2/").split()
63+
InstallCmd = (sudo + "cp -rf ./include/function2 " + prefix + "/include").split()
6464

6565
print("\n=========== getFunction2.py =============")
6666
print(mkdirCmd)
6767
print(InstallCmd)
6868
print("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n")
6969

70-
os.system(mkdirCmd)
71-
os.system(InstallCmd)
70+
subprocess.run(mkdirCmd, check=True)
71+
subprocess.run(InstallCmd, check=True)
7272

7373
#buildDir = "out/unix"
7474

thirdparty/getJson.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def getJson(install, prefix, par):
1919
url = "https://github.com/nlohmann/json.git "
2020

2121
if os.path.exists(folder) == False:
22-
os.system("git clone --depth 1 " + url)
22+
subprocess.run(("git clone --depth 1 " + url).split(), check=True)
2323
os.chdir(folder)
24-
#os.system("git checkout 3a0746bf5f601dfed05330aefcb6854354fce07d")
24+
#subprocess.run("git checkout 3a0746bf5f601dfed05330aefcb6854354fce07d".split(), check=True)
2525

2626
sudo = ""
2727
if(osStr == "Windows"):
@@ -59,16 +59,16 @@ def getJson(install, prefix, par):
5959
if install and len(prefix) == 0:
6060
prefix = "/usr/local"
6161

62-
mkdirCmd = sudo + "mkdir -p " + prefix + "/include/nlohmann/"
63-
InstallCmd = sudo + "cp -rf ./include/nlohmann " + prefix + "/include"
62+
mkdirCmd = (sudo + "mkdir -p " + prefix + "/include/nlohmann/").split()
63+
InstallCmd = (sudo + "cp -rf ./include/nlohmann " + prefix + "/include").split()
6464

6565
print("\n=========== getJson.py =============")
6666
print(mkdirCmd)
6767
print(InstallCmd)
6868
print("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n")
6969

70-
os.system(mkdirCmd)
71-
os.system(InstallCmd)
70+
subprocess.run(mkdirCmd, check=True)
71+
subprocess.run(InstallCmd, check=True)
7272

7373

7474

thirdparty/getLibOTe.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import os
22
import sys
33
import platform
4+
import subprocess
45

56

67
def getLibOTe(install, prefix, par,libOTe, boost, relic):
78

89
cwd = os.getcwd()
910

1011
if os.path.isdir("libOTe") == False:
11-
os.system("git clone --recursive https://github.com/osu-crypto/libOTe.git")
12+
subprocess.run("git clone --recursive https://github.com/osu-crypto/libOTe.git".split(), check=True)
1213

1314
os.chdir(cwd + "/libOTe")
14-
os.system("git checkout cf537295c47a3924c13030a9b796cee9d6ebeace ")
15-
os.system("git submodule update ")
15+
subprocess.run("git checkout cf537295c47a3924c13030a9b796cee9d6ebeace".split(), check=True)
16+
subprocess.run("git submodule update".split(), check=True)
1617

1718
osStr = (platform.system())
1819

@@ -46,9 +47,9 @@ def getLibOTe(install, prefix, par,libOTe, boost, relic):
4647
cmakePrefix = "-DCMAKE_PREFIX_PATH=" + prefix
4748

4849
cmd = "python3 build.py " + sudo + " --par=" + str(par) + " " + installCmd + " " + debug
49-
boostCmd = cmd + " --setup --boost "
50-
relicCmd = cmd + " --setup --relic "
51-
libOTeCmd = cmd + " -DENABLE_CIRCUITS=ON " + cmakePrefix;
50+
boostCmd = (cmd + " --setup --boost ").split()
51+
relicCmd = (cmd + " --setup --relic ").split()
52+
libOTeCmd = (cmd + " -DENABLE_CIRCUITS=ON " + cmakePrefix).split()
5253

5354

5455
print("\n\n=========== getLibOTe.py ================")
@@ -61,11 +62,11 @@ def getLibOTe(install, prefix, par,libOTe, boost, relic):
6162
print("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n\n")
6263

6364
if boost:
64-
os.system(boostCmd)
65+
subprocess.run(boostCmd, check=True)
6566
if relic:
66-
os.system(relicCmd)
67+
subprocess.run(relicCmd, check=True)
6768
if libOTe:
68-
os.system(libOTeCmd)
69+
subprocess.run(libOTeCmd, check=True)
6970

7071
os.chdir(cwd)
7172

0 commit comments

Comments
 (0)