Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/wbinnssmith/modularize-cli' into…
Browse files Browse the repository at this point in the history
… wbinnssmith/turbopack-cli-build
  • Loading branch information
wbinnssmith committed Jul 18, 2023
2 parents 896be23 + de9b98d commit 82a2ca3
Show file tree
Hide file tree
Showing 402 changed files with 15,367 additions and 12,178 deletions.
4 changes: 4 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
CARGO_WORKSPACE_DIR = { value = "", relative = true }
TURBO_PNPM_WORKSPACE_DIR = { value = "", relative = true }

[build]
rustflags = ["--cfg", "tokio_unstable"]
rustdocflags = ["-Znormalize-docs"]

[target.x86_64-pc-windows-msvc]
linker = "rust-lld"

Expand Down
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/benchmark @vercel/turbo-oss
/buildcontainer @vercel/turbo-oss
/examples @vercel/turbo-oss
/examples-tests @vercel/turbo-oss
/docs/pages/repo @vercel/turbo-oss @anthonyshew
.github/workflows/pr-go-*.yml @vercel/turbo-oss
.github/workflows/pr-js-tests-*.yml @vercel/turbo-oss
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ jobs:
name: Turborepo Examples
needs: determine_jobs
if: needs.determine_jobs.outputs.examples == 'true'
timeout-minutes: 30
timeout-minutes: 40

strategy:
fail-fast: false
Expand Down
36 changes: 34 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ default-members = [
"crates/turbo-tasks-fetch",
"crates/turbo-tasks-fs",
"crates/turbo-tasks-hash",
"crates/turbo-tasks-macros",
"crates/turbo-tasks-macros-shared",
"crates/turbo-tasks-macros-tests",
"crates/turbo-tasks-malloc",
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/turbo/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

const turboVersion = "1.10.8-canary.0"
const turboVersion = "1.10.8"
4 changes: 3 additions & 1 deletion cli/internal/client/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func (c *APIClient) PutArtifact(hash string, artifactBody []byte, duration int,
requestURL := c.makeURL("/v8/artifacts/" + hash + encoded)
allowAuth := true
if c.usePreflight {
resp, latestRequestURL, err := c.doPreflight(requestURL, http.MethodPut, "Content-Type, x-artifact-duration, Authorization, User-Agent, x-artifact-tag")
resp, latestRequestURL, err := c.doPreflight(requestURL,
http.MethodPut,
"Content-Type, x-artifact-duration, Authorization, User-Agent, x-artifact-tag")
if err != nil {
return fmt.Errorf("pre-flight request failed before trying to store in HTTP cache: %w", err)
}
Expand Down
12 changes: 6 additions & 6 deletions cli/internal/ffi/ffi.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ package ffi

// #include "bindings.h"
//
// #cgo darwin,arm64 LDFLAGS: -L${SRCDIR} -lturborepo_ffi_darwin_arm64 -lz -liconv -framework Security
// #cgo darwin,amd64 LDFLAGS: -L${SRCDIR} -lturborepo_ffi_darwin_amd64 -lz -liconv -framework Security
// #cgo linux,arm64,staticbinary LDFLAGS: -L${SRCDIR} -lturborepo_ffi_linux_arm64 -lunwind
// #cgo linux,amd64,staticbinary LDFLAGS: -L${SRCDIR} -lturborepo_ffi_linux_amd64 -lunwind
// #cgo linux,arm64,!staticbinary LDFLAGS: -L${SRCDIR} -lturborepo_ffi_linux_arm64 -lz
// #cgo linux,amd64,!staticbinary LDFLAGS: -L${SRCDIR} -lturborepo_ffi_linux_amd64 -lz
// #cgo darwin,arm64 LDFLAGS: -L${SRCDIR} -lturborepo_ffi_darwin_arm64 -lz -liconv -framework Security -framework CoreFoundation
// #cgo darwin,amd64 LDFLAGS: -L${SRCDIR} -lturborepo_ffi_darwin_amd64 -lz -liconv -framework Security -framework CoreFoundation
// #cgo linux,arm64,staticbinary LDFLAGS: -L${SRCDIR} -lturborepo_ffi_linux_arm64 -lunwind -lm
// #cgo linux,amd64,staticbinary LDFLAGS: -L${SRCDIR} -lturborepo_ffi_linux_amd64 -lunwind -lm
// #cgo linux,arm64,!staticbinary LDFLAGS: -L${SRCDIR} -lturborepo_ffi_linux_arm64 -lz -lm
// #cgo linux,amd64,!staticbinary LDFLAGS: -L${SRCDIR} -lturborepo_ffi_linux_amd64 -lz -lm
// #cgo windows,amd64 LDFLAGS: -L${SRCDIR} -lturborepo_ffi_windows_amd64 -lole32 -lbcrypt -lws2_32 -luserenv -lntdll
import "C"

Expand Down
57 changes: 48 additions & 9 deletions cli/internal/run/real_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ type logBufferWriter struct {
// Write implements io.Writer.Write for logBufferWriter
func (lbw *logBufferWriter) Write(bytes []byte) (int, error) {
n := len(bytes)
lbw.logBuffer.LogLine(bytes, lbw.isStdout)
// The io.Writer contract states that we cannot retain the bytes we are passed,
// so we need to make a copy of them
cpy := make([]byte, n)
copy(cpy, bytes)
lbw.logBuffer.LogLine(cpy, lbw.isStdout)
return n, nil
}

Expand Down Expand Up @@ -212,7 +216,13 @@ func RealRun(

if isGrouped {
outWriter = logBuffer.StdoutWriter()
errWriter = logBuffer.StderrWriter()
if rs.Opts.runOpts.IsGithubActions {
// If we're running on Github Actions, force everything to stdout
// so as not to have out-of-order log lines
errWriter = outWriter
} else {
errWriter = logBuffer.StderrWriter()
}
}

var spacesLogBuffer *threadsafeOutputBuffer
Expand Down Expand Up @@ -276,6 +286,14 @@ func RealRun(
// Assign tasks after execution
runSummary.RunSummary.Tasks = taskSummaries

terminal := base.UI
if rs.Opts.runOpts.IsGithubActions {
terminal = &cli.PrefixedUi{
Ui: terminal,
ErrorPrefix: "::error::",
WarnPrefix: "::warn::",
}
}
for _, err := range errs {
if errors.As(err, &exitCodeErr) {
// If a process gets killed via a signal, Go reports it's exit code as -1.
Expand All @@ -292,7 +310,7 @@ func RealRun(
// We hit some error, it shouldn't be exit code 0
exitCode = 1
}
base.UI.Error(err.Error())
terminal.Error(err.Error())
}

// When continue on error is enabled don't register failed tasks as errors
Expand Down Expand Up @@ -395,14 +413,14 @@ func (ec *execContext) exec(ctx gocontext.Context, packageTask *nodes.PackageTas
Ui: ui,
OutputPrefix: prettyPrefix,
InfoPrefix: prettyPrefix,
ErrorPrefix: prettyPrefix,
ErrorPrefix: prettyPrefix + "ERROR: ",
WarnPrefix: prettyPrefix,
}

if ec.rs.Opts.runOpts.IsGithubActions {
ui.Output(fmt.Sprintf("::group::%s", packageTask.OutputPrefix(ec.isSinglePackage)))
prefixedUI.WarnPrefix = "::warn::"
prefixedUI.ErrorPrefix = "::error::"
prefixedUI.WarnPrefix = "[WARN] "
prefixedUI.ErrorPrefix = "[ERROR] "
defer func() {
// We don't use the prefixedUI here because the prefix in this case would include
// the ::group::<taskID>, and we explicitly want to close the github group
Expand Down Expand Up @@ -540,17 +558,25 @@ func (ec *execContext) exec(ctx gocontext.Context, packageTask *nodes.PackageTas
// If it wasn't a ChildExit, and something else went wrong, we don't have an exitCode
tracer(runsummary.TargetBuildFailed, err, nil)
}

taskIDDisplay := packageTask.TaskID
if ec.isSinglePackage {
taskIDDisplay = packageTask.Task
}
taskErr := &TaskError{
cause: err,
taskIDDisplay: taskIDDisplay,
}
// If there was an error, flush the buffered output
taskCache.OnError(prefixedUI, progressLogger)
progressLogger.Error(fmt.Sprintf("Error: command finished with error: %v", err))
if !ec.rs.Opts.runOpts.ContinueOnError {
prefixedUI.Error(fmt.Sprintf("ERROR: command finished with error: %s", err))
prefixedUI.Error(fmt.Sprintf("command finished with error: %s", err))
ec.processes.Close()
// We're not continuing, stop graph traversal
err = core.StopExecution(err)
err = core.StopExecution(taskErr)
} else {
prefixedUI.Warn("command finished with error, but continuing...")
err = taskErr
}

return taskExecutionSummary, err
Expand All @@ -576,3 +602,16 @@ func (ec *execContext) exec(ctx gocontext.Context, packageTask *nodes.PackageTas
progressLogger.Debug("done", "status", "complete", "duration", taskExecutionSummary.Duration)
return taskExecutionSummary, nil
}

// TaskError wraps an error encountered running the given task
type TaskError struct {
cause error
taskIDDisplay string
}

// Unwrap allows for interoperation with standard library error wrapping
func (te *TaskError) Unwrap() error { return te.cause }

func (te *TaskError) Error() string {
return fmt.Sprintf("%v: %v", te.taskIDDisplay, te.cause)
}
2 changes: 2 additions & 0 deletions cli/internal/spinner/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func getWriterAndColor(terminal cli.Ui, useColor bool) (io.Writer, bool) {
switch terminal := terminal.(type) {
case *cli.BasicUi:
return terminal.Writer, useColor
case *ui.BasicUI:
return terminal.Writer, useColor
case *cli.ColoredUi:
return getWriterAndColor(terminal.Ui, true)
case *cli.ConcurrentUi:
Expand Down
20 changes: 10 additions & 10 deletions cli/internal/ui/ui_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,29 @@ type Factory interface {
type BasicUIFactory struct {
}

// basicUI is an implementation of Ui that just outputs to the given
// BasicUI is an implementation of Ui that just outputs to the given
// writer. This UI is not threadsafe by default, but you can wrap it
// in a ConcurrentUi to make it safe.
//
// Inlined from cli.Ui to fuse newlines to lines being logged. This is
// probably not the optimal way to do it, but it works for now.
type basicUI struct {
type BasicUI struct {
Reader io.Reader
Writer io.Writer
ErrorWriter io.Writer
}

// Ask implements ui.Cli.Ask for BasicUi
func (u *basicUI) Ask(query string) (string, error) {
func (u *BasicUI) Ask(query string) (string, error) {
return u.ask(query, false)
}

// AskSecret implements ui.Cli.AskSecret for BasicUi
func (u *basicUI) AskSecret(query string) (string, error) {
func (u *BasicUI) AskSecret(query string) (string, error) {
return u.ask(query, true)
}

func (u *basicUI) ask(query string, secret bool) (string, error) {
func (u *BasicUI) ask(query string, secret bool) (string, error) {
if _, err := fmt.Fprint(u.Writer, query+" "); err != nil {
return "", err
}
Expand Down Expand Up @@ -92,7 +92,7 @@ func (u *basicUI) ask(query string, secret bool) (string, error) {
}

// Error implements ui.Cli.Error for BasicUi
func (u *basicUI) Error(message string) {
func (u *BasicUI) Error(message string) {
w := u.Writer
if u.ErrorWriter != nil {
w = u.ErrorWriter
Expand All @@ -102,23 +102,23 @@ func (u *basicUI) Error(message string) {
}

// Info implements ui.Cli.Info for BasicUi
func (u *basicUI) Info(message string) {
func (u *BasicUI) Info(message string) {
u.Output(message)
}

// Output implements ui.Cli.Output for BasicUi
func (u *basicUI) Output(message string) {
func (u *BasicUI) Output(message string) {
fmt.Fprintf(u.Writer, "%v\n", message)
}

// Warn implements ui.Cli.Warn for BasicUi
func (u *basicUI) Warn(message string) {
func (u *BasicUI) Warn(message string) {
u.Error(message)
}

// Build builds a cli.BasicUi from input, output and error IOs
func (factory *BasicUIFactory) Build(in io.Reader, out io.Writer, err io.Writer) cli.Ui {
return &basicUI{
return &BasicUI{
Reader: in,
Writer: out,
ErrorWriter: err,
Expand Down
Loading

0 comments on commit 82a2ca3

Please sign in to comment.