-
Notifications
You must be signed in to change notification settings - Fork 37
/
build.py
68 lines (56 loc) · 1.98 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
import os
import sys
import shutil
import subprocess
from argparse import ArgumentParser
#Compile java code
dest = 'GVGAI_Build'
def get_src(path):
source = []
for root, _, files in os.walk(path):
for f in files:
if(f.endswith('.java')):
source.append(os.path.join(root, f))
return source
def main(dir):
if(shutil.which("javac")):
#Verify directory and import local file
try:
sys.path.append(dir)
import check_build
except ImportError:
raise ImportError("Can't import check_build from the given directory.")
except:
raise Exception("Invalid directory path.")
try:
path = os.path.join(dir, dest)
if(os.path.isdir(path)):
shutil.rmtree(path)
os.makedirs(path, exist_ok=True)
#Build Java files
src_path = os.path.join(dir, "src")
source = get_src(src_path)
subprocess.run(["javac", "-d", path] + source, check=True)
#Save hash of build in directory
hash = check_build.dirHash(src_path)
check_build.saveChecksum(path, hash)
except PermissionError as e:
print("Could not edit directory '{}'. Check that you have proper permisions in the installation directory.".format(dest))
raise e
except subprocess.CalledProcessError as e:
print("Failed to build java source code. Make sure you have Java JDK installed (> 7) and javac works.")
print("This build process has not been tested on Windows. Feel free to contribute fixes to the build.py file to get this working on Windows.")
raise e
else:
raise Exception("Command 'javac' is not found. Can't compile source code. May need to install Java JDK or fix path variables.")
if __name__ == "__main__":
d_path = os.path.join(os.path.dirname(__file__), "gym_gvgai", "envs", "gvgai")
parser = ArgumentParser()
parser.add_argument("-p","--path",
type=str,
default=d_path,
help="Path to where Java project exists")
args = parser.parse_args()
if(not os.path.isdir(os.path.join(args.path, 'src'))):
raise Exception("There is no Java 'src' in this directory")
main(args.path)