Skip to content

Commit

Permalink
Add "install-prerequisites" option to installation script
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Cooke committed Dec 17, 2018
1 parent 38bb61d commit 81c6535
Showing 1 changed file with 124 additions and 15 deletions.
139 changes: 124 additions & 15 deletions scripts/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,82 @@
forest_url_base = os.path.join(google_cloud_octopus_base, "forests")
forests = ['germline', 'somatic']

latest_llvm = 'llvm'
latest_gcc = 'gcc@8'

def get_octopus_version():
return "0.5.2-beta"

def is_unix():
system = platform.system()
return system == "Darwin" or system == "Linux"

def is_osx():
return platform.system() == "Darwin"

def download_file(url, file_name):
urllib.request.urlretrieve(url, file_name)

def git_clone(project):
call(['git', 'clone', project])

def get_homebrew_name():
if is_osx():
return 'homebrew'
else:
return 'brew'

def download_homebrew():
if is_osx():
git_clone('https://github.com/mxcl/homebrew.git')
else:
git_clone('https://github.com/Linuxbrew/brew.git')

def install_homebrew():
homebrew = get_homebrew_name()
if not os.path.exists(homebrew):
download_homebrew()
brew_bin = homebrew + '/bin/brew'
call([brew_bin, 'update'])
return brew_bin

def get_required_prerequisites():
result = ['cmake']
if is_osx():
result.append(latest_llvm)
else:
result.append(latest_gcc)
result += ['boost', 'htslib']
return result

def get_brewed_compiler_binaries(homebrew_dir):
cellar_dir = os.path.join(homebrew_dir, 'Cellar')
if is_osx():
llvm_dir = os.path.join(cellar_dir, latest_llvm)
llvm_version = os.listdir(llvm_dir)[0]
llvm_bin_dir = os.path.join(llvm_dir, os.path.join(llvm_version, 'bin'))
return os.path.join(llvm_bin_dir, 'clang'), os.path.join(llvm_bin_dir, 'clang++')
else:
gcc_dir = os.path.join(cellar_dir, latest_gcc)
gcc_version = os.listdir(gcc_dir)[0]
gcc_bin_dir = os.path.join(gcc_dir, os.path.join(gcc_version, 'bin'))
gcc_bin_name = latest_gcc.replace('@', '-')
gxx_bin_name = gcc_bin_name.replace('cc', '++')
return os.path.join(gcc_bin_dir, gcc_bin_name), os.path.join(gcc_bin_dir, gxx_bin_name)

def install_prerequisites(build_dir):
brew_bin = install_homebrew()
prerequisites = get_required_prerequisites()
brew_command = [brew_bin, 'install'] + prerequisites
if call(brew_command) == 0:
prerequisites_dir = os.path.join(build_dir, get_homebrew_name())
cc, cxx = get_brewed_compiler_binaries(prerequisites_dir)
binaries = {'cmake': os.path.join(prerequisites_dir, 'bin/cmake'),
'c_compiler': cc, 'cxx_compiler': cxx}
return prerequisites_dir, binaries
else:
return None, None

def download_forests(forest_dir, version):
if not os.path.exists(forest_dir):
print("No forest directory found, making one")
Expand Down Expand Up @@ -75,13 +141,13 @@ def main(args):
if not args["keep_cache"] and os.path.exists(cmake_cache_file):
os.remove(cmake_cache_file)

prerequisites_dir, prerequisites_binaries = None, None
if args["install_prerequisites"]:
prerequisites_dir, prerequisites_binaries = install_prerequisites(octopus_build_dir)

cmake_options = []
if args["prefix"]:
cmake_options.append("-DCMAKE_INSTALL_PREFIX=" + args["prefix"])
if args["c_compiler"]:
cmake_options.append("-DCMAKE_C_COMPILER=" + args["c_compiler"])
if args["cxx_compiler"]:
cmake_options.append("-DCMAKE_CXX_COMPILER=" + args["cxx_compiler"])
if args["debug"]:
cmake_options.append("-DCMAKE_BUILD_TYPE=Debug")
elif args["sanitize"]:
Expand All @@ -90,18 +156,51 @@ def main(args):
cmake_options.append("-DCMAKE_BUILD_TYPE=Release")
if args["static"]:
cmake_options.append("-DBUILD_SHARED_LIBS=OFF")
if args["boost"]:
cmake_options.append("-DBOOST_ROOT=" + args["boost"])
if args["htslib"]:
cmake_options.append("-DHTSLIB_ROOT=" + args["htslib"])
if args["verbose"]:
cmake_options.append("CMAKE_VERBOSE_MAKEFILE:BOOL=ON")
if prerequisites_dir is not None:
if args["c_compiler"]:
cmake_options.append("-DCMAKE_C_COMPILER=" + args["c_compiler"])
else:
cmake_options.append("-DCMAKE_C_COMPILER=" + prerequisites_binaries["c_compiler"])
if args["cxx_compiler"]:
cmake_options.append("-DCMAKE_CXX_COMPILER=" + args["cxx_compiler"])
else:
cmake_options.append("-DCMAKE_CXX_COMPILER=" + prerequisites_binaries["cxx_compiler"])
if args["boost"]:
cmake_options.append("-DBOOST_ROOT=" + args["boost"])
cmake_options.append("-DBoost_NO_BOOST_CMAKE=TRUE")
cmake_options.append("-DBoost_NO_SYSTEM_PATHS=TRUE")
else:
cmake_options.append("-DBOOST_ROOT=" + prerequisites_dir)
cmake_options.append("-DBoost_NO_BOOST_CMAKE=TRUE")
cmake_options.append("-DBoost_NO_SYSTEM_PATHS=TRUE")
if args["htslib"]:
cmake_options.append("-DHTSLIB_ROOT=" + args["htslib"])
cmake_options.append("-DHTSlib_NO_SYSTEM_PATHS=TRUE")
else:
cmake_options.append("-DHTSLIB_ROOT=" + prerequisites_dir)
cmake_options.append("-DHTSlib_NO_SYSTEM_PATHS=TRUE")

ret = call([prerequisites_binaries['cmake']] + cmake_options + [".."])
else:
if args["c_compiler"]:
cmake_options.append("-DCMAKE_C_COMPILER=" + args["c_compiler"])
if args["cxx_compiler"]:
cmake_options.append("-DCMAKE_CXX_COMPILER=" + args["cxx_compiler"])
if args["boost"]:
cmake_options.append("-DBOOST_ROOT=" + args["boost"])
cmake_options.append("-DBoost_NO_BOOST_CMAKE=TRUE")
cmake_options.append("-DBoost_NO_SYSTEM_PATHS=TRUE")
if args["htslib"]:
cmake_options.append("-DHTSLIB_ROOT=" + args["htslib"])
cmake_options.append("-DHTSlib_NO_SYSTEM_PATHS=TRUE")

try:
# CMake version 3 is called cmake3 in CentOS (see https://github.com/luntergroup/octopus/issues/37).
ret = call(["cmake3"] + cmake_options + [".."])
except FileNotFoundError:
ret = call(["cmake"] + cmake_options + [".."])
try:
# CMake version 3 is called cmake3 in CentOS (see https://github.com/luntergroup/octopus/issues/37).
ret = call(["cmake3"] + cmake_options + [".."])
except FileNotFoundError:
ret = call(["cmake"] + cmake_options + [".."])

if ret == 0:
make_options = []
Expand Down Expand Up @@ -129,7 +228,12 @@ def main(args):
required=False,
type=str,
help='Install into given location')
parser.add_argument('--install-prerequisites',
default=False,
help='Install all prerequisites locally into build directory',
action='store_true')
parser.add_argument('--clean',
default=False,
help='Do a clean install',
action='store_true')
parser.add_argument('-c', '--c_compiler',
Expand All @@ -141,15 +245,19 @@ def main(args):
type=str,
help='C++ compiler path to use')
parser.add_argument('--keep_cache',
default=False,
help='Do not refresh CMake cache',
action='store_true')
parser.add_argument('--debug',
default=False,
help='Builds in debug mode',
action='store_true')
parser.add_argument('--sanitize',
default=False,
help='Builds in release mode with sanitize flags',
action='store_true')
parser.add_argument('--static',
default=False,
help='Builds using static libraries',
action='store_true')
parser.add_argument('--threads',
Expand All @@ -164,10 +272,11 @@ def main(args):
type=str,
help='The HTSlib library root')
parser.add_argument('--download',
required=False,
help='Try to download octopus classifiers',
default=False,
help='Try to download pre-trained random forests for filtering',
action='store_true')
parser.add_argument('--verbose',
default=False,
help='Ouput verbose make information',
action='store_true')
args = vars(parser.parse_args())
Expand Down

0 comments on commit 81c6535

Please sign in to comment.