这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/integration_tests/bad_flag.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Bad flag with an implied run command should display run flags

note: to pass '--bad-flag' as a value, use '-- --bad-flag'

Usage: turbo <--cache-dir <CACHE_DIR>|--cache-workers <CACHE_WORKERS>|--concurrency <CONCURRENCY>|--continue|--dry-run [<DRY_RUN>]|--single-package|--filter <FILTER>|--force|--global-deps <GLOBAL_DEPS>|--graph [<GRAPH>]|--ignore <IGNORE>|--include-dependencies|--no-cache|--no-daemon|--no-deps|--output-logs <OUTPUT_LOGS>|--only|--parallel|--pkg-inference-root <PKG_INFERENCE_ROOT>|--profile <PROFILE>|--remote-only|--scope <SCOPE>|--since <SINCE>|TASKS|PASS_THROUGH_ARGS>
Usage: turbo <--cache-dir <CACHE_DIR>|--cache-workers <CACHE_WORKERS>|--concurrency <CONCURRENCY>|--continue|--dry-run [<DRY_RUN>]|--single-package|--filter <FILTER>|--force|--global-deps <GLOBAL_DEPS>|--graph [<GRAPH>]|--ignore <IGNORE>|--include-dependencies|--no-cache|--no-daemon|--no-deps|--output-logs <OUTPUT_LOGS>|--only|--parallel|--pkg-inference-root <PKG_INFERENCE_ROOT>|--profile <PROFILE>|--remote-only|--scope <SCOPE>|--since <SINCE>|--log-prefix <LOG_PREFIX>|TASKS|PASS_THROUGH_ARGS>

For more information, try '--help'.

Expand Down
1 change: 1 addition & 0 deletions cli/integration_tests/no_args.t
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Make sure exit code is 2 when no args are passed
--remote-only Ignore the local filesystem cache for all tasks. Only allow reading and caching artifacts using the remote cache
--scope <SCOPE> Specify package(s) to act as entry points for task execution. Supports globs
--since <SINCE> Limit/Set scope to changed packages since a mergebase. This uses the git diff ${target_branch}... mechanism to identify which packages have changed
--log-prefix <LOG_PREFIX> Use "none" to remove prefixes from task logs. Note that tasks running in parallel interleave their logs and prefix is the only way to identify which task produced a log [possible values: none]
[1]
$ ${TURBO} run
Turbo error: at least one task must be specified
Expand Down
78 changes: 78 additions & 0 deletions cli/integration_tests/run_logging/log_prefix.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
Setup
$ . ${TESTDIR}/../setup.sh
$ . ${TESTDIR}/setup.sh $(pwd) ./monorepo

# Run for the first time with --log-prefix=none
$ ${TURBO} run build --log-prefix=none
\xe2\x80\xa2 Packages in scope: app-a (esc)
\xe2\x80\xa2 Running build in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
cache miss, executing 74eb1b46ce8b29d3

\> build (re)
\> echo 'build app-a' (re)

build app-a

Tasks: 1 successful, 1 total
Cached: 0 cached, 1 total
Time:\s*[\.0-9]+m?s (re)

# Check that the cached logs don't have prefixes
$ cat app-a/.turbo/turbo-build.log

\> build (re)
\> echo 'build app-a' (re)

build app-a

# Running again should get a cache hit and no prefixes
$ ${TURBO} run build --log-prefix=none
\xe2\x80\xa2 Packages in scope: app-a (esc)
\xe2\x80\xa2 Running build in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
cache miss, executing 3df2c74b2bfbc724

\> build (re)
\> echo 'build app-a' (re)

build app-a

Tasks: 1 successful, 1 total
Cached: 0 cached, 1 total
Time:\s*[\.0-9]+m?s (re)

# Running again withuot `--log-prefix` should get a cache hit, but should print prefixes this time
$ ${TURBO} run build
\xe2\x80\xa2 Packages in scope: app-a (esc)
\xe2\x80\xa2 Running build in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
app-a:build: cache hit, replaying output 3df2c74b2bfbc724
app-a:build:
app-a:build: > build
app-a:build: > echo 'build app-a'
app-a:build:
app-a:build: build app-a

Tasks: 1 successful, 1 total
Cached: 1 cached, 1 total
Time:\s*[\.0-9]+m?s >>> FULL TURBO (re)


# Running with bogus option
$ ${TURBO} run build --log-prefix=blah
ERROR invalid value 'blah' for '--log-prefix <LOG_PREFIX>'
[possible values: none]

For more information, try '--help'.

[1]

# Running with missing value for option
$ ${TURBO} run build --log-prefix
ERROR a value is required for '--log-prefix <LOG_PREFIX>' but none was supplied
[possible values: none]

For more information, try '--help'.

[1]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "app-a",
"scripts": {
"build": "echo 'build app-a'"
}
}
6 changes: 6 additions & 0 deletions cli/integration_tests/run_logging/monorepo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "monorepo",
"workspaces": [
"app-*"
]
}
5 changes: 5 additions & 0 deletions cli/integration_tests/run_logging/monorepo/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"pipeline": {
"build": {}
}
}
7 changes: 7 additions & 0 deletions cli/integration_tests/run_logging/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]})
TARGET_DIR=$1
TEST_DIR=$2
cp -a ${SCRIPT_DIR}/$TEST_DIR/. ${TARGET_DIR}/
${SCRIPT_DIR}/../setup_git.sh ${TARGET_DIR}
2 changes: 2 additions & 0 deletions cli/integration_tests/turbo_help.t
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Test help flag
--remote-only Ignore the local filesystem cache for all tasks. Only allow reading and caching artifacts using the remote cache
--scope <SCOPE> Specify package(s) to act as entry points for task execution. Supports globs
--since <SINCE> Limit/Set scope to changed packages since a mergebase. This uses the git diff ${target_branch}... mechanism to identify which packages have changed
--log-prefix <LOG_PREFIX> Use "none" to remove prefixes from task logs. Note that tasks running in parallel interleave their logs and prefix is the only way to identify which task produced a log [possible values: none]



Expand Down Expand Up @@ -118,6 +119,7 @@ Test help flag
--remote-only Ignore the local filesystem cache for all tasks. Only allow reading and caching artifacts using the remote cache
--scope <SCOPE> Specify package(s) to act as entry points for task execution. Supports globs
--since <SINCE> Limit/Set scope to changed packages since a mergebase. This uses the git diff ${target_branch}... mechanism to identify which packages have changed
--log-prefix <LOG_PREFIX> Use "none" to remove prefixes from task logs. Note that tasks running in parallel interleave their logs and prefix is the only way to identify which task produced a log [possible values: none]

Test help flag for link command
$ ${TURBO} link -h
Expand Down
6 changes: 5 additions & 1 deletion cli/internal/colorcache/colorcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,9 @@ func (c *ColorCache) colorForKey(key string) colorFn {
// color based on the cacheKey
func (c *ColorCache) PrefixWithColor(cacheKey string, prefix string) string {
colorFn := c.colorForKey(cacheKey)
return colorFn("%s: ", prefix)
if prefix != "" {
return colorFn("%s: ", prefix)
}

return ""
}
14 changes: 11 additions & 3 deletions cli/internal/run/real_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ func (ec *execContext) logError(log hclog.Logger, prefix string, err error) {
func (ec *execContext) exec(ctx gocontext.Context, packageTask *nodes.PackageTask, deps dag.Set) error {
cmdTime := time.Now()

prefix := packageTask.OutputPrefix(ec.isSinglePackage)
prettyPrefix := ec.colorCache.PrefixWithColor(packageTask.PackageName, prefix)

progressLogger := ec.logger.Named("")
progressLogger.Debug("start")

Expand All @@ -177,6 +174,17 @@ func (ec *execContext) exec(ctx gocontext.Context, packageTask *nodes.PackageTas
progressLogger.Debug("done", "status", "skipped", "duration", time.Since(cmdTime))
return nil
}

var prefix string
var prettyPrefix string
if ec.rs.Opts.runOpts.logPrefix == "none" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since none is the only value that does anything, we should probably:

  • alter the help text so it's clear that "--log-prefix=none" is the only correct use of this flag
  • throw is the user passes something that's not none and not silently ignore an incorrect flag

prefix = ""
} else {
prefix = packageTask.OutputPrefix(ec.isSinglePackage)
}

prettyPrefix = ec.colorCache.PrefixWithColor(packageTask.PackageName, prefix)

// Cache ---------------------------------------------
taskCache := ec.runCache.TaskCache(packageTask, hash)
// Create a logger for replaying
Expand Down
2 changes: 2 additions & 0 deletions cli/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func ExecuteRun(ctx gocontext.Context, helper *cmdutil.Helper, signalWatcher *si

func optsFromArgs(args *turbostate.ParsedArgsFromRust) (*Opts, error) {
runPayload := args.Command.Run

opts := getDefaultOptions()
// aliases := make(map[string]string)
scope.OptsFromArgs(&opts.scopeOpts, args)
Expand All @@ -76,6 +77,7 @@ func optsFromArgs(args *turbostate.ParsedArgsFromRust) (*Opts, error) {
opts.cacheOpts.SkipFilesystem = runPayload.RemoteOnly
opts.cacheOpts.OverrideDir = runPayload.CacheDir
opts.cacheOpts.Workers = runPayload.CacheWorkers
opts.runOpts.logPrefix = runPayload.LogPrefix

// Runcache flags
opts.runcacheOpts.SkipReads = runPayload.Force
Expand Down
3 changes: 3 additions & 0 deletions cli/internal/run/run_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,7 @@ type runOpts struct {
graphFile string
noDaemon bool
singlePackage bool

// logPrefix controls whether we should print a prefix in task logs
logPrefix string
Copy link
Contributor Author

@mehulkar mehulkar Feb 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into using an enum here instead of a string, but decided against it because:

  • we don't have any other options to implement yet
  • we'd need unmarshaling from the rust args payload, which seems like throwaway work. We should be able to adapt to an internal enum any time down the line if it's necessary (before or after rust port)

}
1 change: 1 addition & 0 deletions cli/internal/turbostate/turbostate.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type RunPayload struct {
SinglePackage bool `json:"single_package"`
Tasks []string `json:"tasks"`
PkgInferenceRoot string `json:"pkg_inference_root"`
LogPrefix string `json:"log_prefix"`
}

// Command consists of the data necessary to run a command.
Expand Down
11 changes: 11 additions & 0 deletions crates/turborepo-lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ pub struct RunArgs {
/// to identify which packages have changed.
#[clap(long)]
pub since: Option<String>,
/// Use "none" to remove prefixes from task logs. Note that tasks running
/// in parallel interleave their logs and prefix is the only way
/// to identify which task produced a log.
#[clap(long, value_enum)]
pub log_prefix: Option<LogPrefix>,
// NOTE: The following two are hidden because clap displays them in the help text incorrectly:
// > Usage: turbo [OPTIONS] [TASKS]... [-- <FORWARDED_ARGS>...] [COMMAND]
#[clap(hide = true)]
Expand All @@ -360,6 +365,12 @@ pub struct RunArgs {
pub pass_through_args: Vec<String>,
}

#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Serialize)]
pub enum LogPrefix {
#[serde(rename = "none")]
None,
}

/// Runs the CLI by parsing arguments with clap, then either calling Rust code
/// directly or returning a payload for the Go code to use.
///
Expand Down