rdmd: support --eval <arg> to make it Makefile friendly#336
rdmd: support --eval <arg> to make it Makefile friendly#336dlang-bot merged 1 commit intodlang:masterfrom Superstar64:makefile_compat_rdmd
Conversation
|
Thanks for your pull request and interest in making D better, @Superstar64! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + tools#336" |
|
Interesting addition, thanks for the PR! However, I'm not sure if Is there a restriction that the flag must be single-letter? Why not just allow The following simpler patch works for me: diff --git a/rdmd.d b/rdmd.d
index 4ca39b3..d547f28 100755
--- a/rdmd.d
+++ b/rdmd.d
@@ -330,7 +330,8 @@ size_t indexOfProgram(string[] args)
foreach(i, arg; args[1 .. $])
{
if (!arg.startsWith('-', '@') &&
- !arg.endsWith(".obj", ".o", ".lib", ".a", ".def", ".map", ".res"))
+ !arg.endsWith(".obj", ".o", ".lib", ".a", ".def", ".map", ".res") &&
+ args[i /*- 1 + 1*/] != "--eval")
{
return i + 1;
}Also, tests & documentation would be nice! |
And changelog entry :) |
|
Pardon my ignorance, but how do I add documentation and to the change log? |
rdmd.d
Outdated
| if (!arg.startsWith('-', '@') && | ||
| !arg.endsWith(".obj", ".o", ".lib", ".a", ".def", ".map", ".res")) | ||
| !arg.endsWith(".obj", ".o", ".lib", ".a", ".def", ".map", ".res") && | ||
| args[i /*- 1 + 1*/] != "--eval") |
There was a problem hiding this comment.
This is already checked via !arg.startsWith('-', '@') isn't it?
There was a problem hiding this comment.
No, the new snippet allows --eval code. Before it would think code was a file.
There was a problem hiding this comment.
oh I see. args[i] != arg...very confusing I must say. I see you put a comment to try to indicate this.
Maybe create a new variable previousArg to make it less confusing?
|
Simply add a file to the changelog folder - see e.g. this Readme to get started: https://github.com/dlang/dmd/blob/master/changelog/README.md |
posix.mak
Outdated
|
|
||
| test_rdmd: $(ROOT)/rdmd_test $(RDMD_TEST_EXECUTABLE) | ||
| export RDMD_TEST_EXECUTABLE | ||
| export ROOT |
There was a problem hiding this comment.
Can we just export these variables when invoking the Makefile to avoid leakage and being explicit?
|
(also mind the CI failures) |
|
Not completely sure, but I think the reason the test failing is because .SHELLFLAGS is a gnu extension. What should I do about that? |
|
Travis uses Ubuntu 14.04 which uses GNUmake, but maybe an old version? |
|
It appears to be ignoring .ONESHELL and .SHELLFLAGS. Might be make's posix compliant mode? |
changelog/rdmdMakefiles.dd
Outdated
| @@ -0,0 +1,12 @@ | |||
| rdmd can now used as a shell in makefiles | |||
There was a problem hiding this comment.
rdmd can now be used as a shell in makefiles
|
The only ways I can think of fixing this is to have either break compatibility and make rdmd interpret -c as --eval,have a separate program |
rdmd.d
Outdated
| { | ||
| foreach(i, arg; args[1 .. $]) | ||
| { | ||
| //args[i] check for the previous argument |
There was a problem hiding this comment.
How about this? Seems much less confusing to me:
size_t indexOfProgram(string[] args)
{
foreach (i; 1 .. args.length)
{
auto arg = args[i];
if (!arg.startsWith('-', '@') &&
!arg.endsWith(".obj", ".o", ".lib", ".a", ".def", ".map", ".res") &&
args[i - 1] != "--eval")
{
return i;
}
}
return args.length;
}There was a problem hiding this comment.
The current code would be better written as
foreach (previousArgIndex, arg; args[1 .. $])...definitely confusing...
|
Not sure what the best solution would be, but another idea would be to create a shell wrapper that looks something like this, i.e. rdmd_shell: |
|
Yet another idea is to create an alias to if (args[0].baseName == "rdmd_shell")
{
// behave as if --eval was given
} |
|
Ok i've figured it out, |
|
Another way to do the test would be to make |
changelog/rdmdMakefiles.dd
Outdated
| .SHELLFLAGS = --eval | ||
| hello.txt: | ||
| import std.file; | ||
| write("$@","hello world\n"); |
rdmd_makefile_test.mak
Outdated
| SHELL = $(RDMD_TEST_EXECUTABLE) | ||
| .SHELLFLAGS = --eval | ||
| $(ROOT)/rdmd_makefile_test.txt: | ||
| import std.file; |
There was a problem hiding this comment.
Entire Phobos is auto-imported with --eval ;-)
changelog/rdmdMakefiles.dd
Outdated
| SHELL = $(RDMD_TEST_EXECUTABLE) | ||
| .SHELLFLAGS = --eval | ||
| hello.txt: | ||
| import std.file; |
There was a problem hiding this comment.
Entire Phobos is auto-imported with --eval ;-)
There was a problem hiding this comment.
That import is there because std.file : write conflicts with std.stdio : write. Would you rather it be std.file.write(...)?
Probably something worthwhile to mentioned in the changelog. Ideas to workaround this:
Building from source isn't so hard: curl https://ftp.gnu.org/gnu/make/make-4.2.tar.gz | tar -xz
cd make-4.2
./configure
./build.sh
cd ..
MAKE=$(PWD)/make-4.2/make |
Should there be a check if the version of make running the makefile is least 3.82? |
|
Imho it's safe that all other systems running the tool's testsuite use 3.82 or higher, so I would simply put this building code in |
|
Sorry it took me so many commits to get travis working |
wilzbach
left a comment
There was a problem hiding this comment.
LGTM too! Thanks a lot for the hard work!
changelog/rdmdMakefiles.dd
Outdated
| .SHELLFLAGS = --eval | ||
| hello.txt: | ||
| import std.file; | ||
| write("$@","hello world\n"); |
There was a problem hiding this comment.
FYI: @CyberShadow we should use tabs here, s.t. users can easily copy/paste this file.
changelog/rdmdMakefiles.dd
Outdated
| SHELL = /usr/bin/rdmd | ||
| .SHELLFLAGS = --eval | ||
| hello.txt: | ||
| import std.file; |
There was a problem hiding this comment.
We should really resolve this conflict between std.stdio.write and std.file.write.
There's one workaround though: "$@".File("w").writeln("hello world");, but I'm not sure if it's better than the import.
| if (!arg.startsWith('-', '@') && | ||
| !arg.endsWith(".obj", ".o", ".lib", ".a", ".def", ".map", ".res")) | ||
| !arg.endsWith(".obj", ".o", ".lib", ".a", ".def", ".map", ".res") && | ||
| args[i - 1] != "--eval") |
There was a problem hiding this comment.
@Superstar64 FYI: I fixed the style here. DStyle is to use whitespace before/after binary operators.
changelog/rdmdMakefiles.dd
Outdated
| SHELL = /usr/bin/rdmd | ||
| .SHELLFLAGS = --eval | ||
| hello.txt: | ||
| import std.file; |
There was a problem hiding this comment.
We should really resolve this conflict between std.stdio.write and std.file.write.
There's one workaround though: "$@".File("w").writeln("hello world");, but I'm not sure if it's better than the import.
changelog/rdmdMakefiles.dd
Outdated
| .SHELLFLAGS = --eval | ||
| hello.txt: | ||
| import std.file; | ||
| write("$@","hello world\n"); |
There was a problem hiding this comment.
FYI: @CyberShadow we should use tabs here, s.t. users can easily copy/paste this file, but DAutoTest complains about it, so I guess we just keep spaces for the sake of simplicity.
There was a problem hiding this comment.
Maybe we can get a $(TAB) DDoc macro?
|
travis build failed because of a http 502. how do request a rebuild? |
|
You just did so. FWIW you might be interested in dlang/installer#273 which would avoid this error, but it's in the queue for a long time already with Martin being so busy :/ |
|
Wait isn't the commit message misleading? |
|
Thank you |
|
Yeah, I just squashed to your initial one. Thanks! |
|
(added |
This a patch to make rdmd work for makefiles using a -e flag.
note --eval= won't work in SHELLFLAGS because make passes SHELLFLAGS and the code in seperate arguments.