-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
50 lines (40 loc) · 1.29 KB
/
build.py
File metadata and controls
50 lines (40 loc) · 1.29 KB
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
"""The build script."""
import os
import os.path
import shutil
import subprocess
root_dir = os.path.dirname(os.path.abspath(__file__))
java_dir = os.path.join(root_dir, "donuts", "java")
jar_file = os.path.join(java_dir, "donuts-all.jar")
if os.name == "posix":
gradlew_cmd = "./gradlew"
elif os.name == "nt":
gradlew_cmd = "gradlew.bat"
def build_jar() -> None:
"""Generate the JAR file."""
if os.path.isfile(os.path.join(java_dir, "build.gradle")):
# Build the fat JAR file by Gradle.
subprocess.run( # noqa: S603
[gradlew_cmd, "-Dorg.gradle.project.version=", "donuts-python:shadowJar"],
cwd=java_dir,
check=True,
)
shutil.copy(
os.path.join(
java_dir, "donuts-python", "build", "libs", "donuts-python-all.jar"
),
jar_file,
)
if not os.path.isfile(jar_file):
raise OSError("Failed to generate the JAR file")
def run_gradle(*cmd: str) -> None:
"""Run a Gradle command."""
if not os.path.isfile(os.path.join(java_dir, "build.gradle")):
raise FileNotFoundError("build.gradle not found")
subprocess.run( # noqa: S603
[gradlew_cmd, *cmd],
cwd=java_dir,
check=True,
)
if __name__ == "__main__":
build_jar()