-
Notifications
You must be signed in to change notification settings - Fork 24
/
python_build_script.py
executable file
·66 lines (53 loc) · 2.6 KB
/
python_build_script.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
import os
import datetime
import logging
import itertools
# Set up logging
log_filename = 'test_results_{}.log'.format(datetime.datetime.now().strftime('%Y%m%d_%H%M%S'))
logging.basicConfig(filename=log_filename, level=logging.INFO, format='%(asctime)s:%(levelname)s:%(message)s')
# List all combinations of COUNTLY_USE_CUSTOM_SHA256 and COUNTLY_USE_SQLITE
options = [(0, 0), (0, 1), (1, 0), (1, 1)]
for custom_sha256, use_sqlite in options:
print("Running script with COUNTLY_USE_CUSTOM_SHA256="+str(custom_sha256)+" and COUNTLY_USE_SQLITE="+str(use_sqlite))
logging.info("Running script with COUNTLY_USE_CUSTOM_SHA256="+str(custom_sha256)+" and COUNTLY_USE_SQLITE="+str(use_sqlite))
# Check if script is in the "build" folder
if os.path.basename(os.getcwd()) == "build":
print("In build folder. Changing directory...")
logging.info("In build folder. Changing directory...")
os.chdir("..")
print("Current directory:", os.getcwd())
logging.info("Current directory: {}".format(os.getcwd()))
else:
print("Not in build folder. Current directory:", os.getcwd())
logging.info("Not in build folder. Current directory: {}".format(os.getcwd()))
# Delete "build" folder and subfolders
print("Deleting folder and its subfolders...")
logging.info("Deleting folder and its subfolders...")
os.system("rm -rf build")
print("Folder and subfolders deleted.")
logging.info("Folder and subfolders deleted.")
# Run cmake to generate makefiles
build_dir = "build"
cmake_command = "cmake -DCOUNTLY_BUILD_SAMPLE=1 -DCOUNTLY_BUILD_TESTS=1 -DCOUNTLY_USE_CUSTOM_SHA256={} -DCOUNTLY_USE_SQLITE={} -B {} .".format(custom_sha256, use_sqlite, build_dir)
os.system(cmake_command)
logging.info("Ran cmake to generate makefiles.")
# Change directory to "build" and build the sample and tests
os.chdir("build")
print("Current directory:", os.getcwd())
logging.info("Current directory: {}".format(os.getcwd()))
os.system("make ./countly-sample")
os.system("make ./countly-tests")
# Redirect standard output and standard error to a file
output_file = "doctest_results.txt"
with open(output_file, "w") as f:
os.system("./countly-tests > {} 2>&1".format(output_file))
# Include doctest results in the log file
with open(output_file, "r") as f:
doctest_results = f.read()
logging.info("Doctest results:\n{}".format(doctest_results))
# Clean up
os.remove(output_file)
logging.info("Removed doctest output file.")
# Print status message
print("Done.")
logging.info("Script finished.")