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))
def composite_stage_with_expanding_resource( mock_archive, mock_expand_resource): composite_stage = StageComposite() root_stage = Stage(mock_archive.url) composite_stage.append(root_stage) test_resource_fetcher = spack.fetch_strategy.from_kwargs( url=mock_expand_resource.url) # Specify that the resource files are to be placed in the 'resource-dir' # directory test_resource = Resource( 'test_resource', test_resource_fetcher, '', 'resource-dir') resource_stage = ResourceStage( test_resource_fetcher, root_stage, test_resource) composite_stage.append(resource_stage) return composite_stage, root_stage, resource_stage
def test_composite_stage_with_noexpand_resource( self, mock_archive, mock_noexpand_resource): composite_stage = StageComposite() root_stage = Stage(mock_archive.url) composite_stage.append(root_stage) resource_dst_name = 'resource-dst-name.sh' test_resource_fetcher = spack.fetch_strategy.from_kwargs( url='file://' + mock_noexpand_resource, expand=False) test_resource = Resource( 'test_resource', test_resource_fetcher, resource_dst_name, None) resource_stage = ResourceStage( test_resource_fetcher, root_stage, test_resource) composite_stage.append(resource_stage) composite_stage.create() composite_stage.fetch() composite_stage.expand_archive() assert os.path.exists( os.path.join(composite_stage.source_path, resource_dst_name))
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))