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

env var replacement not supporting ${VAR_NAME} syntax #1392

Merged
merged 5 commits into from
Jul 27, 2018

Conversation

MartinNowak
Copy link
Member

This is commonly needed to join pathes or a suffix, e.g. $PACKAGE_DIRmylib.a (as unfortunately PACKAGE_DIR ends on /).
Expanding variables is straighforward, https://github.com/MartinNowak/alertd/blob/cbc4459bbdbcc8c799413f58a591f6d28205f147/src/alertd.d#L503.

MartinNowak added a commit to MartinNowak/dub that referenced this pull request Feb 22, 2018
- simplified and cleaner env var replacement using
  straighforward regex replaceAll
- support ${MY_VAR}suffix replacements
@dlang-bot
Copy link
Collaborator

Thanks for your pull request, @MartinNowak!

@s-ludwig
Copy link
Member

Did you check if we get any significant compile-time regressions due to ctRegex?

Otherwise LGTM.

BTW, I'll go through the commit history to add missing change log entries once more, but I already wanted to suggest that we switch to a mode where each significant PR must add a change log entry, because I simply didn't manage to manually author them in time recently. We should probably add a CONTRIBUTING file at some point mentioning this.

@MartinNowak
Copy link
Member Author

MartinNowak commented Feb 22, 2018

Did you check if we get any significant compile-time regressions due to ctRegex?

Yeah, replaced it with a runtime regex (btw, nowadays even enum re = regex("") is slow, as it merely does the same as ctRegex (dlang/phobos#5722)). Regexes are cached by std.regex, so it shouldn't be a runtime problem.

@s-ludwig
Copy link
Member

s-ludwig commented Feb 22, 2018

Regexes are cached by std.regex, so it shouldn't be a runtime problem.

Didn't know that. Then we can also remove the manual caching that is done in other places within DUB.

@MartinNowak
Copy link
Member Author

MartinNowak commented Feb 22, 2018

Of course it's messier than explainable, seems like NativePath only preserves trailing separators on posix, so one would need ${PACKAGE_PATH}foobar on posix but ${PACKAGE_PATH}\\foobar for Windows. Given that concatenating suffixes is currently not possible the risk of breaking sth. by removing the slash from PACKAGE_PATH on Posix doesn't seem to big, so I'll go for that to not create an even worse mess.

BTW, I think it would be a net positive for dub to get rid of NativePath.

Slash behavior originally introduced here vibe-d/vibe.d@970a022#diff-3620332feace439ec637b023bc2e7a01R262, and apparently broken here vibe-d/vibe.d@344fe34#diff-47d6be40e29a186df00d5f3bfad92671R36.

@MartinNowak
Copy link
Member Author

MartinNowak commented Feb 22, 2018

Didn't know that. Then we can also remove the manual caching that is done in other places within DUB.

Depends on expectations, https://github.com/dlang/phobos/blob/b26aad3209c1adb3006ff7003c44a7f0cdde06d9/std/regex/package.d#L364, 8 entries isn't necessarily enough, but processVars calls are coming all at once.

@MartinNowak
Copy link
Member Author

The slash was introduced with 4d4017c to fix #268. It also makes sense for output such as dub list to append a slash, so I'd suggest to just remove the slash in env var expansion.

@MartinNowak
Copy link
Member Author

MartinNowak commented Feb 23, 2018

Does that look reasonable? It seems that the chances for breakage are small as $PATHsuffix wasn't possible beforehand, so mostly cd $PATH && ./script were used.
Could subtly break weird path based comparisons or concatenations in scripts though.

@MartinNowak MartinNowak force-pushed the env_vars branch 2 times, most recently from a8f5adb to 73ec880 Compare February 23, 2018 22:48
@wilzbach
Copy link
Member

but I already wanted to suggest that we switch to a mode where each significant PR must add a change log entry, because I simply didn't manage to manually author them in time recently. We should probably add a CONTRIBUTING file at some point mentioning this.

If you add a changelog entry to changelog like DMD does, the files will be displayed at https://dlang.org/changelog/pending.html and automatically part of the release announcement.

I recently added support for this on tools/dlang.org side for this:
dlang/tools#302
dlang/dlang.org#2163

Integrating the GitHub issues (like @dlang-bot currently does) is more work and I wasn't sure whether that's wanted, so I left that one out for now.

@wilzbach
Copy link
Member

wilzbach commented Mar 23, 2018

Regexes are cached by std.regex, so it shouldn't be a runtime problem.

With dlang/phobos#6268 (in the upcoming 2.080) std.regex caching got a big improvement.
So there's some reason to use static varRE, but OTOH it's probably not worth the troubles.

Copy link
Member

@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.

Does that look reasonable? It seems that the chances for breakage are small as $PATHsuffix wasn't possible beforehand, so mostly cd $PATH && ./script were used.
Could subtly break weird path based comparisons or concatenations in scripts though.

It doesn't break anything in the ~40 projects on Jenkins, so that's a good start.
And yes not using a trailing looks and thus having a unified behavior for the path variables looks very reasonable to me.

enum isPath = true;

version (Posix) enum sep = "/";
else version (Windows) enum sep = `\`;
Copy link
Member

Choose a reason for hiding this comment

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

aka as std.path.dirSeparator

if (name == "PACKAGE_DIR")
path = pack.path;
else if (name == "ROOT_PACKAGE_DIR")
path = project.rootPackage.path;

if (name.endsWith("_PACKAGE_DIR")) {
auto pname = name[0 .. $-12];
foreach (prj; project.getTopologicalPackageList())
if (prj.name.toUpper().replace("-", "_") == pname)
Copy link
Member

Choose a reason for hiding this comment

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

FWIW there's no need to allocate for this check,sth. like this should work fine and is @nogc:
prj.name.asUpperCase.map!(a == '-' ? '_' : a).equal(pname)

@wilzbach wilzbach added this to the 1.9.0 milestone Mar 23, 2018
@wilzbach wilzbach mentioned this pull request May 2, 2018
wilzbach pushed a commit to MartinNowak/dub that referenced this pull request Jul 11, 2018
- simplified and cleaner env var replacement using
  straighforward regex replaceAll
- support ${MY_VAR}suffix replacements
@wilzbach wilzbach removed this from the 1.9.0 milestone Jul 11, 2018
@wilzbach
Copy link
Member

wilzbach commented Jul 11, 2018

Addressed my review myself and rebased (the changelog entry is now in changelog/).

@wilzbach wilzbach added this to the 1.11 milestone Jul 21, 2018
wilzbach pushed a commit to MartinNowak/dub that referenced this pull request Jul 21, 2018
- simplified and cleaner env var replacement using
  straighforward regex replaceAll
- support ${MY_VAR}suffix replacements
@wilzbach
Copy link
Member

Rebased again :/

- simplified and cleaner env var replacement using
  straighforward regex replaceAll
- support ${MY_VAR}suffix replacements
MartinNowak and others added 3 commits July 27, 2018 14:29
- expand $VARS without trailing slash/backslash
  (for concatenation e.g. `${PACKAGE_PATH}/subpath`)
@MartinNowak MartinNowak merged commit f447add into dlang:master Jul 27, 2018
@MartinNowak MartinNowak deleted the env_vars branch July 27, 2018 19:32
Geod24 added a commit to Geod24/dub that referenced this pull request Sep 4, 2018
This was broken by the refactoring in dlang#1392 (commit 14c00c4)
Geod24 added a commit to Geod24/dub that referenced this pull request Sep 5, 2018
This was broken by the refactoring in dlang#1392 (commit 14c00c4)
Geod24 added a commit to Geod24/dub that referenced this pull request Sep 5, 2018
This was broken by the refactoring in dlang#1392 (commit 14c00c4)
Geod24 added a commit to Geod24/dub that referenced this pull request Sep 8, 2018
This was broken by the refactoring in dlang#1392 (commit 14c00c4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants