Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task dependencies via needs is broken when modules have namespace separators #1188

Closed
ferki opened this issue Jan 15, 2018 · 0 comments
Closed
Assignees

Comments

@ferki
Copy link
Member

ferki commented Jan 15, 2018

As reported via a comment by @alip, calling needs seem to be broken at least for some use cases, and it at least happens since merging 7cf0ca4 (to fix #1066 on #1157).

I'm opening this issue in order to describe some details based on my own debugging, and also to collect more feedback before applying a fix.

I've used the following code while trying to replicate the reported behavior:

$ cat Rexfile
use Rex;

use Module;
use Nested::Module;

task 'test', sub {
  say q(This is a test);

  needs 'local_needs';
  needs Module 'module_needs';
  needs Nested::Module 'nested_needs';

  say q(end test);
};

task 'local_needs', sub {
  say q(I'm needed locally);
};
$ cat lib/Module.pm
package Module;

use Rex -base;

task 'module_needs', sub {
  say q(I'm needed in a module);
};

1;
$ cat lib/Nested/Module.pm
package Nested::Module;

use Rex -base;

task 'nested_needs', sub {
  say q(I'm needed in a nested module);
  needs main 'local_needs';
};

1;

This tests needing tasks from the same namespace, from a "simple" namespace, and from a "nested" namespace, as well as needing a task in the main namespace from one of the used modules.

Trying to execute the test task shows the following (-qw is only used for reduced output before copy-pasting):

$ rex -qw test
This is a test
I'm needed locally
I'm needed in a module
end test

Which indicates that the originally mentioned use cases of

needs Pkg 'task' and needs 'task'

are working correctly, but it fails to handle cases when the module contains name separator(s).

Applying the following hotfix converts Perl's module namespace separators to Rex task namespace separators, and seems to solve the above for me:

diff --git a/lib/Rex/Commands.pm b/lib/Rex/Commands.pm
index 256b32f0..9a619fb7 100644
--- a/lib/Rex/Commands.pm
+++ b/lib/Rex/Commands.pm
@@ -1035,6 +1035,8 @@ sub needs {
 
   Rex::Logger::debug("need to call tasks from $self");
 
+  $self =~ s/::/:/g;
+
   my @tasks_to_run;
   if($self) {
     @tasks_to_run = $tl->get_all_tasks(qr{^\Q$self\E:[A-Za-z0-9_\-]+$});

edit: of course, a proper fix should contain tests for the "nested" case too :)

@ferki ferki self-assigned this Jan 19, 2018
@ferki ferki added the in progress A topic that is currently being taken care of label Jan 19, 2018
@ferki ferki closed this as completed in 88949fd Apr 29, 2018
@ferki ferki removed the in progress A topic that is currently being taken care of label Apr 29, 2018
alip pushed a commit to adjust/Rex that referenced this issue Feb 7, 2020
alip pushed a commit to adjust/Rex that referenced this issue Aug 10, 2020
alip pushed a commit to adjust/Rex that referenced this issue Aug 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant