FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

#! on linux

 
Post new topic   Reply to topic     Forum Index -> Build
View previous topic :: View next topic  
Author Message
keinfarbton



Joined: 03 Dec 2005
Posts: 224
Location: Stuttgart - Germany

PostPosted: Mon Oct 02, 2006 6:50 am    Post subject: #! on linux Reply with quote

#! is also called shebang or hashbang.

I tried to use build/bud on linux with the shells #! syntax, but I can't get it to run.

This feature would be very useful on linux, because it would enable D as a scripting language. I fact without build, this is not possible. Dmd supports this feature, but without the ability to automatically build and link the needed files, it is not really useful.

dmd supports #! line in source files since http://www.digitalmars.com/d/changelog.html#new0146.

A more detailed description about #!:
http://homepages.cwi.nl/~aeb/std/hashexclam-1.html#ss1.1. Note the mixing of the argument sequence. So if the -exec argument needs to be the last, there is the need to correct this.

If I add the following line into my source file:
Code:
#!/usr/bin/build303 -full -cleanup -op -exec

Then I get the error message:
Code:
Error: unrecognized switch '-full -cleanup -op -exec'

I think this is because the shell passes these arguments as one argument, not as four.
Back to top
View user's profile Send private message
Derek Parnell



Joined: 22 Apr 2004
Posts: 408
Location: Melbourne, Australia

PostPosted: Mon Oct 02, 2006 11:48 am    Post subject: Re: #! on linux Reply with quote

keinfarbton wrote:
#! is also called shebang or hashbang.

I tried to use build/bud on linux with the shells #! syntax, but I can't get it to run.

This feature would be very useful on linux


So programs that support the '#!' must do their own command line parsing. Sort of defeats the purpose of the shell. Anyhow, I was not aware of this restriction. I'll add support for #! to Build.

BTW, the "-exec" does not have to go anywhere in particular.
_________________
--
Derek
skype name: derek.j.parnell
Back to top
View user's profile Send private message
keinfarbton



Joined: 03 Dec 2005
Posts: 224
Location: Stuttgart - Germany

PostPosted: Mon Oct 02, 2006 12:48 pm    Post subject: Reply with quote

Cool, thx.
Back to top
View user's profile Send private message
pragma



Joined: 28 May 2004
Posts: 607
Location: Washington, DC

PostPosted: Mon Oct 02, 2006 2:03 pm    Post subject: Re: #! on linux Reply with quote

Derek Parnell wrote:
keinfarbton wrote:
#! is also called shebang or hashbang.

I tried to use build/bud on linux with the shells #! syntax, but I can't get it to run.

This feature would be very useful on linux


So programs that support the '#!' must do their own command line parsing. Sort of defeats the purpose of the shell. Anyhow, I was not aware of this restriction. I'll add support for #! to Build.

BTW, the "-exec" does not have to go anywhere in particular.


Derek, just an idea out of the blue: would it make sense to pass arguments to build via a pragma() instead?

Code:
version(build) pragma(options,"-full -cleanup -op -exec");


Or something similar? It's really not so dissimilar than using the shebang line, only this way, it's more flexible. Smile
_________________
-- !Eric.t.Anderton at gmail
Back to top
View user's profile Send private message Yahoo Messenger
keinfarbton



Joined: 03 Dec 2005
Posts: 224
Location: Stuttgart - Germany

PostPosted: Mon Oct 02, 2006 3:12 pm    Post subject: Reply with quote

I like this idea too.

For a first version - to get some experience with this feature - one could have the user to split the args:
Code:
#!/usr/bin/bud
version(build){
  pragma(options,"-full");
  pragma(options,"-cleanup");
  pragma(options,"-op");
  pragma(options,"-exec");
}
....

I see only one difficulty. Not related to the pragmas...
It should also be possible to give the user-program args on command line, the caller shall use this like a compiled program.
Code:
frank@linux:~/$ ./mysource.d arg1 arg2=3

Now build/bud is called with this arg-list:
Code:
"/usr/bin/bud", "./mysource.d", "arg1" "arg2=3"

How can build/bud know that this is an argument for the user-program?
Back to top
View user's profile Send private message
Derek Parnell



Joined: 22 Apr 2004
Posts: 408
Location: Melbourne, Australia

PostPosted: Mon Oct 02, 2006 3:56 pm    Post subject: Re: #! on linux Reply with quote

pragma wrote:

Derek, just an idea out of the blue: would it make sense to pass arguments to build via a pragma() instead?

Code:
version(build) pragma(options,"-full -cleanup -op -exec");


Or something similar? It's really not so dissimilar than using the shebang line, only this way, it's more flexible. Smile

This has been on the TODO list for awhile. It's not hard to get the args, but I have to reorganize the structure of the program's logic flow. Currently, it gathers all the switches and arguments, then runs the compiler etc... With this change, I'll have to be able to run the compiler for different sets of 'command line' arguments.

I want to do this but it might not show up until v4.0
_________________
--
Derek
skype name: derek.j.parnell
Back to top
View user's profile Send private message
Derek Parnell



Joined: 22 Apr 2004
Posts: 408
Location: Melbourne, Australia

PostPosted: Mon Oct 02, 2006 3:59 pm    Post subject: Reply with quote

keinfarbton wrote:

I see only one difficulty. Not related to the pragmas...
It should also be possible to give the user-program args on command line, the caller shall use this like a compiled program.
Code:
frank@linux:~/$ ./mysource.d arg1 arg2=3

Now build/bud is called with this arg-list:
Code:
"/usr/bin/bud", "./mysource.d", "arg1" "arg2=3"

How can build/bud know that this is an argument for the user-program?

Currently you can give the args on the -exec switch, but I see your point. I'll add a new switch "-execargs" with which you can pass arguments to the compiled program when Build runs it via "-exec".
_________________
--
Derek
skype name: derek.j.parnell
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Build All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group