Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def mkdir(self, *args):
p = os.path.join(self.tmp_dir, *args)
cget.util.mkdir(p)
return DirForTests(p)
def test_symlink_in_prefix(d):
p = d.get_path('usr')
if cget.util.USE_SYMLINKS:
cget.util.mkdir(os.path.join(p, 'share', 'man'))
os.symlink(os.path.join(p, 'share', 'man'), os.path.join(p, 'man'))
d.cmds(install_cmds(url=get_exists_path('libsimple'), lib='simple', prefix=p))
def test_rm_with_symlink(d):
p = d.get_path('usr')
share = os.path.join(p, 'share')
cget.util.mkfile(share, 'data.txt', 'data')
if cget.util.USE_SYMLINKS:
os.symlink(os.path.join(share, 'data.txt'), os.path.join(share, 'data.sym'))
else:
cget.util.mkfile(share, 'data.sym', 'data')
os.remove(os.path.join(share, 'data.txt'))
cg = CGetCmd(prefix=p)
d.cmds([
cg('install', '--verbose --test', 'simple,'+get_exists_path('libsimple')),
cg('size', '1'),
cg('rm', '--verbose -y', 'simple'),
cg('size', '0')
])
assert os.path.exists(os.path.join(share))
assert not os.path.exists(os.path.join(share, 'data.txt'))
assert os.path.lexists(os.path.join(share, 'data.sym'))
def test_rm_with_symlink(d):
p = d.get_path('usr')
share = os.path.join(p, 'share')
cget.util.mkfile(share, 'data.txt', 'data')
if cget.util.USE_SYMLINKS:
os.symlink(os.path.join(share, 'data.txt'), os.path.join(share, 'data.sym'))
else:
cget.util.mkfile(share, 'data.sym', 'data')
os.remove(os.path.join(share, 'data.txt'))
cg = CGetCmd(prefix=p)
d.cmds([
cg('install', '--verbose --test', 'simple,'+get_exists_path('libsimple')),
cg('size', '1'),
cg('rm', '--verbose -y', 'simple'),
cg('size', '0')
])
assert os.path.exists(os.path.join(share))
assert not os.path.exists(os.path.join(share, 'data.txt'))
assert os.path.lexists(os.path.join(share, 'data.sym'))
def init_command(prefix, toolchain, cc, cxx, cflags, cxxflags, ldflags, std, define, shared, static):
""" Initialize install directory """
if shared and static:
click.echo("ERROR: shared and static are not supported together")
sys.exit(1)
defines = util.to_define_dict(define)
if shared: defines['BUILD_SHARED_LIBS'] = 'On'
if static: defines['BUILD_SHARED_LIBS'] = 'Off'
prefix.write_cmake(
always_write=True,
toolchain=toolchain,
cc=cc,
cxx=cxx,
cflags=cflags,
cxxflags=cxxflags,
ldflags=ldflags,
std=std,
defines=defines)
def which(p, paths=None, throws=True):
exes = [p+x for x in ['', '.exe', '.bat']]
for dirname in list(paths or [])+os.environ['PATH'].split(os.pathsep):
for exe in exes:
candidate = os.path.join(os.path.expanduser(dirname), exe)
if os.path.isfile(candidate):
return candidate
if throws: raise BuildError("Can't find file %s" % p)
else: return None
@params(pb=PACKAGE_SOURCE_TYPES, test=bool)
def build(self, pb, test=False, target=None, generator=None):
pb = self.parse_pkg_build(pb)
src_dir = pb.pkg_src.get_src_dir()
with self.create_builder(pb.to_fname()) as builder:
# Install any dependencies first
self.install_deps(pb, src_dir, generator=generator, test=test)
# Configure and build
if not builder.exists: builder.configure(src_dir, defines=pb.define, generator=generator)
builder.build(variant='Release', target=target)
# Run tests if enabled
if test: builder.test(variant='Release')
self.install_deps(pb, src_dir, test=test, test_all=test_all, generator=generator, insecure=insecure)
# Setup cmake file
if pb.cmake:
target = os.path.join(src_dir, 'CMakeLists.txt')
if os.path.exists(target):
os.rename(target, os.path.join(src_dir, builder.cmake_original_file))
shutil.copyfile(pb.cmake, target)
# Configure and build
builder.configure(src_dir, defines=pb.define, generator=generator, install_prefix=install_dir, test=test, variant=pb.variant)
builder.build(variant=pb.variant)
# Run tests if enabled
if test or test_all: builder.test(variant=pb.variant)
# Install
builder.build(target='install', variant=pb.variant)
if util.USE_SYMLINKS: util.symlink_dir(install_dir, self.prefix)
else: util.copy_dir(install_dir, self.prefix)
self.write_parent(pb, track=track)
return "Successfully installed {}".format(pb.to_name())
# Install any dependencies first
self.install_deps(pb, src_dir, test=test, test_all=test_all, generator=generator, insecure=insecure)
# Setup cmake file
if pb.cmake:
target = os.path.join(src_dir, 'CMakeLists.txt')
if os.path.exists(target):
os.rename(target, os.path.join(src_dir, builder.cmake_original_file))
shutil.copyfile(pb.cmake, target)
# Configure and build
builder.configure(src_dir, defines=pb.define, generator=generator, install_prefix=install_dir, test=test, variant=pb.variant)
builder.build(variant=pb.variant)
# Run tests if enabled
if test or test_all: builder.test(variant=pb.variant)
# Install
builder.build(target='install', variant=pb.variant)
if util.USE_SYMLINKS: util.symlink_dir(install_dir, self.prefix)
else: util.copy_dir(install_dir, self.prefix)
self.write_parent(pb, track=track)
return "Successfully installed {}".format(pb.to_name())
def from_file(self, file, url=None, no_recipe=False):
if file is not None and os.path.exists(file):
start = os.path.dirname(file)
if url is not None and url.startswith('file://'):
start = url[7:]
with open(file) as f:
for line in f.readlines():
tokens = shlex.split(line, comments=True)
if len(tokens) > 0:
yield self.parse_pkg_build(parse_pkg_build_tokens(tokens), start=start, no_recipe=no_recipe)