build_executable.x 3.36 KB
Newer Older
1
#!/usr/bin/env python
2
3
4
5
6
7
8
9
10
11
"""
-------------------------------------------------------------------------------
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.
-------------------------------------------------------------------------------
"""
12
13

import os
14
import argparse
15
import shutil
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
#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/<test_id_string>/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

#------------------------------------------------------------------------------
45
46

def main():
47
    """Main program for building the executable."""
48
49

    # Get the command line arguments.
50
51
52
53
54

    args = process_command_line_args()
    path_to_workspace = args.p
    #test_id = args.i

55
56
    # Create the temporary workspace.
    # Save the tempoary workspace for the submit executable.
57

58
59
    create_tmp_workspace(path_to_workspace)

60
61
62

    # Make the binary.

63
    make_exit_status = make_binary(path_to_workspace)
64

65
66
67
68
69
70
71
    if make_exit_status == 0:
        make_exit_value = 0
    else:
        make_exit_value = 1

    return make_exit_value

72
73
#------------------------------------------------------------------------------

74
def make_binary(path_to_workspace):
75
    """Execute the make."""
76
77

    # Get the current working directory.
78

79
80
81
82
    cwd = os.getcwd()

    # Get the 2 tail paths in the cwd.

83
84
85
    dir_head1, dir_tail1 = os.path.split(cwd)
    dir_head2, dir_tail2 = os.path.split(dir_head1)

86
87
    # Get the path to the Source directory for the application.

88
89
    path_to_source = os.path.join(dir_head2, "Source")

90
91
    # Now make the path to the build directory.

92
93
94
95
96
    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)
97
98

    # Change back to build directory.
99

100
101
102
    os.chdir(path_to_build_directory)

    # Make executable.
103

104
105
106
107
108
    make_command = "./make.sh"
    make_exit_status = os.system(make_command)

    return make_exit_status

109
#------------------------------------------------------------------------------
110
111

def create_tmp_workspace(path1):
112
    """Create the workspace dir."""
113
114
    os.makedirs(path1)

115
116
117
#------------------------------------------------------------------------------

if __name__ == '__main__':
118
    main()
119
120

#------------------------------------------------------------------------------