def test_fix_object_code_with_targets(self): """ Test we handle the targets.dat hack correctly in fix_object_code. Some of our eggs use /PLACEHOLD in the LC_LOAD_DYLIB command (i.e. inside the dependency names). Those are rewritten by finding the dependency in the installed egg first. We're ensuring here that those are also rewritten correctly. """ # targets.dat hack is handled in the function that expects an egg, but # we don't want to deal with an egg. Instead, we emulate the # targets.dat hack by patching object_code._targets with mock pyext_dependency_dir = os.path.join("lib", "foo-4.2") installed_pyext_dependency = os.path.join( self.prefix, pyext_dependency_dir, os.path.basename(PYEXT_DEPENDENCY)) installed_pyext_dependency_dir = os.path.dirname( installed_pyext_dependency) targets = [self.prefix, installed_pyext_dependency_dir] installed_pyext = os.path.join( self.prefix, os.path.basename(PYEXT_WITH_LEGACY_PLACEHOLD_DEPENDENCY)) shutil.copy(PYEXT_WITH_LEGACY_PLACEHOLD_DEPENDENCY, installed_pyext) os.makedirs(installed_pyext_dependency_dir) shutil.copy(PYEXT_DEPENDENCY, installed_pyext_dependency_dir) _fix_object_code(installed_pyext, targets) deps = set(rewriter_factory(installed_pyext).dependencies) self.assertTrue(installed_pyext_dependency in deps)
def test_fix_object_code_with_targets(self): """ Test we handle the targets.dat hack correctly in fix_object_code. Some of our eggs use /PLACEHOLD in the LC_LOAD_DYLIB command (i.e. inside the dependency names). Those are rewritten by finding the dependency in the installed egg first. We're ensuring here that those are also rewritten correctly. """ # targets.dat hack is handled in the function that expects an egg, but # we don't want to deal with an egg. Instead, we emulate the # targets.dat hack by patching object_code._targets with mock pyext_dependency_dir = os.path.join("lib", "foo-4.2") installed_pyext_dependency = os.path.join(self.prefix, pyext_dependency_dir, os.path.basename(PYEXT_DEPENDENCY)) installed_pyext_dependency_dir = os.path.dirname(installed_pyext_dependency) targets = [self.prefix, installed_pyext_dependency_dir] installed_pyext = os.path.join(self.prefix, os.path.basename(PYEXT_WITH_LEGACY_PLACEHOLD_DEPENDENCY)) shutil.copy(PYEXT_WITH_LEGACY_PLACEHOLD_DEPENDENCY, installed_pyext) os.makedirs(installed_pyext_dependency_dir) shutil.copy(PYEXT_DEPENDENCY, installed_pyext_dependency_dir) _fix_object_code(installed_pyext, targets) deps = set(rewriter_factory(installed_pyext).dependencies) self.assertTrue(installed_pyext_dependency in deps)
def test_fix_object_code_legacy_macho(self): """ Test that we handle correctly our legacy egg with the /PLACHOLD * 20 hack. """ copy = os.path.join(self.prefix, "foo.dylib") shutil.copy(LEGACY_PLACEHOLD_FILE_RPATH, copy) _fix_object_code(copy, [self.prefix]) rpaths = rewriter_factory(copy).rpaths self.assertEqual(rpaths, [self.prefix])
def list_load_entries(filepath): """ Return load entry dict for the given filepath. :param filepath: file to get rpaths from """ try: rewriter = rewriter_factory(filepath) dynamic_deps = [dep[6:] for dep in rewriter.dependencies if dep.startswith('@rpath')] return {'rpaths': rewriter.rpaths, 'libraries': dynamic_deps} except MachoError: return {'rpaths': [], 'libraries': []}
def test_legacy_placehold_lib(self): with mkdtemp() as d: new_rpaths = ["@loader_path/..", "dummy"] copy = op.join(d, op.basename(LEGACY_PLACEHOLD_FILE)) shutil.copy(LEGACY_PLACEHOLD_FILE, copy) macho_add_rpaths_to_file(copy, new_rpaths) rpaths = rewriter_factory(copy).rpaths self.assertEqual(rpaths, new_rpaths)
def test_fix_object_code_wo_legacy_macho(self): """ Test that we handle correctly egg *without* the /PLACHOLD (i.e. we don't touch them). """ r_rpaths = FILE_TO_RPATHS[NOLEGACY_RPATH_FILE] copy = os.path.join(self.prefix, "foo.dylib") shutil.copy(NOLEGACY_RPATH_FILE, copy) _fix_object_code(copy, self.prefix) rpaths = rewriter_factory(copy).rpaths self.assertEqual(rpaths, r_rpaths)
def test_fix_object_code_legacy_macho(self): """ Test that we handle correctly our legacy egg with the /PLACHOLD * 20 hack. """ with mkdtemp() as d: copy = op.join(d, "foo.dylib") shutil.copy(LEGACY_PLACEHOLD_FILE, copy) with mock.patch("egginst.object_code._targets", [d]): fix_object_code(copy) rpaths = rewriter_factory(copy).rpaths self.assertEqual(rpaths, [d])
def test_fix_object_code_wo_legacy_macho(self): """ Test that we handle correctly egg *without* the /PLACHOLD (i.e. we don't touch them). """ r_rpaths = FILE_TO_RPATHS[NOLEGACY_RPATH_FILE] with mkdtemp() as d: copy = op.join(d, "foo.dylib") shutil.copy(NOLEGACY_RPATH_FILE, copy) with mock.patch("egginst.object_code._targets", [d]): fix_object_code(copy) rpaths = rewriter_factory(copy).rpaths self.assertEqual(rpaths, r_rpaths)