Coder Social home page Coder Social logo

oilshell / oil Goto Github PK

View Code? Open in Web Editor NEW
2.7K 36.0 143.0 42.75 MB

Oils is our upgrade path from bash to a better language and runtime. It's also for Python and JavaScript users who avoid shell!

Home Page: http://www.oilshell.org/

License: Other

Python 57.13% C 32.92% Shell 4.59% C++ 1.35% CSS 0.07% HTML 0.35% JavaScript 0.04% Makefile 0.41% Batchfile 0.01% Roff 0.47% PLSQL 0.05% M4 0.45% Assembly 1.26% TeX 0.69% DIGITAL Command Language 0.06% R 0.14% VBScript 0.01% Nix 0.01% GDB 0.01%

oil's Introduction

Oils Source Code

Build Status Contribute with Gitpod

Oils is our upgrade path from bash to a better language and runtime!

  • OSH runs your existing shell scripts.
  • YSH is for Python and JavaScript users who avoid shell.

(The project was slightly renamed in March 2023, so there are still old references to "Oil". Feel free to send pull requests with corrections!)

Oils 2023 FAQ / Why Create a New Unix Shell?

It's written in Python, so the code is short and easy to change. But we automatically translate it to C++ with custom tools, to make it fast and small. The deployed executable doesn't depend on Python.

This README is at the root of the git repo.

Contributing

  • Try making the dev build of Oils with the instructions on the Contributing page. This should take 1 to 5 minutes if you have a Linux machine.
  • If it doesn't, let us know. You can post on the #oil-dev channel of oilshell.zulipchat.com, or file an issue on Github.
  • Feel free to grab an issue from Github. Let us know what you're thinking before you get too far.

Quick Start on Linux

After following the instructions on the Contributing page, you'll have a Python program that you can quickly run and change! Try it interactively:

bash$ bin/osh

osh$ name=world
osh$ echo "hello $name"
hello world
  • Try running a shell script you wrote with bin/osh myscript.sh.
  • Try YSH with bin/ysh.

Let us know if any of these things don't work! The continuous build tests them at every commit.

Dev Build vs. Release Build

Again, note that the developer build is very different from the release tarball. The Contributing page describes this difference in detail.

The release tarballs are linked from the home page. (Developer builds don't work on OS X, so use the release tarballs on OS X.)

Important: We Accept Small Contributions!

Oils is full of many ideas, which may be intimidating at first.

But the bar to contribution is very low. It's basically a medium size Python program with many tests, and many programmers know how to change such programs. It's great for prototyping.

  • For OSH compatibility, I often merge failing spec tests. You don't even have to write code! The tests alone help. I search for related tests with grep xtrace spec/*.test.sh, where xtrace is a shell feature.
  • You only have to make your code work in Python. Plain Python programs are easy to modify. The semi-automated translation to C++ is a separate step, although it often just works.
  • You can influence the design of YSH. If you have an itch to scratch, be ambitious. For example, you might want to show us how to implement nonlinear pipelines.

I aim for 24 hour response time

Please feel free to ping andychu on Zulip or Github if you're waiting for a pull request review! (or to ask questions)

Usually I can respond in 24 hours. I might be traveling, in which case I'll respond with something like I hope to look at this by Tuesday.

I might have also missed your Github message, so it doesn't hurt to ping me.

Thank you for the contributions!

Docs

The Wiki has many developer docs. Feel free to edit them. If you make a major change, let us know on Zulip!

There are also READMEs in some subdirectories, like opy/ and mycpp/.

If you're confused, the best thing to do is to ask on Zulip and someone should produce a pointer and/or improve the docs.

Docs for end users are linked from each release page.

Repository Structure

Try this to show a summary of what's in the repo and their line counts:

$ metrics/source-code.sh overview

(Other functions in this file may be useful as well.)

A Collection of Interpreters

Oils is naturally structured as a set of mutually recursive parsers and evaluators. These interpreters are specified at a high-level: with regular languages, Zephyr ASDL, and a statically-typed subset of Python.

bin/              # Main entry points like bin/osh (source in bin/oils_for_unix.py)
frontend/         # Input and lexing common to OSH and YSH
osh/              # OSH parsers and evaluators (cmd, word, sh_expr)
ysh/              # YSH parser and evaluator
data_lang/        # Languages based on JSON
builtin/          # Builtin commands and functions
core/             # Other code shared between OSH and YSH
pyext/            # Python extension modules, e.g. libc.c
pylib/            # Borrowed from the Python standard library.
tools/            # User-facing tools, e.g. the osh2oil translator

DSLs / Code Generators

Here are the tools that transform that high-level code to efficient code:

asdl/             # ASDL implementation, derived from CPython
pgen2/            # Parser Generator, borrowed from CPython
mycpp/            # Experimental translator from typed Python to C++.
                  # Depends on MyPy.  See mycpp/README.md
pea/              # Perhaps a cleaner version of mycpp
opy/              # Python compiler in Python (mycpp/ will replace it)

Native Code and Build System

We have native code to support both the dev build (running under CPython) and the oils-for-unix build (pure C++):

NINJA-config.sh   # Generates build.ninja

build/            # High level build
  NINJA-steps.sh
  NINJA_main.py   # invoked by NINJA-config.sh
  NINJA_subgraph.py
  oil-defs/       # Files that define our slice of CPython.
  py.sh           # For development builds, running CPython
cpp/              # C++ code which complements the mycpp translation
  NINJA-steps.sh
  NINJA_subgraph.py
mycpp/            # Runtime for the translator
  NINJA-steps.sh
  NINJA_subgraph.py

prebuilt/         # Prebuilt files committed to git, instead of in _gen/

Python-2.7.13/    # For the slow Python build

# Temp dirs (see below)
_bin/
_build/
_gen/
_test/

Several Kinds of Tests

Unit tests are named foo_test.py and live next to foo.py.

test/             # Test automation
  gold/           # Gold Test cases
  gold.sh         
  sh_spec.py      # shell spec test framework
  spec.sh         # Types of test runner: spec, unit, gold, wild
  unit.sh         
  wild.sh
testdata/
spec/             # Spec test cases
  bin/            # tools used in many spec tests
  testdata/       # scripts for specific test cases
  stateful/       # Tests that use pexpect

Dev Tools and Scripts

We use a lot of automation to improve the dev process. It's largely written in shell, of course!

benchmarks/       # Benchmarks should be run on multiple machines.
metrics/          # Metrics don't change between machines (e.g. code size)
client/           # Demonstration of OSH as a headless server.
deps/             # Dev dependencies and Docker images
devtools/         # For Oils developers (not end users)
  release.sh      # The (large) release process.
  services/       # talk to cloud services
demo/             # Demonstrations of bash/shell features.  Could be
                  # moved to tests/ if automated.
  old/            # A junk drawer.
web/              # HTML/JS/CSS for tests and tools
soil/             # Multi-cloud continuous build (e.g. sourcehut, Github)

Temp Dirs

Directories that begin with _ are not stored in git. The dev tools above create and use these dirs.

_bin/             # Native executables are put here
  cxx-dbg/
_build/           # Temporary build files
_cache/           # Dev dependency tarballs
_devbuild/        # Generated Python code, etc.
_gen/             # Generated C++ code that mirrors the repo
  frontend/
_release/         # Source release tarballs are put here
  VERSION/        # Published at oilshell.org/release/$VERSION/
    benchmarks/
    doc/
    metrics/
    test/
      spec.wwz
      wild.wwz
      ...
    web/          # Static files, copy of $REPO_ROOT/web
      table/
_test/            # Unit tests, mycpp examples
  tasks/
_tmp/             # Output of other test suites; temp files
  spec/
  wild/
    raw/
    www/
  osh-parser/
  osh-runtime/
  vm-baseline/
  oheap/
  startup/
  ...

Build Dependencies in ../oil_DEPS

These tools are built from shell scripts in soil/. The oil_DEPS dir is "parallel" to Oils because it works better with container bind mounds.

../oil_DEPS/
  re2c/           # to build the lexer
  cmark/          # for building docs
  spec-bin/       # shells to run spec tests against
  mypy/           # MyPy repo
  mycpp-venv/     # MyPy binaries deps in a VirtualEnv

  py3/            # for mycpp and pea/
  cpython-full/   # for bootstrapping Oils-CPython

Build System for End Users version.

These files make the slow "Oils Python" build, which is very different than the developer build of Oils.

Makefile
configure
install

These files are for the C++ oils-for-unix tarball (in progress):

_build/
  oils.sh

Doc Sources

doc/              # A mix of docs
doctools/         # Tools that use lazylex/ to transform Markdown/HTML
lazylex/          # An HTML lexer which doctools/ builds upon.
README.md         # This page, which is For Oils developers

LICENSE.txt       # For end users
INSTALL.txt

More info

There are README files in many subdirectories, like mycpp/README.md.

oil's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oil's Issues

Polish Parse Error Message Appearance

They're a little ugly now, e.g.

$ bin/osh -c 'source bad.sh'
osh error: Parse error in 'bad.sh':
Line 1 of 'bad.sh'
  echo >
        ^
Expected word after redirect operator
---
Line 0 of '<unknown>'
  <no position info for token>
Error parsing AndOr in ParseCommandTerm
---

Allow easy installation

I attempted to try and create an Arch Linux PKGBUILD for this project and realized that setup.py install only installs python libc, and not oil. Could this be fixed?

allow use as library

this would allow python tools that provide toy-ish shell subsets (like tox for example)
to provide a real shell language without implementing an own

cd fails when called without a parameter

$ ./_bin/oil.ovm osh
osh$ cd
Traceback (most recent call last):
  File "/home/andy/git/oil/Python-2.7.13/Lib/runpy.py", line 174, in _run_module_as_main
  File "/home/andy/git/oil/Python-2.7.13/Lib/runpy.py", line 72, in _run_code
  File "/home/andy/git/oil/bin/oil.py", line 440, in <module>
  File "/home/andy/git/oil/bin/oil.py", line 427, in main
  File "/home/andy/git/oil/bin/oil.py", line 410, in OilMain
  File "/home/andy/git/oil/bin/oil.py", line 311, in OshMain
  File "/home/andy/git/oil/bin/oil.py", line 122, in InteractiveLoop
  File "/home/andy/git/oil/bin/../core/cmd_exec.py", line 892, in Execute
  File "/home/andy/git/oil/bin/../core/cmd_exec.py", line 856, in _Execute
  File "/home/andy/git/oil/bin/../core/cmd_exec.py", line 674, in _Dispatch
  File "/home/andy/git/oil/bin/../core/cmd_exec.py", line 885, in _ExecuteList
  File "/home/andy/git/oil/bin/../core/cmd_exec.py", line 856, in _Execute
  File "/home/andy/git/oil/bin/../core/cmd_exec.py", line 584, in _Dispatch
  File "/home/andy/git/oil/bin/../core/cmd_exec.py", line 473, in _RunSimpleCommand
  File "/home/andy/git/oil/bin/../core/cmd_exec.py", line 214, in _RunBuiltin
  File "/home/andy/git/oil/bin/../core/builtin.py", line 406, in _Cd
IndexError: list index out of range

OSH should be smarter about calling execvpe()

execvpe() apparently results in a lot of execve() calls, which other shells don't do. Is this related to caching?

~/git/alpine/abuild$ strace -ff -e fork,execve  -- ~/git/oil/bin/osh -c 'ls /'                              
execve("/home/andy/git/oil/bin/osh", ["/home/andy/git/oil/bin/osh", "-c", "ls /"], [/* 75 vars */]) = 0
execve("/usr/local/sbin/python", ["python", "/home/andy/git/oil/bin/osh", "-c", "ls /"], [/* 75 vars */]) = -1 ENOENT (No such file or directory)
execve("/usr/local/bin/python", ["python", "/home/andy/git/oil/bin/osh", "-c", "ls /"], [/* 75 vars */]) = -1 ENOENT (No such file or directory)
execve("/usr/sbin/python", ["python", "/home/andy/git/oil/bin/osh", "-c", "ls /"], [/* 75 vars */]) = -1 ENOENT (No such file or directory)
execve("/usr/bin/python", ["python", "/home/andy/git/oil/bin/osh", "-c", "ls /"], [/* 75 vars */]) = 0
strace: Process 24347 attached
[pid 24347] execve("/usr/local/sbin/ls", ["ls", "/"], [/* 75 vars */]) = -1 ENOENT (No such file or directory)
[pid 24347] execve("/usr/local/bin/ls", ["ls", "/"], [/* 75 vars */]) = -1 ENOENT (No such file or directory)
[pid 24347] execve("/usr/sbin/ls", ["ls", "/"], [/* 75 vars */]) = -1 ENOENT (No such file or directory)
[pid 24347] execve("/usr/bin/ls", ["ls", "/"], [/* 75 vars */]) = -1 ENOENT (No such file or directory)
[pid 24347] execve("/sbin/ls", ["ls", "/"], [/* 75 vars */]) = -1 ENOENT (No such file or directory)
[pid 24347] execve("/bin/ls", ["ls", "/"], [/* 75 vars */]) = 0
bin   cdrom  etc   initrd.img      lib    lib64       media  opt   root  sbin  srv  tmp  var      vmlinuz.old
boot  dev    home  initrd.img.old  lib32  lost+found  mnt    proc  run   snap  sys  usr  vmlinuz

vs.  dash and bash

~/git/alpine/abuild$ strace -ff -e fork,execve  -- bash -c 'ls /'                                           
execve("/bin/bash", ["bash", "-c", "ls /"], [/* 75 vars */]) = 0
execve("/bin/ls", ["ls", "/"], [/* 74 vars */]) = 0
bin   cdrom  etc   initrd.img      lib    lib64       media  opt   root  sbin  srv  tmp  var      vmlinuz.old
boot  dev    home  initrd.img.old  lib32  lost+found  mnt    proc  run   snap  sys  usr  vmlinuz

Set up auto-formatting of Python

While exploring the code, I couldn't help but notice that the code style is not pep8 compliant. Following the standard way of writing code is very advantageous as it allow for gentle learning curve for someone how wants to contribute to the project.

Build fails without readline

Even if readline is correctly detected as absent, app_deps.py will fail when called by scripts/release.sh oil to determine oil's dependencies as it tries (and fails) to import readline unconditionally — even if the module wasn't built because the C library was missing.

[osh] arithmetic evaluation context in test clause

If you use the test compound command with arithmetic binary operators, there is also a whole let expression available. In bash you can write stuff like:

[[ ('(x=5, y[10]+=5), x*=y[10]' -eq x) && y[2]==y[10]?1:0 -eq 0 ]];
s=$? declare -p s x y;

osh gives me an AssertionError then.

cd not yet working

Right now, when I run bin/osh, ls works, but cd either does nothing, or fails because it cannot find the cd executable, depending on if I am running on OSX or Ubuntu 14.04

bash parses array literal after eval but OSH doesn't

Test case (extracted from a large shell script used by my employer):

#!/bin/bash
component=foo
foo_tasks=(a b c)
eval tasks=(\${${component}_tasks[@]})
echo "${tasks[@]}"

Result with osh 0.3.0:

Line 4 of 'arrlit.sh'
  eval tasks=(\${${component}_tasks[@]})
       ^~~~~~
Unexpected array literal: (CompoundWord
  parts: [
    (ArrayLiteralPart
      words: [
        (CompoundWord
...

Result with bash 4.3.32:

a b c

JFYI...

`help` builtin crashes OSH when argument is passed

Any time I pass an argument to the help builtin, OSH crashes. It's also a bit odd because it explicitly has "/home/andy" in the error message.

$>   # I'm in bash here
$> osh --version
Oil version 0.2.0
Release Date: 2017-11-09 05:50:32+00:00
Arch: x86_64
OS: Linux
Platform: #1 SMP PREEMPT Wed Nov 8 11:54:06 CET 2017
Compiler: GCC 7.2.0
Interpreter: OVM
Interpreter version: 2.7.13
$>   # Dropping into OSH now
$> osh
$osh> help
Usage:
  help <topic>   -- show help on a given topic
  help toc       -- list help topics
  help osh-usage -- same as osh --help
  help oil-usage -- same as oil --help

View on the web: http://www.oilshell.org/$VERSION/doc/osh-quick-ref.html

$osh> help echo
Traceback (most recent call last):
  File "/home/andy/git/oilshell/oil/Python-2.7.13/Lib/runpy.py", line 174, in _run_module_as_main
  File "/home/andy/git/oilshell/oil/Python-2.7.13/Lib/runpy.py", line 72, in _run_code
  File "/home/andy/git/oilshell/oil/bin/oil.py", line 475, in <module>
  File "/home/andy/git/oilshell/oil/bin/oil.py", line 458, in main
  File "/home/andy/git/oilshell/oil/bin/oil.py", line 441, in OilMain
  File "/home/andy/git/oilshell/oil/bin/oil.py", line 329, in OshMain
  File "/home/andy/git/oilshell/oil/bin/oil.py", line 131, in InteractiveLoop
  File "/home/andy/git/oilshell/oil/bin/../core/cmd_exec.py", line 969, in Execute
  File "/home/andy/git/oilshell/oil/bin/../core/cmd_exec.py", line 933, in _Execute
  File "/home/andy/git/oilshell/oil/bin/../core/cmd_exec.py", line 743, in _Dispatch
  File "/home/andy/git/oilshell/oil/bin/../core/cmd_exec.py", line 962, in _ExecuteList
  File "/home/andy/git/oilshell/oil/bin/../core/cmd_exec.py", line 933, in _Execute
  File "/home/andy/git/oilshell/oil/bin/../core/cmd_exec.py", line 623, in _Dispatch
  File "/home/andy/git/oilshell/oil/bin/../core/cmd_exec.py", line 511, in _RunSimpleCommand
  File "/home/andy/git/oilshell/oil/bin/../core/cmd_exec.py", line 312, in _RunBuiltin
  File "/home/andy/git/oil/bin/../core/builtin.py", line 866, in Help
KeyError: 'echo'
FATAL: couldn't import from app bundle '/home/timetoplatypus/Documents/archBuilds/osh/pkg/osh/usr/bin/oil.ovm' (1)
Stripping the oil.ovm binary may cause this error.
See https://github.com/oilshell/oil/issues/47
$>   # OSH has crashed and I'm back in bash here

A little list of build issues

A couple of small issues related to distribution and packaging. This would ideally be handled on IRC but it appears oilshell doesn't advertise a channel anywhere I could find.

Currently using the commit a6bc98e

So far this in my experience trying to build this software. I start with ./configure --help which tells me I can use --with-readline and it appears to support the --prefix mechanism.

Running the command ./configure --prefix=/usr --with-readline simply exits with a return status of 1.

When using sh -x (since the script defines itself to be /bin/sh) it seems to show the intended error indicating a failure to detect readline:

+ FLAG_prefix=/usr/local
+ FLAG_with_readline=
+ FLAG_without_readline=
+ true
+ case "$1" in
++ expr --prefix=/usr : '--prefix=\(.*\)'
+ FLAG_prefix=/usr
+ shift
+ true
+ case "$1" in
+ FLAG_with_readline=1
+ shift
+ true
+ case "$1" in
+ break
+ main
+ cc_quiet build/detect-cc.c
+ cc build/detect-cc.c -o /dev/null
+ mkdir -p _build
+ local out=_build/detected-config.sh
+ detect_and_echo_vars
+ test '' = 1
+ detect_readline
+ cc_quiet build/detect-readline.c -l readline
+ cc build/detect-readline.c -l readline -o /dev/null
+ test 1 = 1
+ die 'readline was not detected on the system (--with-readline passed).'
+ echo './configure ERROR: readline was not detected on the system (--with-readline passed).'
+ exit 1

This appears to be due to the detect-readline.c not including the relevant headers as documented in the manual (at least for readline 7.0):
I wish readline would get a .pc file...

diff --git a/build/detect-readline.c b/build/detect-readline.c
index 4b85e5d..b27ac29 100644
--- a/build/detect-readline.c
+++ b/build/detect-readline.c
@@ -1,4 +1,6 @@
+#include <stdio.h>
 #include <readline/readline.h>
+#include <readline/history.h>
 
 int main(void) {
   char *line = readline("");

After fixing this the initial ./configure command seems to succeed with the message:

./configure: Wrote _build/detected-config.sh

However when running make I am faced with the following issues:

% make
test -d _build/oil && \
  build/actions.sh app-deps oil ~/git/oil bin.oil
ln: failed to create symbolic link '/home/earnest/git/oil/_tmp': No such file or directory
test -d _build/hello && \
  build/actions.sh app-deps hello build/testdata hello
ln: failed to create symbolic link '/home/earnest/git/oil/_tmp': No such file or directory
make: *** No rule to make target '_build/oil/app-deps-c.txt', needed by '_build/oil/all-deps-c.txt'.  Stop.

This is just a simple laundry list of issues which could have been discussed elsewhere but github seemed like the only place.

Implement command builtin

Running command -v clear, for example, yields the following error message in OSH:

Unexpected error in execvpe('command', ['command', '-v', 'clear'], ...): [Errno 2] No such file or directory

Flaky tests

Test case 23 failed non-deterministically with dash for some reason.

The first time it failed, and then subsequent runs worked. Due to tmp file state?

$ test/spec.sh builtins

23 174 FAIL pass pass pass pass set umask in octal
24 185 pass pass pass FAIL FAIL set umask symbolically
107 passed, 5 ok, 3 known unimplemented, 5 known bugs, 3 failed, 0 skipped

Also, there are some bugs related that only show up when you run the whole test suite in parallel.

Run Nix setup.sh?

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 builtin
  • compatibility issue: case "$(type -t "$hookName")" in fails in OSH because we respect errexit in command sub, but bash doesn't
  • compatibility issue: for 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 #19, trying to run [ with empty $PATH
    • test -x
  • content="${content//"$pattern"/$replacement}"
  • ${FUNCNAME[@]}
  • ${!varRef} -- completion scripts also use this
  • shopt -s nullglob
  • local -a times=(...) (unparsed)
  • declare -a (unparsed)
  • append e.g. eval "$var"'+=("$pkg")' (unparsed)
  • might be tricky: if [[ -z "$makeFlags" && ! ( -n "$makefile" || -e Makefile || -e makefile || -e GNUmakefile[[ ) ]]

Deferred:

  • named file descriptors: exec {fd}< "$fn" (unparsed)
  • closing descriptor: exec {fd}<&- (unparsed)
  • printf builtin -- %q is used, but external command should be OK

https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/generic/setup.sh#L318

Output from "source" unclear on parse error

Given a script foo.sh which osh cannot parse, source foo.sh gives much less helpful information than osh foo.sh, simply outputting the contents of the script rather than describing the errors.

$ cat foo.sh
declare -a foo
$ result/bin/osh -c 'source foo.sh'
Error parsing code 'declare -a foo\n'
$ result/bin/osh foo.sh
Line 1 of 'foo.sh'
  declare -a foo
          ^~
Invalid variable name '-a'
---
Line 0 of '<unknown>'
  <no position info for token>
Error parsing AndOr in ParseCommandTerm
---

Cannot deal with undefined variables

icenowy@x220i [ oil@master ] $ bin/osh
osh$ $a
Traceback (most recent call last):
  File "bin/osh", line 374, in <module>
    sys.exit(main(sys.argv))
  File "bin/osh", line 364, in main
    return OshMain(main_argv)
  File "bin/osh", line 274, in OshMain
    InteractiveLoop(opts, ex, c_parser, w_parser, line_reader)
  File "bin/osh", line 100, in InteractiveLoop
    status, cflow = ex.ExecuteTop(node)
  File "/home/icenowy/git-repos/oil/bin/../core/cmd_exec.py", line 635, in ExecuteTop
    status, cflow = self.Execute(node)
  File "/home/icenowy/git-repos/oil/bin/../core/cmd_exec.py", line 663, in Execute
    raise AssertionError('Error evaluating words: %s' % err)
AssertionError: Error evaluating words: ['Undefined variable a', 'Error evaluating word part (SimpleVarSub token:(token id:VSub_Name val:"$a" span_id:0))', 'Error evaluating word (CompoundWord parts:[(SimpleVarSub token:(token id:VSub_Name val:"$a" span_id:0))])']

But on a standard POSIX sh, the value of undefined variables are just nothing.

spec tests should run in a known environment

There have been some issues with assuming /usr/bin/time, /usr/bin/python, /bin/bash, etc. This seems to be the first issue everybody runs into when developing Oil.

The tests also depend on gawk I think. And the shells: busybox, dash, bash, ash, etc.

Right now I think the best solution is an Alpine Linux chroot, because it's small and easy to set up. Should be runnable on any distro quite easily.

FYI @lheckemann

Also see issue #12

Disambiguate between OpenSolaris Bourne shell "osh" vs. oilshell "osh"

For backwards compatibility, ancient versions of the pre-bash, pre-POSIX Bourne shell, AKA the OpenSolaris Bourne shell, AKA "osh", is available on Linux systems today. The "osh" name for oilshell conflicts with this legacy shell, and so may confuse text editors and other systems. Would it be possible to select another name for the oilshell binary?

OSH build problems on multiple platforms

Most of these are probably because I froze pyconfig.h with Alpine Linux / gcc / musl libc.

TODO: Run on faster virtualized armhf box!

Support declare for checking for function definition

I use the following bashism to determine if a function I need from a dynamically sourced script is available:

    if ! declare -f choose_env > /dev/null; then
        echo "Must have choose_env defined"
        return 1
    fi

However, when I try to run a script that uses this idiom with the 0.3 release, I get the following error:

Unexpected error in execvpe('declare', ['declare', '-f', 'choose_env'], ...): [Errno 2] No such file or directory

It looks like osh doesn't recognize declare as a built-in.

Improve error message when binary is stripped (Assertion error making OSH AUR package)

Hm this is because the ./configure step writes out the PREFIX to _tmp/detected-config.sh. If the file isn't installed to that place, it won't run.

The core issue is that a Unix executable doesn't know where it is run from! The executable has to be set as PYTHONPATH in order to find the bytecode.

https://stackoverflow.com/questions/4031672/without-access-to-argv0-how-do-i-get-the-program-name

$>   export OVM_VERBOSE=1
$>   oil.ovm 
ovm_path = ovm_path_buf (/usr/local/bin/oil.ovm)
ovm_path: /usr/local/bin/oil.ovm
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
oil.ovm: Modules/main.c:347: Ovm_Main: Assertion `sts != -1' failed.
Aborted (core dumped)

In the PKGBUILD, I do execute ./configure and make to compile OSH. I do not, however, invoke the install script that ships with OSH. This is because the PKGBUILD convention dictates that you shouldn’t rely on an external script to actually do the placement of binaries on the system.

The PKGBUILD convention prefers that any binaries that need to be installed on the system be placed within a specific subdirectory beneath wherever the PKGBUILD file is sitting (this is referred to as $pkgdir).

Spec tests fail with ASCII locale ?

This was reported on the mailing list and also here:

https://lobste.rs/s/obktxo/oil_shell_help_needed_if_you_have_debian/comments/akvbsk#c_akvbsk

sh_spec.py needs to read with a known encoding. *.test.sh should be restricted to utf-8 ?

$ ./spec.sh all
./spec-runner.sh run-cases append 
./spec-runner.sh run-cases arith-context 
./spec-runner.sh run-cases arith 
./spec-runner.sh run-cases array 
./spec-runner.sh run-cases assign 
./spec-runner.sh run-cases assoc-zsh 
./spec-runner.sh run-cases assoc 
./spec-runner.sh run-cases blog1 
Traceback (most recent call last):
  File "./sh_spec.py", line 838, in <module>
    sys.exit(main(sys.argv))
  File "./sh_spec.py", line 766, in main
    tokens = Tokenizer(LineIter(f))
  File "./sh_spec.py", line 125, in __init__
    self.next()
  File "./sh_spec.py", line 129, in next
    self.cursor = self.it.__next__()
  File "./sh_spec.py", line 87, in LineIter
    for i, line in enumerate(f):
  File "/usr/lib/python3.4/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 133: ordinal not in range(128)
./spec-runner.sh run-cases brace-expansion 
./spec-runner.sh run-cases bugs 
./spec-runner.sh run-cases builtins 
./spec-runner.sh run-cases case_ 
./spec-runner.sh run-cases command-sub 
./spec-runner.sh run-cases comments 
*** Got 1 allowed osh failures, exit with status 0
./spec-runner.sh run-cases dbracket 
Traceback (most recent call last):
  File "./sh_spec.py", line 838, in <module>
    sys.exit(main(sys.argv))
  File "./sh_spec.py", line 766, in main
    tokens = Tokenizer(LineIter(f))
  File "./sh_spec.py", line 125, in __init__
    self.next()
  File "./sh_spec.py", line 129, in next
    self.cursor = self.it.__next__()
  File "./sh_spec.py", line 87, in LineIter
    for i, line in enumerate(f):
  File "/usr/lib/python3.4/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 2750: ordinal not in range(128)
./spec-runner.sh run-cases dparen 

Efficient `popen` using `clone` trickery (or `posix_spawn`)

Not sure how relevant this is to oil, but I figured it was worth pointing out.

This article describes a way to write popen/system in terms of clone + execve, which is more efficient than the typical implementation in terms of fork + execve. According to the comments, the posix_spawn function in glibc seems to be implemented this way, but apparently has API issues (e.g.: it supposedly doesn't allow you to close all open file handles).

EDIT: this repo is made by the same person, and seems relevant

CSP style asynchronous commands

It's so nice to see that somebody finally designs and implements a proper shell! I absolutely must say that you're awesome and your work is great.

But this issue is not about that but some nice feature of rc shell:

<{command}
>{command}
The command is executed asynchronously with its standard output or standard input connected to a pipe. The value of the argument is the name of a file referring to the other end of the pipe. This allows the construction of non-linear pipelines. For example, the following runs two commands old and new and uses cmp to compare their outputs
cmp <{old} <{new}

It works fine when used like foo <{bar} >{baz}, but when you try to assign <{bar} or >{baz} to variables to use later, problems occur. Also, rc provides no way to create a bidirectional stream.

So I wonder, if can shell have CSP-like streams? Like Go channels or Erlang processes. It would be a really nice feature to have, though I haven't figured out how exactly should it look like.

Problem using OSH as login shell

On an AWS EC2 instance running RedHat 7.3 I set up a user and used chsh to change its login shell to OSH. When I try to log in as that user I get the following:

Usage: oil MAIN_NAME [ARG]...
       MAIN_NAME [ARG]...

oil behaves like busybox.  If it's invoked through a symlink, e.g. 'osh', then
it behaves like that binary.  Otherwise the binary name can be passed as the
first argument, e.g.:

    oil osh -c 'echo hi'


Invalid main '-osh'

Then the connection is closed.

OSH is installed as /usr/local/bin/oil with a symlink from /usr/local/bin/osh . There is an entry in /etc/shells for /usr/local/bin/osh .

I get the same error if I try sudo -i -u $USER or su - $USER .

Contributing uses ssh git url

Right now the contributing doc uses the ssh git URL instead of the https URL. Is this done for any particular reason? I had trouble pulling due to public key permissions, but could pull using the https URL.

Install on Ubuntu 16.04.3 - python 3 set as the default python breaks install script

To be specific, it's in build/quick_ref.py, #!/usr/bin/env python should be #!/usr/bin/env python2

This change may be needed on other files, as you wish.

Also, on a related note, when running build/dev.sh minimal, libc.so is linked to _devbuild/py-ext/x86_64/libc.so but the generated file is _devbuild/py-ext/x86_64/libc.cpython-35m-x86_64-linux-gnu.so. Thus raise an Import Error in native/libc_test.py when doing import libc.

And....on a still related note, when I get the correct libc.so import, I'm getting:

native/libc.c:287:3: warning: implicit declaration of function ‘Py_InitModule’ [-Wimplicit-function-declaration]
   Py_InitModule("libc", methods);
   ^

I'm investigating, maybe it would be useful to setup a Travis to show the working chain.

run k-script-build correctly

Placeholder for all the issues found

  • "\n" escape (within double quotes)
  • [ foo -o bar ] not parsed correctly
  • read builtin should respect IFS (not use Python's split!)
  • k-script-build-static has fewer lines under OSH.
    • this is most likely because of the same IFS issue. "include lines" are parsed with IFS
      splitting.
  • Fix bug with ${s%-*}

make clean doesn't work in the tarball distribution

This is because all the Python source is in the app bundle already. Hm.

~/src/oil-0.1.0$ make clean
build/actions.sh clean
find: ‘Python-2.7.13/Lib’: No such file or directory
Makefile:89: recipe for target 'clean' failed
make: *** [clean] Error 1

better error if ~/bin doesn't exist

Installing to /home/poppy/bin/oil.ovm
install: cannot create regular file '/home/poppy/bin/oil.ov
': No such file or directory
FATAL install error: Couldn't install oil binary

IOError when source is called with nonexistent path

Certain inputs will trigger an uncaught Python exception. If you run into such a bug, report it on Github, or leave a comment.

./_bin/oil.ovm osh
osh$ source asdf
Traceback (most recent call last):
  File "/home/andy/git/oil/Python-2.7.13/Lib/runpy.py", line 174, in _run_module_as_main
  File "/home/andy/git/oil/Python-2.7.13/Lib/runpy.py", line 72, in _run_code
  File "/home/andy/git/oil/bin/oil.py", line 440, in <module>
  File "/home/andy/git/oil/bin/oil.py", line 427, in main
  File "/home/andy/git/oil/bin/oil.py", line 410, in OilMain
  File "/home/andy/git/oil/bin/oil.py", line 311, in OshMain
  File "/home/andy/git/oil/bin/oil.py", line 122, in InteractiveLoop
  File "/home/andy/git/oil/bin/../core/cmd_exec.py", line 892, in Execute
  File "/home/andy/git/oil/bin/../core/cmd_exec.py", line 856, in _Execute
  File "/home/andy/git/oil/bin/../core/cmd_exec.py", line 674, in _Dispatch
  File "/home/andy/git/oil/bin/../core/cmd_exec.py", line 885, in _ExecuteList
  File "/home/andy/git/oil/bin/../core/cmd_exec.py", line 856, in _Execute
  File "/home/andy/git/oil/bin/../core/cmd_exec.py", line 584, in _Dispatch
  File "/home/andy/git/oil/bin/../core/cmd_exec.py", line 473, in _RunSimpleCommand
  File "/home/andy/git/oil/bin/../core/cmd_exec.py", line 244, in _RunBuiltin
  File "/home/andy/git/oil/bin/../core/cmd_exec.py", line 177, in _Source
IOError: [Errno 2] No such file or directory: 'asdf'

"${empty:-}" evaluates to nothing rather than empty string

Fixed with 8da6ccb

@lheckemann I just created a dummy issue to talk about this since the pull request was closed.

If you haven't used it yet, the -n flag is very useful. It prints out the AST/LST. Roughly speaking, there are nodes like (CommandList ...) and (BracedVarSub ...).

But I put some abbreviations like (C ...) for SimpleCommand and { } for CompoundWord so it's not too verbose. And ( ) for a word part.

Prior to my fix, there was an empty arg_word:(), but now it looks like arg_word:(SQ ) -- an empty SingleQuotedPart.

$ bin/osh -n -c 'echo ${empty:-}'
(CommandList
  children: [
    (C {(echo)} 
      {
        (BracedVarSub
          token: <VSub_Name empty>
          suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(SQ )})
          spids: [2 5]
        )
      }
    )
  ]
)

Oh and the "spids" mentioned in the comments are "span IDs". I have very detailed source location information for good error messages. But those synthetic nodes have no locations now so it's possible it breaks something.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.