예제 #1
0
def _run_cache_scm(conanfile, scm_sources_folder, src_folder, output):
    """
    :param conanfile: recipe
    :param src_folder: sources folder in the cache, (Destination dir)
    :param scm_sources_folder: scm sources folder in the cache, where the scm sources were exported
    :param output: output
    :return:
    """
    scm_data = get_scm_data(conanfile)
    if not scm_data:
        return

    if scm_data.subfolder:
        dest_dir = os.path.normpath(
            os.path.join(src_folder, scm_data.subfolder))
    else:
        dest_dir = src_folder
    if os.path.exists(scm_sources_folder):
        output.info("Copying previously cached scm sources")
        merge_directories(scm_sources_folder, dest_dir)
    else:
        output.info("SCM: Getting sources from url: '%s'" % scm_data.url)
        try:
            scm = SCM(scm_data, dest_dir, output)
            scm.checkout()
        except Exception as e:
            raise ConanException("Couldn't checkout SCM: %s" % str(e))
        # This is a bit weird. Why after a SCM should we remove files.
        # Maybe check conan 2.0
        # TODO: Why removing in the cache? There is no danger.
        _clean_source_folder(dest_dir)
예제 #2
0
def _run_local_scm(conanfile, conanfile_folder, src_folder, output):
    """
    Only called when 'conan source' in user space
    :param conanfile: recipe
    :param src_folder: specified src_folder
    :param conanfile_folder: Folder containing the local conanfile
    :param output: Output
    :return:
    """

    scm_data = get_scm_data(conanfile)
    if not scm_data:
        return
    dest_dir = os.path.normpath(
        os.path.join(src_folder, scm_data.subfolder or ""))
    # In user space, if revision="auto", then copy
    if scm_data.capture_origin or scm_data.capture_revision:  # FIXME: or clause?
        scm = SCM(scm_data, conanfile_folder, output)
        scm_url = scm_data.url if scm_data.url != "auto" else \
            scm.get_qualified_remote_url(remove_credentials=True)

        src_path = scm.get_local_path_to_url(url=scm_url)
        if src_path and src_path != dest_dir:
            excluded = SCM(scm_data, src_path, output).excluded_files
            output.info("SCM: Getting sources from folder: %s" % src_path)
            merge_directories(src_path, dest_dir, excluded=excluded)
            return

    output.info("SCM: Getting sources from url: '%s'" % scm_data.url)
    scm = SCM(scm_data, dest_dir, output)
    scm.checkout()
예제 #3
0
파일: source.py 프로젝트: si-mikey/conan
def _run_scm(conanfile, src_folder, local_sources_path, output, cache):
    scm_data = get_scm_data(conanfile)
    if not scm_data:
        return

    dest_dir = os.path.normpath(os.path.join(src_folder, scm_data.subfolder))
    if cache:
        # When in cache, capturing the sources from user space is done only if exists
        if not local_sources_path or not os.path.exists(local_sources_path):
            local_sources_path = None
    else:
        # In user space, if revision="auto", then copy
        if scm_data.capture_origin or scm_data.capture_revision:  # FIXME: or clause?
            scm = SCM(scm_data, local_sources_path, output)
            scm_url = scm_data.url if scm_data.url != "auto" else \
                scm.get_qualified_remote_url(remove_credentials=True)

            src_path = scm.get_local_path_to_url(url=scm_url)
            if src_path:
                local_sources_path = src_path
        else:
            local_sources_path = None

    if local_sources_path and conanfile.develop:
        excluded = SCM(scm_data, local_sources_path, output).excluded_files
        output.info("Getting sources from folder: %s" % local_sources_path)
        merge_directories(local_sources_path, dest_dir, excluded=excluded)
    else:
        output.info("Getting sources from url: '%s'" % scm_data.url)
        scm = SCM(scm_data, dest_dir, output)
        scm.checkout()

    if cache:
        # This is a bit weird. Why after a SCM should we remove files. Maybe check conan 2.0
        _clean_source_folder(dest_dir)
예제 #4
0
def _run_scm(conanfile, src_folder, local_sources_path, output, cache):
    scm_data = get_scm_data(conanfile)
    if not scm_data:
        return

    dest_dir = os.path.normpath(os.path.join(src_folder, scm_data.subfolder))
    if cache:
        # When in cache, capturing the sources from user space is done only if exists
        captured = local_sources_path and os.path.exists(local_sources_path)
    else:
        # In user space, if revision="auto", then copy
        captured = scm_data.capture_origin or scm_data.capture_revision
    local_sources_path = local_sources_path if captured else None

    if local_sources_path:
        excluded = SCM(scm_data, local_sources_path, output).excluded_files
        output.info("Getting sources from folder: %s" % local_sources_path)
        merge_directories(local_sources_path, dest_dir, excluded=excluded)
    else:
        output.info("Getting sources from url: '%s'" % scm_data.url)
        scm = SCM(scm_data, dest_dir, output)
        scm.checkout()
    if cache:
        # This is a bit weird. Why after a SCM should we remove files. Maybe check conan 2.0
        _clean_source_folder(dest_dir)
예제 #5
0
def _capture_scm_auto_fields(conanfile, conanfile_dir, package_layout, output,
                             ignore_dirty, scm_to_conandata):
    """Deduce the values for the scm auto fields or functions assigned to 'url' or 'revision'
       and replace the conanfile.py contents.
       Returns a tuple with (scm_data, path_to_scm_local_directory)"""
    scm_data = get_scm_data(conanfile)
    if not scm_data:
        return None, None

    # Resolve SCMData in the user workspace (someone may want to access CVS or import some py)
    scm = SCM(scm_data, conanfile_dir, output)
    captured = scm_data.capture_origin or scm_data.capture_revision

    if not captured:
        # We replace not only "auto" values, also evaluated functions (e.g from a python_require)
        _replace_scm_data_in_recipe(package_layout, scm_data, scm_to_conandata)
        return scm_data, None

    if not scm.is_pristine() and not ignore_dirty:
        output.warn(
            "There are uncommitted changes, skipping the replacement of 'scm.url' and "
            "'scm.revision' auto fields. Use --ignore-dirty to force it. The 'conan "
            "upload' command will prevent uploading recipes with 'auto' values in these "
            "fields.")
        origin = scm.get_qualified_remote_url(remove_credentials=True)
        local_src_path = scm.get_local_path_to_url(origin)
        return scm_data, local_src_path

    if scm_data.url == "auto":
        origin = scm.get_qualified_remote_url(remove_credentials=True)
        if not origin:
            output.warn(
                "Repo origin cannot be deduced, 'auto' fields won't be replaced."
                " 'conan upload' command will prevent uploading recipes with 'auto'"
                " values in these fields.")
            local_src_path = scm.get_local_path_to_url(origin)
            return scm_data, local_src_path
        if scm.is_local_repository():
            output.warn("Repo origin looks like a local path: %s" % origin)
        output.success("Repo origin deduced by 'auto': %s" % origin)
        scm_data.url = origin

    if scm_data.revision == "auto":
        # If it is pristine by default we don't replace the "auto" unless forcing
        # This prevents the recipe to get uploaded pointing to an invalid commit
        scm_data.revision = scm.get_revision()
        output.success("Revision deduced by 'auto': %s" % scm_data.revision)

    local_src_path = scm.get_local_path_to_url(scm_data.url)
    _replace_scm_data_in_recipe(package_layout, scm_data, scm_to_conandata)

    return scm_data, local_src_path
예제 #6
0
def _capture_export_scm_data(conanfile, conanfile_dir, destination_folder,
                             output, scm_src_file):

    if os.path.exists(scm_src_file):
        os.unlink(scm_src_file)

    scm_data = get_scm_data(conanfile)
    if not scm_data:
        return

    # Resolve SCMData in the user workspace (someone may want to access CVS or import some py)
    scm = SCM(scm_data, conanfile_dir, output)
    captured = scm_data.capture_origin or scm_data.capture_revision

    if scm_data.url == "auto":
        origin = scm.get_qualified_remote_url(remove_credentials=True)
        if not origin:
            raise ConanException("Repo origin cannot be deduced")
        if scm.is_local_repository():
            output.warn("Repo origin looks like a local path: %s" % origin)
        output.success("Repo origin deduced by 'auto': %s" % origin)
        scm_data.url = origin

    if scm_data.revision == "auto":
        if not scm.is_pristine():
            output.warn(
                "Repo status is not pristine: there might be modified files")
        scm_data.revision = scm.get_revision()
        output.success("Revision deduced by 'auto': %s" % scm_data.revision)

    _replace_scm_data_in_conanfile(
        os.path.join(destination_folder, "conanfile.py"), scm_data)

    if captured:
        # Generate the scm_folder.txt file pointing to the src_path
        src_path = scm.get_local_path_to_url(scm_data.url)
        if src_path:
            save(scm_src_file, os.path.normpath(src_path).replace("\\", "/"))

    return scm_data
예제 #7
0
파일: export.py 프로젝트: efremovd/conan
def _capture_export_scm_data(conanfile, conanfile_dir, destination_folder,
                             output, paths, conan_ref):

    scm_src_file = paths.scm_folder(conan_ref)
    if os.path.exists(scm_src_file):
        os.unlink(scm_src_file)

    scm_data = get_scm_data(conanfile)
    captured_revision = scm_data.capture_revision if scm_data else False

    if not scm_data or not (scm_data.capture_origin
                            or scm_data.capture_revision):
        return None, captured_revision

    scm = SCM(scm_data, conanfile_dir, output)

    if scm_data.url == "auto":
        origin = scm.get_qualified_remote_url()
        if not origin:
            raise ConanException("Repo origin cannot be deduced by 'auto'")
        if scm.is_local_repository():
            output.warn("Repo origin looks like a local path: %s" % origin)
        output.success("Repo origin deduced by 'auto': %s" % origin)
        scm_data.url = origin
    if scm_data.revision == "auto":
        if not scm.is_pristine():
            output.warn(
                "Repo status is not pristine: there might be modified files")
        scm_data.revision = scm.get_revision()
        output.success("Revision deduced by 'auto': %s" % scm_data.revision)

    # Generate the scm_folder.txt file pointing to the src_path
    src_path = scm.get_repo_root()
    save(scm_src_file, src_path.replace("\\", "/"))
    _replace_scm_data_in_conanfile(
        os.path.join(destination_folder, "conanfile.py"), scm_data)

    return scm_data, captured_revision