aboutsummaryrefslogtreecommitdiff
path: root/project
diff options
context:
space:
mode:
authorMohammad Akhlaghi <mohammad@akhlaghi.org>2019-10-01 16:17:59 +0100
committerMohammad Akhlaghi <mohammad@akhlaghi.org>2019-10-01 16:23:39 +0100
commit7caa2845304c40540a336f840b3ca468bf6c8697 (patch)
tree2ee7942a848f6880e5e2f9c2252e365bc20b7e65 /project
parent6f86ba0c1f84b9c349666254c2a9716ba2058a3b (diff)
Preparation phase added before final building
In many real-world scenarios, `./project make' can really benefit from having some basic information about the data before being run. For example when quering a server. If we know how many datasets were downloaded and their general properties, it can greatly optmize the process when we are designing the solution to be run in `./project make'. Therefore with this commit, a new phase has been added to the template's design: `./project prepare'. In the raw template this is empty, because the simple analysis done in the template doesn't warrant it. But everything is ready for projects using the template to add preparation phases prior to the analysis.
Diffstat (limited to 'project')
-rwxr-xr-xproject128
1 files changed, 97 insertions, 31 deletions
diff --git a/project b/project
index 14fc272..fcf32fd 100755
--- a/project
+++ b/project
@@ -65,12 +65,14 @@ print_help() {
# Print the output.
cat <<EOF
Usage: $scriptname configure [OPTIONS]
+ $scriptname prepare [OPTIONS]
$scriptname make [OPTIONS]
Top-level script to manage the reproducible project. The high-level
operation is defined by the (mandatory) second argument:
configure - Configure project for this machine (e.g., build software).
+ prepare - Low-level preparations to optimize building with 'make'.
make - Run the project (do analysis and build outputs).
RECOMMENDATION: If this is the first time you are configuring this
@@ -147,6 +149,7 @@ do
case $1 in
# Main operation.
configure) func_operation_set $1; shift;;
+ prepare) func_operation_set $1; shift;;
make) func_operation_set $1; shift;;
@@ -218,6 +221,74 @@ fi
+# Run operations in controlled environment
+# ----------------------------------------
+controlled_env() {
+ # Get the full address of the build directory:
+ bdir=`.local/bin/realpath .build`
+
+ # Remove all existing environment variables (with `env -i') and only
+ # use some pre-defined environment variables, then build the project.
+ envmake=".local/bin/env -i HOME=$bdir sys_rm=$(which rm) $gopt"
+ envmake="$envmake .local/bin/make -f $1"
+ if ! [ x"$debug" = x ]; then envmake="$envmake --debug=$debug"; fi
+
+ # Set the number of jobs. Note that for the `configure.sh' script the
+ # default value has to be 0, so the default is the maximum number of
+ # threads. But here, the default value is 1.
+ if ! [ x"$jobs" = x0 ]; then envmake="$envmake -j$jobs"; fi
+
+ # Run the project
+ if [ x"$group" = x ]; then
+ $envmake $make_targets
+ else
+ # Set the group and permission flags.
+ sg "$group" "umask $perms && $envmake $make_targets"
+ fi
+}
+
+
+
+
+
+# Error messages
+# --------------
+#
+# Having the error messages here helps the over-all process be more
+# readable.
+print_error_abort() {
+ case $1 in
+ prepare)
+ cat <<EOF
+
+The project isn't configured for this system, or the configuration wasn't
+successful. To configure the project, please use this command:
+
+ $ ./project configure
+
+(TIP: if you have already ran this command once, run it with '-e' to use
+the previous configuration, run with '--help' for more info)
+
+EOF
+ exit 1;
+ ;;
+ make)
+ cat <<EOF
+
+The project preparation hasn't been completed, or it wasn't successful. To
+prepare the project prior to building it, please use this command:
+
+ $ ./project prepare
+
+EOF
+ exit 1;
+ ;;
+ esac
+}
+
+
+
+
# Do requested operation
# ----------------------
perms="u+r,u+w,g+r,g+w,o-r,o-w,o-x"
@@ -280,54 +351,49 @@ case $operation in
fi
;;
- # Run the project
- make)
+
+
+
+
+ # Run the input management.
+ prepare)
# Make sure the configure script has been completed properly
# (`configuration-done.txt' exists).
if ! [ -f .build/software/configuration-done.txt ]; then
- cat <<EOF
+ print_error_abort $operation
+ fi
-The project isn't configured for this system, or the configuration wasn't
-successful. To configure the project, please use this command:
+ # Run input-preparations in control environment
+ controlled_env reproduce/analysis/make/top-prepare.mk
+ ;;
- '$ ./project configure'
-(TIP: if you have already ran this command once, run it with '-e' to use
-the previous configuration, run with '--help' for more info)
-EOF
- exit 1
+
+
+ # Run the project
+ make)
+
+ # Make sure the configure script has been completed properly
+ # (`configuration-done.txt' exists).
+ if ! [ -f .build/software/preparation-done.txt ]; then
+ print_error_abort $operation
fi
- # Get the full address of the build directory:
- bdir=`.local/bin/realpath .build`
+ # Run the actual project.
+ controlled_env reproduce/analysis/make/top-make.mk
+ ;;
- # Remove all existing environment variables (with `env -i') and
- # only use some pre-defined environment variables, then build the
- # project.
- envmake=".local/bin/env -i HOME=$bdir sys_rm=$(which rm) $gopt"
- envmake="$envmake .local/bin/make -f reproduce/analysis/make/top.mk"
- if ! [ x"$debug" = x ]; then envmake="$envmake --debug=$debug"; fi
- # Set the number of jobs. Note that for the `configure.sh' script
- # the default value has to be 0, so the default is the maximum
- # number of threads. But here, the default value is 1.
- if ! [ x"$jobs" = x0 ]; then envmake="$envmake -j$jobs"; fi
- # Run the project
- if [ x"$group" = x ]; then
- $envmake $make_targets
- else
- # Set the group and permission flags.
- sg "$group" "umask $perms && $envmake $make_targets"
- fi
- ;;
# Operation not specified.
*)
- echo "No operation defined (you can give 'configure' or 'make')."
+ echo "No operation defined."
+ echo "Please run with '--help' for more information."
+ echo "Available operations are: 'configure', 'prepare', or 'make')."
exit 1
;;
esac