diff options
author | Niels Thykier <niels@thykier.net> | 2017-07-22 16:58:58 +0000 |
---|---|---|
committer | Niels Thykier <niels@thykier.net> | 2017-07-22 16:58:58 +0000 |
commit | 2a89989d1bee10c92d4426b97616cc497c8af080 (patch) | |
tree | a4ec4753d08989e1b3805a1024b4559848a5add8 | |
parent | 855f303c7e21aa0e16f3113ae9c9fdd145e92c0b (diff) | |
download | debhelper-2a89989d1bee10c92d4426b97616cc497c8af080.tar.gz |
Buildsystem: Refactor doit_in_* methods
Signed-off-by: Niels Thykier <niels@thykier.net>
-rw-r--r-- | Debian/Debhelper/Buildsystem.pm | 74 |
1 files changed, 23 insertions, 51 deletions
diff --git a/Debian/Debhelper/Buildsystem.pm b/Debian/Debhelper/Buildsystem.pm index 3d31d0f7..26b0813b 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 |