Skip to content

dub.project: Improve variable expansion logic#1641

Merged
wilzbach merged 1 commit intodlang:masterfrom
CyberShadow:pull-20190120-125417
Feb 28, 2019
Merged

dub.project: Improve variable expansion logic#1641
wilzbach merged 1 commit intodlang:masterfrom
CyberShadow:pull-20190120-125417

Conversation

@CyberShadow
Copy link
Copy Markdown
Member

Replace the previous buggy logic with a simpler and more efficient
implementation.
@dlang-bot
Copy link
Copy Markdown
Collaborator

Thanks for your pull request, @CyberShadow!

@CyberShadow CyberShadow changed the title dub.source.dub.project: Improve variable expansion logic dub.project: Improve variable expansion logic Jan 20, 2019
Comment thread source/dub/project.d
assertThrown(expandVars!expandVar("${X"));

// https://github.com/dlang/dmd/pull/9275
assert(expandVars!expandVar("$${DUB_EXE:-dub}") == "${DUB_EXE:-dub}");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we test for other Bash variable syntaxes: https://www.tldp.org/LDP/abs/html/parameter-substitution.html ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the point of this test is to explicitly check that Dub doesn't do anything crazy here, and it ignores anything following $$ and passes it through verbatim, whatever the syntax might be. The previous implementation expected very specific syntax to be used even when escaping Dub processing, which was presumptuous and led to wrong behavior. This test (and any other tests we might add in the same vein) are supplemental / illustrative to the behavior tests above, and don't actually add to the test coverage. An implementation of expandVars which somehow passes all of these tests but would behave incorrectly with other kinds of Bash variable substitution syntax would be very weird indeed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, good enough for me.

@jacob-carlborg
Copy link
Copy Markdown
Contributor

LGTM.

@PetarKirov
Copy link
Copy Markdown
Member

Instead of looking for $ (minding escapes), it uses a regular expression to match what it thinks shell variable use looks like.

@CyberShadow Yes, it is working as intended - it's just that we have a different definition of what's intended. I asked for input on this matter on the newsgroup, but apparently no one cared enough to respond at the time, so we went with the current behavior.

@CyberShadow
Copy link
Copy Markdown
Member Author

@ZombineDev Sorry, what do you mean? Of the unit tests I added, how would you consider an implementation that failed them as "working as intended"?

Copy link
Copy Markdown
Contributor

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new implementation is so much more readable 👍

@wilzbach
Copy link
Copy Markdown
Contributor

I'm going to merge this now as it still passes all the tests of the referenced #1392 which is in master now.

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

Successfully merging this pull request may close these issues.

6 participants