-
Notifications
You must be signed in to change notification settings - Fork 96
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
Draft: Runtime Dependency Checker (RDC) #107
Conversation
im feeling like RDC's first line might be treated as shebang like
Really good job implementing this @b1ek! Here is some bug that I found. When I ran this code that used a standard library function It seems that it uses a predefined variable to set the IFS (Internal Field Separator) for just this command. Can we detect if a command is setting some variable before running something else? If so then can we find the real command? If not then we could omit or emit some kind of warning perhaps that the RDC is disabled for this command. The bad part is that the variable assignment could be like this: let command = "echo"
${command} "Hello World"$ |
im not sure that a thing like that can be caught compile time, without rethinking the type system. perhaps we could create a type that would only allow certain strings, such as in typescript: let cmd: 'echo' | 'curl'; and then check for all those strings in RDC. but all of that seems as too much work for too little gain. my opinion is to let the user know that if they are specifying a command dynamically, RDC won't catch it. a workaround is possible:
|
actually, it would be pretty neat to add a compiler flag to tell RDC what other commands should it check for, without impacting the output file |
you're right. this one should match any valid bash syntax: i love writing regex. |
done | ||
|
||
if (( ${#AMBER_RDC_MD[@]} != 0 )); then | ||
>&2 echo This program requires for these commands: \( $AMBER_RDC_MD \) to be present in \$PATH. |
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.
The "for" in here breaks the english grammar. "This program requires these commands:" would be more correct.
@@ -49,6 +49,9 @@ impl TranslateModule for CommandStatement { | |||
let interps = self.interps.iter() | |||
.map(|item| item.translate(meta)) | |||
.collect::<Vec<String>>(); | |||
|
|||
scan_append_externs(self.strings.clone(), meta); |
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 think this is probably not something we want to try and do. Trying to understand all of the dependencies that a script relies on is a big ask. There could be dependencies that are set based on environment variables, the script could change the $PATH
adding new things that were previously not present.
I think that in this initial pass we should add support for the Amber runtime dependencies. If we really want to provide this affordance to Amber users then it seems like it would be best to add a library function they can call to explicitly call out a dependency they want to check for.
In that way the script checks for the pieces that it depends on and then it provides a way for script uathors to do something siimlar.
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.
Oh yeah. That's actually a good point that people could add things later on in the script to the $PATH
. For now let's just leave it as a precheck for making sure that Amber script can at least run.
i feel like this should be maintained as a separate project, so it would work with any bash file, with a possibility of integrating it into amber later |
We should continue this discussion on Github Discussions that I'll create this evening. This PR is great and I think we can leave the basic RDC for Amber itself. I'd remove the REGEX parsing of commands to search for the dependencies or I'd move them to a separate project. But I think that we need to discuss this whole idea first. |
By the way, wouldn't it be better to merge the following commit as a separate PR? |
yeah, i agree with that. opening a new PR now |
implemented in #383 |
turns out implementing this wasn't as complicated as i thought.
features added:
cargo test
s--disable-rdc
possible caveats:
regex
crate is added as well. It may increase the compiler binary size, but shouldn't be much.AMBER_RDC_RD
andAMBER_RDC_CD
known issues:
unsafe $...$
blocks. I think its an issue to discuss, whether to ignoreunsafe
commands or create a new keyword for disabling RDC on one specific command.Closes #95