use Cwd 'abs_path';
use File::Basename;
$branch=$ARGV[0];
$ENV{'PATH'} = $ENV{'PATH'}.':/usr/lib64/qt4/bin/:/opt/casa/02/bin/';
print("$ENV{'PATH'}\n");
$scriptdir=dirname(abs_path($0));
print("Script location: $scriptdir\n");
print("Branch: $branch\n");
print("Cloning ALMAtasks\n");
system"git clone -q --recursive https://open-bitbucket.nrao.edu/scm/casa/ALMAtasks.git";
$srcdir = "$scriptdir/ALMAtasks";
print("Checking out branch $branch");
system("cd $srcdir && git checkout $branch && git submodule update --init --recursive");
$build_cfg = $srcdir.'/build.conf';
$pip_casatasks eq "";
if (-e $build_cfg) {
open(CONF,$build_cfg) or die("unable to open build.conf");
foreach (<CONF>) {
if($_ =~ /casatasks/ && $pip_casatasks eq "") { print("casatasks from build.conf: $_"); chomp($_); $pip_casatasks = $_; }
}
}
if ($pip_casatasks eq ""){ $pip_casatasks = "casatasks";}
print("Installing casatasks\n");
system "pip3 install $pip_casatasks";
print("Checking for casatools\n");
$hasCasatools = `python3 -m casatools --grpc-protopy`;
print("Casatools status: $hasCasatools\n");
print("Creating wheel\n");
system("cd $scriptdir/ALMAtasks && python3 setup.py bdist_wheel");
print("Audit wheel\n");
system("cd $scriptdir/ALMAtasks/dist/ && auditwheel repair *.whl");
print("Copying wheel to /wheeldirectory");
system("cp `find . -name *manylinux*.whl` /wheeldirectory/");