-
Notifications
You must be signed in to change notification settings - Fork 191
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
Feature/rules multi sources #340
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,43 +236,84 @@ Rule.prototype = new (function () { | |
, source | ||
, action | ||
, opts | ||
, prereqs | ||
, parts | ||
, valid | ||
, src | ||
, tNs | ||
, createdTask | ||
, name = Task.getBaseTaskName(fullName) | ||
, nsPath = Task.getBaseNamespacePath(fullName) | ||
, ns = this.ns.resolveNamespace(nsPath); | ||
, ns = this.ns.resolveNamespace(nsPath) | ||
, prereqs = this.prereqs.slice(); // Get a copy to work with | ||
|
||
pattern = this.pattern; | ||
source = this.source; | ||
|
||
if (typeof source == 'string') { | ||
src = Matcher.getSource(name, pattern, source); | ||
// TODO: Write a utility function that appends a | ||
// taskname to a namespace path | ||
var completeNamespace = function(s){ | ||
return nsPath.split(':').filter(function (item) { | ||
return !!item; | ||
}).concat(s).join(':'); | ||
}; | ||
|
||
// Deal with the various things the source argument can be: | ||
// 1: A function | ||
if (typeof source == 'function') { | ||
source = source(name); | ||
|
||
if (source instanceof Array) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like duplcate logic of what's below. Can you refactor this so that it does its function stuff first, then do the regular logic for Array/String? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had a similar thought - but then noticed each instance works slightly differently. The
while
(same for From skimming the source, I think that means if a string is passed directly, it can contain wildcards, but if it's returned from a function, it must be the entire filename of the source, without wildcards, etc. Now, maybe wildcards should always be applied (or I've misinterpreted the code I skimmed), but that's my 2 cents. |
||
// It's a function that returns an array of sources (strings) | ||
src = []; | ||
source.forEach(function(srcName){ | ||
src.push(completeNamespace( srcName) ); | ||
}); | ||
prereqs = prereqs.concat(src); | ||
} | ||
|
||
else if (typeof source == 'string') { | ||
// It's a function that returns a single source (string) | ||
src = completeNamespace(source); | ||
prereqs.unshift(src); | ||
} | ||
|
||
else { | ||
// It's a function that returns a headache. | ||
debugger; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove debugger statement. |
||
throw new Error("Can't parse rule source."); | ||
} | ||
} | ||
else { | ||
src = source(name); | ||
|
||
// 2: An array of sources | ||
else if (source instanceof Array) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// Find them all: | ||
src = []; | ||
source.forEach(function(srcName){ | ||
src.push(completeNamespace( Matcher.getSource(name, pattern, srcName) )); | ||
}); | ||
prereqs = prereqs.concat(src); | ||
} | ||
|
||
// 3: A single source | ||
else if (typeof source == 'string') { | ||
src = completeNamespace( Matcher.getSource(name, pattern, source) ); | ||
prereqs.unshift(src); | ||
} | ||
|
||
// TODO: Write a utility function that appends a | ||
// taskname to a namespace path | ||
src = nsPath.split(':').filter(function (item) { | ||
return !!item; | ||
}).concat(src).join(':'); | ||
// 4: There is no #4 | ||
else { | ||
throw new Error("Can't parse rule source."); | ||
} | ||
|
||
// Generate the prerequisite for the matching task. | ||
// It is the original prerequisites plus the prerequisite | ||
// It is the original prerequisites plus the definied prerequisite/prerequisites | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If changes are being made, might as well fix a typo in the new code? |
||
// representing source file, i.e., | ||
// | ||
// rule( '%.o', '%.c', ['some.h'] ... | ||
// | ||
// If the objective is main.o, then new task should be | ||
// | ||
// file( 'main.o', ['main.c', 'some.h' ] ... | ||
prereqs = this.prereqs.slice(); // Get a copy to work with | ||
prereqs.unshift(src); | ||
|
||
// Prereq should be: | ||
// 1. an existing task | ||
|
@@ -307,7 +348,14 @@ Rule.prototype = new (function () { | |
tNs = jake.currentNamespace; | ||
jake.currentNamespace = ns; | ||
createdTask = jake.createTask('file', name, prereqs, action, opts); | ||
createdTask.source = src.split(':').pop(); | ||
if (src instanceof Array) { | ||
createdTask.source = []; | ||
src.forEach(function(s){ | ||
createdTask.source.push(s.split(':').pop()); | ||
}); | ||
} else { | ||
createdTask.source = src.split(':').pop(); | ||
} | ||
jake.currentNamespace = tNs; | ||
|
||
return createdTask; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not completely sold on the function idea, mostly because part of the idea here was to make Rules behave more like Tasks. Could you leave this change for a different PR, and maybe implement it for both Tasks and Rules?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mde I think that this is just a more explicit version of the
else {
that was already in the codebase (https://github.com/jakejs/jake/pull/340/files/afe002d343308d61527ec894e78630889f406281#diff-03fda114c6cfeff1993dbc9c03d7724bL255) (exact body) - just more explicit about the conditions.