示例#1
0
    def _execute_resource(pkg):
        when = kwargs.get('when')
        when_spec = make_when_spec(when)
        if not when_spec:
            return

        destination = kwargs.get('destination', "")
        placement = kwargs.get('placement', None)

        # Check if the path is relative
        if os.path.isabs(destination):
            message = ('The destination keyword of a resource directive '
                       'can\'t be an absolute path.\n')
            message += "\tdestination : '{dest}\n'".format(dest=destination)
            raise RuntimeError(message)

        # Check if the path falls within the main package stage area
        test_path = 'stage_folder_root'
        normalized_destination = os.path.normpath(
            os.path.join(test_path, destination))  # Normalized absolute path

        if test_path not in normalized_destination:
            message = ("The destination folder of a resource must fall "
                       "within the main package stage directory.\n")
            message += "\tdestination : '{dest}'\n".format(dest=destination)
            raise RuntimeError(message)

        resources = pkg.resources.setdefault(when_spec, [])
        name = kwargs.get('name')
        fetcher = from_kwargs(**kwargs)
        resources.append(Resource(name, fetcher, destination, placement))
示例#2
0
文件: directives.py 项目: LLNL/spack
    def _execute_resource(pkg):
        when = kwargs.get('when', pkg.name)
        destination = kwargs.get('destination', "")
        placement = kwargs.get('placement', None)

        # Check if the path is relative
        if os.path.isabs(destination):
            message = ('The destination keyword of a resource directive '
                       'can\'t be an absolute path.\n')
            message += "\tdestination : '{dest}\n'".format(dest=destination)
            raise RuntimeError(message)

        # Check if the path falls within the main package stage area
        test_path = 'stage_folder_root'
        normalized_destination = os.path.normpath(
            os.path.join(test_path, destination)
        )  # Normalized absolute path

        if test_path not in normalized_destination:
            message = ("The destination folder of a resource must fall "
                       "within the main package stage directory.\n")
            message += "\tdestination : '{dest}'\n".format(dest=destination)
            raise RuntimeError(message)

        when_spec = spack.spec.parse_anonymous_spec(when, pkg.name)
        resources = pkg.resources.setdefault(when_spec, [])
        name = kwargs.get('name')
        fetcher = from_kwargs(**kwargs)
        resources.append(Resource(name, fetcher, destination, placement))
示例#3
0
文件: directives.py 项目: d-tk/spack
def resource(pkg, **kwargs):
    """
    Define an external resource to be fetched and staged when building the package. Based on the keywords present in the
    dictionary the appropriate FetchStrategy will be used for the resource. Resources are fetched and staged in their
    own folder inside spack stage area, and then linked into the stage area of the package that needs them.

    List of recognized keywords:

    * 'when' : (optional) represents the condition upon which the resource is needed
    * 'destination' : (optional) path where to link the resource. This path must be relative to the main package stage
    area.
    * 'placement' : (optional) gives the possibility to fine tune how the resource is linked into the main package stage
    area.
    """
    when = kwargs.get('when', pkg.name)
    destination = kwargs.get('destination', "")
    placement = kwargs.get('placement', None)
    # Check if the path is relative
    if os.path.isabs(destination):
        message = "The destination keyword of a resource directive can't be an absolute path.\n"
        message += "\tdestination : '{dest}\n'".format(dest=destination)
        raise RuntimeError(message)
    # Check if the path falls within the main package stage area
    test_path = 'stage_folder_root/'
    normalized_destination = os.path.normpath(join_path(test_path, destination))  # Normalized absolute path
    if test_path not in normalized_destination:
        message = "The destination folder of a resource must fall within the main package stage directory.\n"
        message += "\tdestination : '{dest}'\n".format(dest=destination)
        raise RuntimeError(message)
    when_spec = parse_anonymous_spec(when, pkg.name)
    resources = pkg.resources.setdefault(when_spec, [])
    name = kwargs.get('name')
    fetcher = from_kwargs(**kwargs)
    resources.append(Resource(name, fetcher, destination, placement))
示例#4
0
def resource(pkg, **kwargs):
    """
    Define an external resource to be fetched and staged when building the
    package. Based on the keywords present in the dictionary the appropriate
    FetchStrategy will be used for the resource. Resources are fetched and
    staged in their own folder inside spack stage area, and then linked into
    the stage area of the package that needs them.

    List of recognized keywords:

    * 'when' : (optional) represents the condition upon which the resource is
    needed
    * 'destination' : (optional) path where to link the resource. This path
    must be relative to the main package stage area.
    * 'placement' : (optional) gives the possibility to fine tune how the
    resource is linked into the main package stage area.
    """
    when = kwargs.get('when', pkg.name)
    destination = kwargs.get('destination', "")
    placement = kwargs.get('placement', None)
    # Check if the path is relative
    if os.path.isabs(destination):
        message = "The destination keyword of a resource directive can't be"
        " an absolute path.\n"
        message += "\tdestination : '{dest}\n'".format(dest=destination)
        raise RuntimeError(message)
    # Check if the path falls within the main package stage area
    test_path = 'stage_folder_root'
    normalized_destination = os.path.normpath(join_path(
        test_path, destination))  # Normalized absolute path
    if test_path not in normalized_destination:
        message = "The destination folder of a resource must fall within the"
        " main package stage directory.\n"
        message += "\tdestination : '{dest}'\n".format(dest=destination)
        raise RuntimeError(message)
    when_spec = parse_anonymous_spec(when, pkg.name)
    resources = pkg.resources.setdefault(when_spec, [])
    name = kwargs.get('name')
    fetcher = from_kwargs(**kwargs)
    resources.append(Resource(name, fetcher, destination, placement))