-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
Refactor and test the compiler #93
Conversation
…local/opt/python@3.8/bin:/Users/m/.cargo/bin:/Users/m/.yarn/bin:/Users/m/.config/yarn/global/node_modules/.bin:/Users/m/Library/Python/2.7/bin:/usr/local/opt/coreutils/libexec/gnubin:/Users/m/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/opt/X11/bin:/Library/Apple/usr/bin:/Users/m/dev/bin:/Users/m/dev/src/github.com/matthewmueller/depot_tools:/usr/local/sbin:/Users/m/.composer/vendor/bin
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.
Hopefully not such a big PR in the future!
# os.Pipe | ||
- name: Install bud binary into $PATH | ||
run: go install github.com/livebud/bud@latest | ||
|
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.
This will go away soon, we'll change v8client to use os.Pipe
and the same technique we're using with TCP listeners to pass the file descriptors through the binaries via ExtraFiles
. This is mostly setup now, just needs to be refactored in.
RUN git checkout $BUD_VERSION | ||
RUN make install | ||
RUN go install . | ||
RUN bud version |
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.
Helped me track down some Ubuntu-only issues in CI!
|
||
```sh | ||
docker build -t bud:latest contributing | ||
docker run -it --rm -v $(PWD):/bud bud /bin/bash |
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.
This allows you to make modifications in a local bud directory and see those changes within the docker container.
cli.Flag("port", "port").String(&cmd.Port).Default("3000") | ||
cli.Run(cmd.Run) | ||
// Run the CLI and wait for the command to finish | ||
func (c *CLI) Run(ctx context.Context, args ...string) error { |
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.
Swapping out the compiler is the meat of this PR.
The previous implementation in internal/bud
wasn't tested or setup for testing. Additionally it exposed too many internals as public APIs making some tests pass without actually working top level.
Now there's just one way to build or run a project. Use: err := cli.Run(ctx, args...)
and we can focus our energy on making this well-tested, fast, etc.
The CLI itself exposes a lot of optional configuration in its struct for making this package testable.
cli.Args("args").Strings(&c.args).Default(c.args...) | ||
cli.Run(fn) | ||
|
||
{ // $ bud create <dir> |
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 only CLI commands in here should be bud commands that are available when we're not in a bud project. The reason for this is we want to be able to define project commands that can even wrap commands like bud build
, so the fewer commands we have outside the project the better.
@@ -42,7 +42,7 @@ type Flusher interface { | |||
Flush() | |||
} | |||
|
|||
type Logger interface { | |||
type Interface interface { |
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.
log.Logger would always default to the standard libary's log package. This fixes that.
// are also fs.ErrNotExists | ||
func (*notExists) Unwrap() error { | ||
return fs.ErrNotExist | ||
} |
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.
This is a surprisingly important fix.
The error chain was getting lost when looking up a file that didn't exist in any filesystem (this can happen when there's errors).
We now collect and continue the chain when we encounter fs.ErrNotExist
errors.
The collected errors themselves also satisfy errors.Is(err, fs.ErrNotExist)
.
func (c *Command) compileAndStart(ctx context.Context, ln net.Listener) (*exe.Cmd, error) { | ||
app, err := c.Project.Compile(ctx, c.Flag) | ||
if err != nil { | ||
func (c *Command) compileAndStart(ctx context.Context, listener socket.Listener) (*exe.Cmd, error) { |
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.
Moved most of the bud {run,build,...}
logic into the runtime to prep for wrapping built-in commands.
if err != nil { | ||
console.Error(err.Error()) | ||
return nil | ||
} | ||
// TODO: host should be dynamic | ||
console.Info("Ready on http://127.0.0.1" + c.Port) | ||
process = p |
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.
^ Fixes a panic where failures would cause the process to be nil, if the watch command exited, process.Close would panic.
`) | ||
// Test stdio | ||
is.Equal(stdout.String(), "") | ||
is.Equal(stderr.String(), "") |
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.
Lots of tests needed to be refactored to use the new testcli package.
This is a mammoth of a PR that I should have broken up but...
¯\_(ツ)_/¯
The focus of this PR was to:
User facing changes:
bud run --port
renamed tobud run --listen