def test_install_sbang_too_long(tmpdir): root = str(tmpdir) num_extend = sbang.system_shebang_limit - len(root) - len('/bin/sbang') long_path = root while num_extend > 1: add = min(num_extend, 255) long_path = os.path.join(long_path, 'e' * add) num_extend -= add with spack.store.use_store(spack.store.Store(long_path)): with pytest.raises(sbang.SbangPathError) as exc_info: sbang.sbang_install_path() err = str(exc_info.value) assert 'root is too long' in err assert 'exceeds limit' in err assert 'cannot patch' in err
def check_sbang_installation(): sbang_path = sbang.sbang_install_path() sbang_bin_dir = os.path.dirname(sbang_path) assert sbang_path.startswith(spack.store.store.unpadded_root) assert os.path.exists(sbang_path) assert fs.is_exe(sbang_path) status = os.stat(sbang_path) assert (status.st_mode & 0o777) == 0o755 status = os.stat(sbang_bin_dir) assert (status.st_mode & 0o777) == 0o755
def patch(self): """ phar sbang is added before build phase. Because phar is php script with binary data (Not UTF-8 text file) And phar is embeded own sha1 checksum. """ shebang_limit = 127 if len(self.prefix.bin.php) + 2 <= shebang_limit: return new_sbang_line = '#!/bin/bash %s' % sbang.sbang_install_path() original_bang = '-b "$(PHP_PHARCMD_BANG)"' makefile = join_path('ext', 'phar', 'Makefile.frag') filter_file( original_bang, original_bang + ' -z "{0}"'.format(new_sbang_line), makefile, string=True)
def test_install_sbang(install_mockery): sbang_path = sbang.sbang_install_path() sbang_bin_dir = os.path.dirname(sbang_path) assert sbang_path.startswith(spack.store.store.unpadded_root) assert not os.path.exists(sbang_bin_dir) sbang.install_sbang() check_sbang_installation() # put an invalid file in for sbang fs.mkdirp(sbang_bin_dir) with open(sbang_path, "w") as f: f.write("foo") sbang.install_sbang() check_sbang_installation() # install again and make sure sbang is still fine sbang.install_sbang() check_sbang_installation()
def check_sbang_installation(group=False): sbang_path = sbang.sbang_install_path() sbang_bin_dir = os.path.dirname(sbang_path) assert sbang_path.startswith(spack.store.store.unpadded_root) assert os.path.exists(sbang_path) assert fs.is_exe(sbang_path) status = os.stat(sbang_bin_dir) mode = (status.st_mode & 0o777) if group: assert mode == 0o775, 'Unexpected {0}'.format(oct(mode)) else: assert mode == 0o755, 'Unexpected {0}'.format(oct(mode)) status = os.stat(sbang_path) mode = (status.st_mode & 0o777) if group: assert mode == 0o775, 'Unexpected {0}'.format(oct(mode)) else: assert mode == 0o755, 'Unexpected {0}'.format(oct(mode))
def setup_build_environment(self, env): env.set('SPACK_SBANG', sbang.sbang_install_path())
def setup_build_environment(self, env): # Only needed for sbang.patch above if self.spec.satisfies('@:1.60'): env.set('SPACK_SBANG', sbang.sbang_install_path())