

def safe_classpath(classpath, synthetic_jar_dir, custom_name=None):
    'Bundles classpath into one synthetic jar that includes original classpath in its manifest.\n\n  This is to ensure classpath length never exceeds platform ARG_MAX.\n\n  :param list classpath: Classpath to be bundled.\n  :param string synthetic_jar_dir: directory to store the synthetic jar, if `None`\n    a temp directory will be provided and cleaned up upon process exit. Otherwise synthetic\n    jar will remain in the supplied directory, only for debugging purpose.\n  :param custom_name: filename of the synthetic jar to be created.\n\n  :returns: A classpath (singleton list with just the synthetic jar).\n  :rtype: list of strings\n  '
    if synthetic_jar_dir:
        safe_mkdir(synthetic_jar_dir)
    else:
        synthetic_jar_dir = safe_mkdtemp()
    bundled_classpath = relativize_classpath(classpath, synthetic_jar_dir)
    manifest = Manifest()
    manifest.addentry(Manifest.CLASS_PATH, ' '.join(bundled_classpath))
    with temporary_file(root_dir=synthetic_jar_dir, cleanup=False, suffix='.jar') as jar_file:
        with open_zip(jar_file, mode='w', compression=ZIP_STORED) as jar:
            jar.writestr(Manifest.PATH, manifest.contents())
        if custom_name:
            custom_path = os.path.join(synthetic_jar_dir, custom_name)
            safe_concurrent_rename(jar_file.name, custom_path)
            return [custom_path]
        else:
            return [jar_file.name]

dataset/ETHPy150Open pantsbuild/pants/src/python/pants/java/util.py safe_classpath/original