-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
Run Nix setup.sh? #26
Comments
FYI @lheckemann |
Awesome, thanks! I'll see if I can find the time to contribute some of this functionality myself. |
OK great I'm going to tackle the parsing stuff first, so:
The |
Note that we accept flags but don't do anything with them yet. The variable is known to be an array from the RHS, not LHS. We might have to parse these dynamically later, as with 'export', but so far all usages are static. Addresses issue #26.
Extract EvalLhs function and share it. Still need to parse LHS indexing, e.g. a[x]+=b. Addresses issue #26.
Note on last bullet point. This works fine:
The LST doesn't preserve the grouping parentheses, but that's (maybe) an issue for conversion and not execution. |
@lheckemann If you pull master, the setup.sh should parse now, with:
It doesn't run yet though -- failing on the shopt builtin. Also, I believe these lines in isELF and isScript:
should be replaced with:
The pattern they're using is "open to fd", then "read -u $fd", then "close $fd". There's no point to this as you can just redirect the stdin of (This similar to the point here [1] I made about [1] https://www.reddit.com/r/oilshell/comments/6kygto/osh_runs_real_shell_programs/djr8ier/ OSH is still pretty far from running this script, so I wouldn't change it for OSH. But if there is a decent way of testing it, maybe someone wants to change it for readability / simplicity / slight efficiency. I'm going to put off the |
Great! I'll take a look at implementing some of the missing functionality as soon as I've managed to get oil building from the repo. |
wrt printf — I noticed that on my NixOS system (with coreutils 8.26)
Meanwhile on an old debian system (coreutils 8.23)
So depending on the coreutils version, support for |
OK good point about I'm not opposed to a full printf builtin, but it's a fair amount of work that probably doesn't have to block this. |
Oh also make sure you can run say
|
My favorite bash oddity is the hardly-believable |
Details: - Implement LooksLikeGlob() with unit tests Other: - Add a stub/test for 'shopt -s failglob too', but it's not implemented. - Fix up comments in core/glob_.py Addresses issue #26.
Details: - Implement LooksLikeGlob() with unit tests Other: - Add a stub/test for 'shopt -s failglob too', but it's not implemented. - Fix up comments in core/glob_.py Addresses issue #26.
Hm wow I didn't know about That's very similar to issue #3, which is runtime parsing of arithmetic expressions inside strings. Bash is very confused about data vs. code. I think this is basically because That is, |
|
Polish var-ref tests. Addresses issue #26.
@andychu I just learned variable expansion is array + $ declare -a 'foo=("$bar")'; set | grep foo
_='foo=("$bar")'
foo=([0]="") $ declare -a 'foo="$bar"'; set | grep foo
_='foo="$bar"'
foo=([0]="\"\$bar\"") $ declare +a 'foo=("$bar")'; set | grep foo
_='foo=("$bar")'
foo='("$bar")' |
Interesting examples. I haven't encountered stuff like this in the wild, but I think I get what's going on there, if not why. The
This would make a great post for "Bash: the Awful Parts" but I'm intentionally concentrating on OSH/Oil over the blog. But if I get Oil done and need to justify it, there is a great example :) Right now OSH doesn't have an array attribute of a cell/location -- it only has The problem is that bash has two ways to express an array -- That is,
This doesn't work in bash but it has no ambiguity. It's a little more Python-like, where objects have types, not variables. Thanks for the examples! |
The "type" of an undefined variable is observable here: $ declare -i a
$ a+=' 1'
$ echo "$a"
1
$ a+=' 1'
$ echo "$a"
2 I fear bash is poorly designed to the point where almost all internal implementation details are not abstracted way. |
Hm that's another good one. And note that I hope that OSH doesn't have to implement these flags to make real programs run, but I saved them here in case: https://github.com/oilshell/oil/blob/master/spec/type-compat.test.sh Nix is definitely using some nooks and crannies of bash, but nothing too insane. The eval / var ref stuff is a little odd but I think it should work in OSH. I understand https://github.com/oilshell/oil/blob/master/spec/var-ref.test.sh If you have any slightly easier bash scripts to run I would be interested in those too :) |
Also make note of a var-ref issue where $? is not dynamic. Addresses issue #26.
FYI I turned the http://www.oilshell.org/blog/2017/08/12.html tl;dr isELF and isScript in https://github.com/oilshell/blog-code/blob/master/hard-coded-descriptors/demo.sh#L24 |
Re: |
There are two strategies, depending on the pattern. 1) Fixed strings use Python's string methods, e.g. startswith/endswith/replace/slice. 2) Glob patterns are converted to Python regexes. (Character classes aren't currently supported.) Then we use the regex engine for position information and greedy/non-greedy matches. Also: - Added tests. - Fix parsing. - TODO: Unicode Addresses issue #26.
@andychu I rewrote |
@Ericson2314 There is no problem with using The way
Nothing but I think this wasn't have been entirely clear to me before writing a shell, but it's clear now. Demo here: oils-for-unix/blog-code@f61ff5c
EDIT: Rewrite of somewhat related example from Reddit: |
I learned that the [ language isn't really specified by a grammar, as [[ is. Instead we handle it like bash does: by splitting it into 6 cases: expressions of length 0, 1, 2, 3, 4, and more. The bash source implies that POSIX specifies this. And it explains why -a and -o are deprecated. I'm not supporting -a as a unary operator, since it's an alias for -e. I also added a couple test cases to dbracket.test.sh, and fixed some syntax error handling bugs in [[. NOTE: There's still a bug where [ abc = 'a*' ] should not support globbing. Addresses issue #19 and issue #26.
Used by setup.sh in Nix. Addresses issue #26.
We can print options in two formats, as well as set the options from the 'set' builtin. There are still a few cases left to do, like 'set -o'. - Tests for shopt -p and shopt -po Addresses issue #26.
@Ericson2314 I noticed this commit where you noted:
but you say this happens only on old versions of bash? Do you have a new version of bash where it doesn't happen? This came up on the bash mailing list: http://lists.gnu.org/archive/html/help-bash/2017-09/threads.html I get this undesired behavior in bash 4.3, and your workaround works. Just curious where you found this or if you came up with it... it is not obvious to me!
|
I released OSH 0.1 with all these bug fixes: http://www.oilshell.org/blog/2017/09/09.html There are a few issues left, as noted at the top, but I'm putting them on the back burner for now. I'd appreciate any more bug reports or feedback on what distros want from a shell. (And patches appreciated too, although I fixed most of the low-hanging fruit) I know it is slow and unpolished, so I'd like to add something you can't get from bash in the near term. I was thinking of adding of adding better debugging features:
(The other place it's already better than bash is I think the initial use case for OSH is building Linux distros, i.e. large shell programs (as opposed to interactive usage). I think I will concentrate on Alpine Linux for the next release, because it's very small, but I'm still interested in feedback from Nix maintainers and users. (BTW I also discovered on the mailing list that bash 4.4 fixed the |
@lheckemann @Ericson2314 Wondering if you guys had any feedback on this? Sorry if this issue got pinged a lot an overwhelmed your mailbox. I'm not sure if it sends notifications when I edit the top-level comment, which I did a lot. |
No worries, thanks for keeping me up to date! I've been busy with other stuff lately, but have just tried running it again. I discovered a bug (#40 includes a test that demonstrates it). This results in the line The script still fails overall, in a rather odd way… in the runHook function, we have the following lines:
This fails after "shift" with the message
(it would be useful if code loaded with |
Thanks for finding that! I just replied to the pull request. What's the command I can reproduce this with? I was running
Also, I should say it might be time to port the spec tests to run in a chroot with busybox, so we can all have the exact same environment. Ironically, the spec tests themselves illustrate a big problem with shell -- Linux distros vary widely. I don't want you to have to fix up a million issues before even getting started and that looks like where it's going... Linux Standard Base was supposed to solve this but it failed. I think containers/chroots are the modern answer, and every distro can run them. I have been playing with Alpine Linux, and I really like the 4 MB chroot ... it seems useful in contexts in addition to the spec tests, like generating docs that include code snippet output and so forth. |
Sorry, I think the failure wasn't actually on that line after all. My best guess is that it's related to the "Hack around old bash being bad and thinking empty arrays are undefined." on the lines after, which is a bit mind-bending. I'll see if I can figure out a minimal test case for it. |
Update: I'm just a bit of an idiot and mistook rebuilding a bunch of stuff for everything working. The same error still occurs with the |
@lheckemann I didn't follow that last part, but please try again after the fix I just made and let me know what the current error is.
|
TODO: Try building "hello" package with Nix as described here: https://www.reddit.com/r/oilshell/comments/7qn0p8/success_with_aboriginal_alpine_and_debian/dsrnp0q/ Now that I look at this bug again, the |
I checked off a few more things on this dormant issue. We're now using this page to prioritize: https://github.com/oilshell/oil/wiki/Shell-Programs-That-Run-Under-OSH |
Knock off test case #26 in spec/prompt, contributed by Simon Leary. (Unrelated comments about HTM8)
Hm this uses several (ugly) bash features not implemented in Oil:
We should definitely be able to parse it -- running it will take some work.
trap
builtincase "$(type -t "$hookName")" in
fails in OSH because we respecterrexit
in command sub, but bash doesn'tfor i in "${nativePkgs[@]}"; do
-- OSH doesn't allow indexing empty var/string with [@]type
builtin (should be easy, only need-t
)read
flags: -r, -n etc. (but lack of-r
not implemented)oldOps="$(shopt -po nounset)"; ...; eval "$oldOpts"
(use case for "with" in Oil)setup.sh
has same issue as Gentoo in issue Implement [ #19, trying to run[
with empty$PATH
test -x
content="${content//"$pattern"/$replacement}"
${FUNCNAME[@]}
${!varRef}
-- completion scripts also use thisshopt -s nullglob
local -a times=(...)
(unparsed)declare -a
(unparsed)eval "$var"'+=("$pkg")'
(unparsed)if [[ -z "$makeFlags" && ! ( -n "$makefile" || -e Makefile || -e makefile || -e GNUmakefile[[ ) ]]
Deferred:
exec {fd}< "$fn"
(unparsed)exec {fd}<&-
(unparsed)printf
builtin --%q
is used, but external command should be OKhttps://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/generic/setup.sh#L318
The text was updated successfully, but these errors were encountered: