Skip to content

Commit b9fb965

Browse files
authored
Merge pull request #106 from Distributive-Network/hamada/fix-104-run-poetry-build-at-top-level
fix(build.py): build.py doesn't assume location
2 parents c36d74f + 2c8884e commit b9fb965

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

build.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
import subprocess
77
import os, sys
88
import platform
9+
from typing import Optional
910

1011
TOP_DIR = os.path.abspath(os.path.dirname(__file__))
1112
BUILD_DIR = os.path.join(TOP_DIR, "build")
1213

1314
# Get number of CPU cores
1415
CPUS = os.cpu_count() or 1
1516

16-
def execute(cmd: str):
17+
def execute(cmd: str, cwd: Optional[str] = None):
1718
popen = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT,
18-
shell = True, text = True )
19+
shell = True, text = True, cwd = cwd )
1920
for stdout_line in iter(popen.stdout.readline, ""):
2021
sys.stdout.write(stdout_line)
2122
sys.stdout.flush()
@@ -27,33 +28,31 @@ def execute(cmd: str):
2728

2829
def ensure_spidermonkey():
2930
# Check if SpiderMonkey libs already exist
30-
spidermonkey_lib_exist = os.path.exists("./_spidermonkey_install/lib")
31+
spidermonkey_lib_exist = os.path.exists(os.path.join( TOP_DIR, "_spidermonkey_install/lib" ))
3132
if spidermonkey_lib_exist:
3233
return
3334

3435
# Build SpiderMonkey
35-
execute("bash ./setup.sh")
36+
execute("bash ./setup.sh", cwd = TOP_DIR)
3637

3738
def run_cmake_build():
3839
os.makedirs(BUILD_DIR, exist_ok=True) # mkdir -p
39-
os.chdir(BUILD_DIR)
4040
if platform.system() == "Windows":
41-
execute("cmake .. -T ClangCL") # use Clang/LLVM toolset for Visual Studio
41+
execute("cmake .. -T ClangCL", cwd=BUILD_DIR) # use Clang/LLVM toolset for Visual Studio
4242
else:
43-
execute("cmake ..")
44-
execute(f"cmake --build . -j{CPUS} --config Release")
45-
os.chdir(TOP_DIR)
43+
execute("cmake ..", cwd=BUILD_DIR)
44+
execute(f"cmake --build . -j{CPUS} --config Release", cwd=BUILD_DIR)
4645

4746
def copy_artifacts():
4847
if platform.system() == "Windows":
49-
execute("cp ./build/src/*/pythonmonkey.pyd ./python/pythonmonkey/") # Release or Debug build
50-
execute("cp ./_spidermonkey_install/lib/mozjs-*.dll ./python/pythonmonkey/")
48+
execute("cp ./build/src/*/pythonmonkey.pyd ./python/pythonmonkey/", cwd=TOP_DIR) # Release or Debug build
49+
execute("cp ./_spidermonkey_install/lib/mozjs-*.dll ./python/pythonmonkey/", cwd=TOP_DIR)
5150
else:
52-
execute("cp ./build/src/pythonmonkey.so ./python/pythonmonkey/")
53-
execute("cp ./_spidermonkey_install/lib/libmozjs* ./python/pythonmonkey/")
51+
execute("cp ./build/src/pythonmonkey.so ./python/pythonmonkey/", cwd=TOP_DIR)
52+
execute("cp ./_spidermonkey_install/lib/libmozjs* ./python/pythonmonkey/", cwd=TOP_DIR)
5453

5554
def build():
56-
execute("git submodule update --init --recursive")
55+
execute("git submodule update --init --recursive", cwd=TOP_DIR)
5756
ensure_spidermonkey()
5857
run_cmake_build()
5958
copy_artifacts()

0 commit comments

Comments
 (0)