Patch.apply() shouldn't affect working directory of caller.

This commit is contained in:
Todd Gamblin 2017-08-26 18:18:24 -07:00
parent 29ce69f3ed
commit a3cb6b61ea

View File

@ -30,7 +30,7 @@
import spack.error import spack.error
import spack.fetch_strategy as fs import spack.fetch_strategy as fs
import spack.stage import spack.stage
from llnl.util.filesystem import join_path from llnl.util.filesystem import working_dir
from spack.util.executable import which from spack.util.executable import which
@ -91,10 +91,11 @@ def apply(self, stage):
Args: Args:
stage: stage for the package that needs to be patched stage: stage for the package that needs to be patched
""" """
stage.chdir_to_source() patch = which("patch", required=True)
# Use -N to allow the same patches to be applied multiple times. with working_dir(stage.source_path):
_patch = which("patch", required=True) # Use -N to allow the same patches to be applied multiple times.
_patch('-s', '-p', str(self.level), '-i', self.path) patch('-s', '-p', str(self.level), '-i', self.path)
class FilePatch(Patch): class FilePatch(Patch):
@ -103,7 +104,7 @@ def __init__(self, pkg, path_or_url, level):
super(FilePatch, self).__init__(pkg, path_or_url, level) super(FilePatch, self).__init__(pkg, path_or_url, level)
pkg_dir = os.path.dirname(absolute_path_for_package(pkg)) pkg_dir = os.path.dirname(absolute_path_for_package(pkg))
self.path = join_path(pkg_dir, path_or_url) self.path = os.path.join(pkg_dir, path_or_url)
if not os.path.isfile(self.path): if not os.path.isfile(self.path):
raise NoSuchPatchFileError(pkg.name, self.path) raise NoSuchPatchFileError(pkg.name, self.path)
@ -123,10 +124,10 @@ def apply(self, stage):
stage: stage for the package that needs to be patched stage: stage for the package that needs to be patched
""" """
fetcher = fs.URLFetchStrategy(self.url, digest=self.md5) fetcher = fs.URLFetchStrategy(self.url, digest=self.md5)
mirror = join_path( mirror = os.path.join(
os.path.dirname(stage.mirror_path), os.path.dirname(stage.mirror_path),
os.path.basename(self.url) os.path.basename(self.url))
)
with spack.stage.Stage(fetcher, mirror_path=mirror) as patch_stage: with spack.stage.Stage(fetcher, mirror_path=mirror) as patch_stage:
patch_stage.fetch() patch_stage.fetch()
patch_stage.check() patch_stage.check()
@ -136,8 +137,8 @@ def apply(self, stage):
patch_stage.expand_archive() patch_stage.expand_archive()
self.path = os.path.abspath( self.path = os.path.abspath(
os.listdir(patch_stage.path).pop() os.listdir(patch_stage.path).pop())
)
super(UrlPatch, self).apply(stage) super(UrlPatch, self).apply(stage)