def build(service_directory):
"""
Builds a Service using the service configuration
inside the service directory.
:param service_directory: The location of the service directory
:return: The path to the generated executable file
"""
service_name = os.path.basename(service_directory)
current_dir = os.getcwd()
os.chdir(service_directory)
with open("service.json", 'r') as f:
config = json.load(f)
try:
Popen(config["build_commands"]).wait()
except BaseException as e:
print(e)
os.chdir(current_dir)
return
output = config["output_file"]
st = os.stat(output)
os.chmod(output, st.st_mode | stat.S_IEXEC) # Make executable
if os.path.basename(output) != service_name:
new_output = os.path.join(os.path.dirname(output), service_name)
os.rename(output, new_output)
output = new_output
os.chdir(current_dir)
return os.path.join(service_directory, output)
评论列表
文章目录