Skip to content

Commit 3336cd2

Browse files
author
Damian Rouson
authored
Merge pull request #357 from sourceryinstitute/capture-build-workflow
Add install features; Adapt to GCC 7 build system
2 parents 71dbee0 + 4447a46 commit 3336cd2

File tree

7 files changed

+325
-53
lines changed

7 files changed

+325
-53
lines changed
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
#!/usr/bin/env bash
2+
3+
### Diagnostics ###
4+
5+
# Print usage information and exit if this script was invoked with no arugments or with -h or --help
6+
# as the first argument or in a location other than the top-level OpenCoarrays source directory
7+
function usage()
8+
{
9+
echo "Usage:"
10+
echo " cd <opencoarrays-source-directory>"
11+
echo " ./developer_scripts/patched-trunk-install.sh <patch-file>"
12+
exit 1
13+
}
14+
[[ $# -eq 0 || "${1}" == "-h" || "${1}" == "--help" || ! -f src/libcaf.h ]] && usage
15+
16+
patch_file="${1}"
17+
18+
function set_absolute_path()
19+
{
20+
: "${1?'set_absolute_path: no argument provided'}"
21+
22+
arg=${1}
23+
first_character=$(echo "${arg}" | cut -c1-1)
24+
if [[ "${first_character}" == "/" ]]; then
25+
absolute_path="${arg}"
26+
else
27+
absolute_path="${PWD%%/}/${arg}"
28+
fi
29+
}
30+
set_absolute_path "${patch_file}"
31+
32+
# Exit on error or use of an unset variable:
33+
set -o errexit
34+
set -o nounset
35+
36+
# Return the highest exit code in a chain of pipes:
37+
set -o pipefail
38+
39+
### Define functions
40+
function choose_package_manager()
41+
{
42+
OS=$(uname)
43+
case "${OS}" in
44+
45+
"Darwin" )
46+
if type brew >& /dev/null; then
47+
package_manager="brew"
48+
elif type port >& /dev/null; then
49+
package_manager="port"
50+
fi
51+
;;
52+
53+
"Linux" )
54+
if [[ ! -f /etc/lsb-release ]]; then
55+
echo "I don't recognize this Linux distribution. Possibly it's too old to have the expected /etc/lsb-release file."
56+
exit 1
57+
fi
58+
. /etc/lsb-release
59+
60+
case "${DISTRIB_ID:-}" in
61+
"Ubuntu" )
62+
package_manager="apt-get"
63+
;;
64+
"Debian" )
65+
package_manager="dnf"
66+
;;
67+
*)
68+
echo "I don't recognize the Linux distribution ${DISTRIB_ID:-}"
69+
exit 1
70+
;;
71+
esac
72+
;;
73+
74+
*)
75+
echo "I don't recognize the operating system \${OS}"
76+
exit 1
77+
;;
78+
esac
79+
}
80+
choose_package_manager
81+
82+
### Install any missing prerequisite packages and executable programs ###
83+
84+
### First install the packages for which package management suffices:
85+
function install_if_missing()
86+
{
87+
# Exit with error message if no first argument:
88+
: "${1?'\n ERROR: install_if_missing function requires a package name as the first argument.'}"
89+
90+
package="${1}" # Interpret the 1st argument as the package name
91+
executable="${2:-${1}}" # Interpret the 2nd argument as the prerequisite executable program (Default = 1st argument)
92+
93+
printf "Checking whether ${executable} is in path... "
94+
95+
if type ${executable} >& /dev/null; then
96+
97+
printf "yes.\n"
98+
99+
else # install package
100+
101+
printf "no\n"
102+
echo "sudo ${package_manager} install ${package}"
103+
sudo "${package_manager}" install ${package}
104+
105+
fi
106+
}
107+
108+
# Install subversion to check out the GCC trunk if not already in the PATH:
109+
install_if_missing subversion svn
110+
111+
# Install released versions of the GNU compilers if not already in the PATH:
112+
install_if_missing gfortran
113+
install_if_missing g++
114+
115+
# Install build software:
116+
install_if_missing cmake
117+
install_if_missing make
118+
install_if_missing flex
119+
120+
### Install the prerequisites that must be built from source ###
121+
122+
# Download and build the GCC trunk:
123+
echo "Downloading the GCC trunk."
124+
./install.sh --only-download --package gcc --install-branch trunk
125+
126+
# Patch the GCC trunk and rebuild
127+
echo "Patching the GCC source using ${absolute_path}."
128+
pushd prerequisites/downloads/trunk
129+
patch -p0 < "${absolute_path}"
130+
popd
131+
132+
# Build the patched GCC trunk
133+
echo "Rebuilding the patched GCC source."
134+
./install.sh --package gcc --install-branch trunk --yes-to-all
135+
136+
# Verify that GCC installed in the expected path
137+
patched_GCC_install_path=${PWD}/prerequisites/installations/gcc/trunk
138+
if ! type "${patched_GCC_install_path}"/bin/gfortran >& /dev/null; then
139+
echo "gfortran is not installed in the expected location ${patched_GCC_install_path}."
140+
exit 1
141+
fi
142+
143+
# Ensure that the just-installed GCC libraries are used when linking
144+
echo "Setting and exporting LD_LIBRARY_PATH"
145+
146+
function prepend_to_LD_LIBRARY_PATH() {
147+
: ${1?'set_LD_LIBRARY_PATH: missing path'}
148+
new_path="${1}"
149+
if [[ -z "${LD_LIBRARY_PATH:-}" ]]; then
150+
export LD_LIBRARY_PATH="${new_path}"
151+
else
152+
export LD_LIBRARY_PATH="${new_path}:${LD_LIBRARY_PATH}"
153+
fi
154+
}
155+
156+
old_path="${LD_LIBRARY_PATH:-}"
157+
158+
if [[ -d "${PWD}/prerequisites/installations/gcc/trunk/lib" ]]; then
159+
prepend_to_LD_LIBRARY_PATH "${patched_GCC_install_path}/lib/"
160+
fi
161+
162+
if [[ -d "${PWD}/prerequisites/installations/gcc/trunk/lib64" ]]; then
163+
prepend_to_LD_LIBRARY_PATH "${patched_GCC_install_path}/lib64/"
164+
fi
165+
166+
echo "\${LD_LIBRARY_PATH}=${LD_LIBRARY_PATH:=}"
167+
168+
if [[ "${LD_LIBRARY_PATH}" == "${old_path}" ]]; then
169+
echo "gfortran libraries did not install where expected: ${patched_GCC_install_path}/lib64 or ${patched_GCC_install_path}/lib"
170+
exit 1
171+
fi
172+
173+
# Build MPICH with the patched compilers.
174+
echo "Building MPICH with the patched compilers."
175+
./install.sh --package mpich --yes-to-all \
176+
--with-fortran "${patched_GCC_install_path}/bin/gfortran" \
177+
--with-c "${patched_GCC_install_path}/bin/gcc" \
178+
--with-cxx "${patched_GCC_install_path}/bin/g++"
179+
180+
# Verify that MPICH installed where expected
181+
mpich_install_path=$(./install.sh -P mpich)
182+
if ! type "${mpich_install_path}"/bin/mpif90; then
183+
echo "MPICH is not installed in the expected location ${mpich_install_path}."
184+
exit 1
185+
fi
186+
187+
# Build OpenCoarrays with the patched compilers and the just-built MPICH
188+
echo "Building OpenCoarrays with the patched compilers"
189+
# Build OpenCoarrays with the patched compiler:
190+
./install.sh --yes-to-all \
191+
--with-fortran "${patched_GCC_install_path}/bin/gfortran" \
192+
--with-c "${patched_GCC_install_path}/bin/gcc" \
193+
--with-cxx "${patched_GCC_install_path}/bin/g++" \
194+
--with-mpi "${mpich_install_path}"

install.sh

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ info "-l (--list-packages): ${arg_l}"
161161
info "-m (--with-cmake): ${arg_m}"
162162
info "-M (--with-mpi): ${arg_M}"
163163
info "-n (--no-color): ${arg_n}"
164+
info "-o (--only-download): ${arg_o}"
164165
info "-p (--package): ${arg_p}"
165166
info "-P (--print-path): ${arg_P}"
166167
info "-U (--print-url): ${arg_U}"
@@ -287,19 +288,31 @@ elif [[ ! -z "${arg_D:-${arg_P:-${arg_U:-${arg_V:-${arg_B}}}}}" || "${arg_l}" =
287288
fi
288289

289290
elif [[ "${arg_p:-}" == "opencoarrays" ]]; then
291+
292+
if [[ "${arg_o}" == "${__flag_present}" ]]; then
293+
294+
# Download all prerequisites and exit
295+
info "source ${OPENCOARRAYS_SRC_DIR}/prerequisites/install-functions/download-all-prerequisites.sh"
296+
source "${OPENCOARRAYS_SRC_DIR}/prerequisites/install-functions/download-all-prerequisites.sh"
297+
info "download_all_prerequisites"
298+
download_all_prerequisites
299+
300+
else
301+
302+
# Install OpenCoarrays
303+
cd prerequisites || exit 1
304+
installation_record=install-opencoarrays.log
305+
# shellcheck source=./prerequisites/build-functions/set_SUDO_if_needed_to_write_to_directory.sh
306+
source "${OPENCOARRAYS_SRC_DIR:-}/prerequisites/build-functions/set_SUDO_if_needed_to_write_to_directory.sh"
307+
version="$("${opencoarrays_src_dir}/install.sh" -V opencoarrays)"
308+
set_SUDO_if_needed_to_write_to_directory "${install_path}"
290309

291-
cd prerequisites || exit 1
292-
installation_record=install-opencoarrays.log
293-
# shellcheck source=./prerequisites/build-functions/set_SUDO_if_needed_to_write_to_directory.sh
294-
source "${OPENCOARRAYS_SRC_DIR:-}/prerequisites/build-functions/set_SUDO_if_needed_to_write_to_directory.sh"
295-
version="$("${opencoarrays_src_dir}/install.sh" -V opencoarrays)"
296-
set_SUDO_if_needed_to_write_to_directory "${install_path}"
297-
298-
# Using process substitution "> >(...) -" instead of piping to tee via "2>&1 |" ensures that
299-
# report_results gets the FC value set in build_opencoarrays
300-
# Source: http://stackoverflow.com/questions/8221227/bash-variable-losing-its-value-strange
301-
build_opencoarrays > >( tee ../"${installation_record}" ) -
302-
report_results 2>&1 | tee -a ../"${installation_record}"
310+
# Using process substitution "> >(...) -" instead of piping to tee via "2>&1 |" ensures that
311+
# report_results gets the FC value set in build_opencoarrays
312+
# Source: http://stackoverflow.com/questions/8221227/bash-variable-losing-its-value-strange
313+
build_opencoarrays > >( tee ../"${installation_record}" ) -
314+
report_results 2>&1 | tee -a ../"${installation_record}"
315+
fi
303316

304317
elif [[ "${arg_p:-}" == "ofp" ]]; then
305318

@@ -315,4 +328,3 @@ elif [[ ! -z "${arg_p:-}" ]]; then
315328

316329
fi
317330
# ____________________________________ End of Main Body ____________________________________________
318-

install.sh-usage

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
-b --install-branch [arg] Install the specified repository development branch.
22
-B --list-branches [arg] List the available branches in the specified package's repository.
3-
-c --with-c [arg] Use specified C compiler.
4-
-C --with-cxx [arg] Use specified C++ compiler.
3+
-c --with-c [arg] Use specified C compiler.
4+
-C --with-cxx [arg] Use specified C++ compiler.
55
-d --debug Enable debug mode.
66
-D --print-downloader [arg] Print download program for package specified in argument.
77
-e --verbose Enable verbose mode, print script as it is executed.
8-
-f --with-fortran [arg] Use specified Fortran compiler.
8+
-f --with-fortran [arg] Use specified Fortran compiler.
99
-h --help Print this page.
1010
-i --install-prefix [arg] Install package in specified path. Default="${OPENCOARRAYS_SRC_DIR}/prerequisites/installations/${package_name:-}/${version_to_build:-}"
1111
-I --install-version [arg] Install package version.
@@ -14,6 +14,7 @@
1414
-m --with-cmake [arg] Use specified CMake installation. Default="cmake"
1515
-M --with-mpi [arg] Use specified MPI installation.
1616
-n --no-color Disable color output.
17+
-o --only-download Download (without building) the source for the package specified by -p or --package.
1718
-p --package [arg] Install specified package. Default="opencoarrays"
1819
-P --print-path [arg] Print installation directory for specified package.
1920
-U --print-url [arg] Print download location for specified package.

0 commit comments

Comments
 (0)