use Cwd 'abs_path';
use File::Basename;
$branch=$ARGV[0];
$path = $ENV{'PATH'};
$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");
$ENV{'PATH'} = '/usr/lib64/ccache:/opt/python/cp36-cp36m/bin:/opt/rh/devtoolset-4/root/usr/bin:/opt/rh/devtoolset-8/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin';
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");