#!/usr/bin/env python """ ------------------------------------------------------------------------------- File: build_executable.x Author: Arnold Tharrington (arnoldt@ornl.gov) Modified: Veronica G. Vergara Larrea, Wayne Joubert National Center for Computational Sciences, Scientific Computing Group. Oak Ridge National Laboratory Copyright (C) 2016 Oak Ridge National Laboratory, UT-Battelle, LLC. ------------------------------------------------------------------------------- """ import os import argparse import shutil #import subprocess #------------------------------------------------------------------------------ def process_command_line_args(): """Get the command line arguments.""" command_description = ( 'A driver program that builds the binary for the test.') p_help = ( 'The absolute path to the workspace. This path must have the ' 'appropiate permissions to permit the user of the test to r, w, and x.') i_help = ( 'The test id string. The build program uses this string to make a ' 'unique directory within path_to_workspace. We don\'t want concurrent ' 'builds to clobber each other. The submit program uses this string ' 'to write the job schedule id to Status//job_id.txt') parser = argparse.ArgumentParser(description=command_description) parser.add_argument('-p', help=p_help, required=True) parser.add_argument('-i', help=i_help, required=True) args = parser.parse_args() return args #------------------------------------------------------------------------------ def main(): """Main program for building the executable.""" # Get the command line arguments. args = process_command_line_args() path_to_workspace = args.p #test_id = args.i # Create the temporary workspace. # Save the tempoary workspace for the submit executable. create_tmp_workspace(path_to_workspace) # Make the binary. make_exit_status = make_binary(path_to_workspace) if make_exit_status == 0: make_exit_value = 0 else: make_exit_value = 1 return make_exit_value #------------------------------------------------------------------------------ def make_binary(path_to_workspace): """Execute the make.""" # Get the current working directory. cwd = os.getcwd() # Get the 2 tail paths in the cwd. dir_head1, dir_tail1 = os.path.split(cwd) dir_head2, dir_tail2 = os.path.split(dir_head1) # Get the path to the Source directory for the application. path_to_source = os.path.join(dir_head2, "Source") # Now make the path to the build directory. path_to_build_directory = os.path.join(path_to_workspace, "build_directory") # Copy Source to build directory. shutil.copytree(path_to_source, path_to_build_directory) # Change back to build directory. os.chdir(path_to_build_directory) # Make executable. make_command = "./make.sh" make_exit_status = os.system(make_command) return make_exit_status #------------------------------------------------------------------------------ def create_tmp_workspace(path1): """Create the workspace dir.""" os.makedirs(path1) #------------------------------------------------------------------------------ if __name__ == '__main__': main() #------------------------------------------------------------------------------