[debhelper-devel] [debhelper] 01/02: Buildsystem: Refactor doit_in_* methods

Niels Thykier nthykier at moszumanska.debian.org
Sat Jul 22 17:06:07 UTC 2017


This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch master
in repository debhelper.

commit 2a89989d1bee10c92d4426b97616cc497c8af080
Author: Niels Thykier <niels at thykier.net>
Date:   Sat Jul 22 16:58:58 2017 +0000

    Buildsystem: Refactor doit_in_* methods
    
    Signed-off-by: Niels Thykier <niels at thykier.net>
---
 Debian/Debhelper/Buildsystem.pm | 74 +++++++++++++----------------------------
 1 file changed, 23 insertions(+), 51 deletions(-)

diff --git a/Debian/Debhelper/Buildsystem.pm b/Debian/Debhelper/Buildsystem.pm
index 3d31d0f..26b0813 100644
--- a/Debian/Debhelper/Buildsystem.pm
+++ b/Debian/Debhelper/Buildsystem.pm
@@ -299,24 +299,28 @@ sub _cd {
 	}
 }
 
-# Changes working directory to the source directory (if needed),
-# calls print_and_doit(@_) and changes working directory back to the
-# top directory.
-sub doit_in_sourcedir {
-	my $this=shift;
-	if ($this->get_sourcedir() ne '.') {
-		my $sourcedir = $this->get_sourcedir();
-		$this->_cd($sourcedir);
+sub _in_dir {
+	my ($this, $dir, $code, @args) = @_;
+	if ($dir ne '.') {
+		my $ret;
+		$this->_cd($dir);
 		eval {
-			print_and_doit(@_);
+			$ret = $code->(@args);
 		};
 		my $saved_exception = $@;
-		$this->_cd($this->_rel2rel($this->{cwd}, $sourcedir));
+		$this->_cd($this->_rel2rel($this->{cwd}, $dir));
 		die $saved_exception if $saved_exception;
+		return $ret;
 	}
-	else {
-		print_and_doit(@_);
-	}
+	return $code->(@args);
+}
+
+# Changes working directory to the source directory (if needed),
+# calls print_and_doit(@_) and changes working directory back to the
+# top directory.
+sub doit_in_sourcedir {
+	my ($this, @args) = @_;
+	$this->_in_dir($this->get_sourcedir, \&print_and_doit, @args);
 	return 1;
 }
 
@@ -324,38 +328,16 @@ sub doit_in_sourcedir {
 # calls print_and_doit(@_) and changes working directory back to the
 # top directory. Errors are ignored.
 sub doit_in_sourcedir_noerror {
-        my $this=shift;
-        my $ret;
-        if ($this->get_sourcedir() ne '.') {
-                my $sourcedir = $this->get_sourcedir();
-                $this->_cd($sourcedir);
-                $ret = print_and_doit_noerror(@_);
-                $this->_cd($this->_rel2rel($this->{cwd}, $sourcedir));
-        }
-        else {
-                $ret = print_and_doit_noerror(@_);
-        }
-        return $ret;
+	my ($this, @args) = @_;
+	return $this->_in_dir($this->get_sourcedir, \&print_and_doit_noerror, @args);
 }
 
 # Changes working directory to the build directory (if needed),
 # calls print_and_doit(@_) and changes working directory back to the
 # top directory.
 sub doit_in_builddir {
-	my $this=shift;
-	if ($this->get_buildpath() ne '.') {
-		my $buildpath = $this->get_buildpath();
-		$this->_cd($buildpath);
-		eval {
-			print_and_doit(@_);
-		};
-		my $saved_exception = $@;
-		$this->_cd($this->_rel2rel($this->{cwd}, $buildpath));
-		die $saved_exception if $saved_exception;
-	}
-	else {
-		print_and_doit(@_);
-	}
+	my ($this, @args) = @_;
+	$this->_in_dir($this->get_buildpath, \&print_and_doit, @args);
 	return 1;
 }
 
@@ -363,18 +345,8 @@ sub doit_in_builddir {
 # calls print_and_doit(@_) and changes working directory back to the
 # top directory. Errors are ignored.
 sub doit_in_builddir_noerror {
-        my $this=shift;
-        my $ret;
-        if ($this->get_buildpath() ne '.') {
-                my $buildpath = $this->get_buildpath();
-                $this->_cd($buildpath);
-                $ret = print_and_doit_noerror(@_);
-                $this->_cd($this->_rel2rel($this->{cwd}, $buildpath));
-        }
-        else {
-                $ret = print_and_doit_noerror(@_);
-        }
-        return $ret;
+	my ($this, @args) = @_;
+	return $this->_in_dir($this->get_buildpath, \&print_and_doit_noerror, @args);
 }
 
 # In case of out of source tree building, whole build directory

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debhelper/debhelper.git




More information about the debhelper-devel mailing list