Skip to content
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

chore: remove silent flag #6008

Merged
merged 3 commits into from
Sep 22, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/turborepo-lib/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
pub struct RunOpts<'a> {
pub(crate) tasks: &'a [String],
pub(crate) concurrency: u32,
parallel: bool,

Check warning on line 60 in crates/turborepo-lib/src/opts.rs

View workflow job for this annotation

GitHub Actions / Build Turborepo (ubuntu, ubuntu-latest)

fields `parallel`, `profile`, `continue_on_error`, `dry_run`, and `summarize` are never read

Check warning on line 60 in crates/turborepo-lib/src/opts.rs

View workflow job for this annotation

GitHub Actions / Build Turborepo (macos, macos-latest)

fields `parallel`, `profile`, `continue_on_error`, `dry_run`, and `summarize` are never read

Check warning on line 60 in crates/turborepo-lib/src/opts.rs

View workflow job for this annotation

GitHub Actions / Turborepo E2E Tests (ubuntu, ubuntu-latest)

fields `parallel`, `profile`, `continue_on_error`, `dry_run`, and `summarize` are never read

Check warning on line 60 in crates/turborepo-lib/src/opts.rs

View workflow job for this annotation

GitHub Actions / Go Integration Tests (ubuntu, ubuntu-latest)

fields `parallel`, `profile`, `continue_on_error`, `dry_run`, and `summarize` are never read

Check warning on line 60 in crates/turborepo-lib/src/opts.rs

View workflow job for this annotation

GitHub Actions / Turborepo Examples (ubuntu, ubuntu-latest)

fields `parallel`, `profile`, `continue_on_error`, `dry_run`, and `summarize` are never read

Check warning on line 60 in crates/turborepo-lib/src/opts.rs

View workflow job for this annotation

GitHub Actions / Turborepo E2E Tests (macos, macos-latest)

fields `parallel`, `profile`, `continue_on_error`, `dry_run`, and `summarize` are never read

Check warning on line 60 in crates/turborepo-lib/src/opts.rs

View workflow job for this annotation

GitHub Actions / Turborepo Examples (macos, macos-latest)

fields `parallel`, `profile`, `continue_on_error`, `dry_run`, and `summarize` are never read
pub(crate) env_mode: EnvMode,
// Whether or not to infer the framework for each workspace.
pub(crate) framework_inference: bool,
Expand Down Expand Up @@ -273,6 +273,14 @@
}
}

impl<'a> RunOpts<'a> {
pub fn should_redirect_stderr_to_stdout(&self) -> bool {
// If we're running on Github Actions, force everything to stdout
// so as not to have out-of-order log lines
matches!(self.log_order, ResolvedLogOrder::Grouped) && self.is_github_actions
}
}

impl ScopeOpts {
pub fn get_filters(&self) -> Vec<String> {
[
Expand Down
30 changes: 6 additions & 24 deletions crates/turborepo-lib/src/package_graph/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub struct PackageGraphBuilder<'a> {
package_manager: Option<PackageManager>,
package_jsons: Option<HashMap<AbsoluteSystemPathBuf, PackageJson>>,
lockfile: Option<Box<dyn Lockfile>>,
quiet: bool,
}

#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -67,7 +66,6 @@ impl<'a> PackageGraphBuilder<'a> {
package_manager: None,
package_jsons: None,
lockfile: None,
quiet: false,
}
}

Expand All @@ -82,11 +80,6 @@ impl<'a> PackageGraphBuilder<'a> {
self
}

pub fn with_quiet(mut self) -> Self {
self.quiet = true;
self
}

#[allow(dead_code)]
pub fn with_package_jsons(
mut self,
Expand Down Expand Up @@ -125,7 +118,6 @@ struct BuildState<'a, S> {
node_lookup: HashMap<WorkspaceNode, NodeIndex>,
lockfile: Option<Box<dyn Lockfile>>,
package_jsons: Option<HashMap<AbsoluteSystemPathBuf, PackageJson>>,
quiet: bool,
state: std::marker::PhantomData<S>,
}

Expand Down Expand Up @@ -164,7 +156,6 @@ impl<'a> BuildState<'a, ResolvedPackageManager> {
package_manager,
package_jsons,
lockfile,
quiet,
} = builder;
let package_manager = package_manager.map_or_else(
|| PackageManager::get_package_manager(repo_root, Some(&root_package_json)),
Expand All @@ -187,7 +178,6 @@ impl<'a> BuildState<'a, ResolvedPackageManager> {
workspaces,
lockfile,
package_jsons,
quiet,
workspace_graph: Graph::new(),
node_lookup: HashMap::new(),
state: std::marker::PhantomData,
Expand Down Expand Up @@ -258,7 +248,6 @@ impl<'a> BuildState<'a, ResolvedPackageManager> {
workspace_graph,
node_lookup,
lockfile,
quiet,
..
} = self;
Ok(BuildState {
Expand All @@ -269,7 +258,6 @@ impl<'a> BuildState<'a, ResolvedPackageManager> {
workspace_graph,
node_lookup,
lockfile,
quiet,
package_jsons: None,
state: std::marker::PhantomData,
})
Expand Down Expand Up @@ -369,13 +357,11 @@ impl<'a> BuildState<'a, ResolvedWorkspaces> {
let lockfile = match self.populate_lockfile() {
Ok(lockfile) => Some(lockfile),
Err(e) => {
if !self.quiet {
warn!(
"Issues occurred when constructing package graph. Turbo will function, \
but some features may not be available: {}",
e
);
}
warn!(
"Issues occurred when constructing package graph. Turbo will function, but \
some features may not be available: {}",
e
);
None
}
};
Expand All @@ -387,7 +373,6 @@ impl<'a> BuildState<'a, ResolvedWorkspaces> {
workspaces,
workspace_graph,
node_lookup,
quiet,
..
} = self;
Ok(BuildState {
Expand All @@ -398,7 +383,6 @@ impl<'a> BuildState<'a, ResolvedWorkspaces> {
workspace_graph,
node_lookup,
lockfile,
quiet,
package_jsons: None,
state: std::marker::PhantomData,
})
Expand Down Expand Up @@ -447,9 +431,7 @@ impl<'a> BuildState<'a, ResolvedLockfile> {

fn build(mut self) -> PackageGraph {
if let Err(e) = self.populate_transitive_dependencies() {
if !self.quiet {
warn!("Unable to calculate transitive closures: {}", e);
}
warn!("Unable to calculate transitive closures: {}", e);
}
let Self {
package_manager,
Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-lib/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ impl<'a> Run<'a> {
&global_hash,
global_env_mode,
self.base.ui,
false,
);

visitor.visit(engine.clone()).await?;
Expand Down
47 changes: 21 additions & 26 deletions crates/turborepo-lib/src/task_graph/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ pub struct Visitor<'a> {
sink: OutputSink<StdWriter>,
color_cache: ColorSelector,
ui: UI,
// For testing purposes we need to be able to silence the output
silent: bool,
}

#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -72,14 +70,15 @@ impl<'a> Visitor<'a> {
global_hash: &'a str,
global_env_mode: EnvMode,
ui: UI,
silent: bool,
) -> Self {
let task_hasher = TaskHasher::new(
package_inputs_hashes,
opts,
env_at_execution_start,
global_hash,
);
let sink = Self::sink(opts);
let sink = Self::sink(opts, silent);
let color_cache = ColorSelector::default();

Self {
Expand All @@ -91,15 +90,9 @@ impl<'a> Visitor<'a> {
sink,
color_cache,
ui,
silent: false,
}
}

pub fn silent(mut self) -> Self {
self.silent = true;
self
}

pub async fn visit(&self, engine: Arc<Engine>) -> Result<(), Error> {
let concurrency = self.opts.run_opts.concurrency as usize;
let (node_sender, mut node_stream) = mpsc::channel(concurrency);
Expand Down Expand Up @@ -191,15 +184,12 @@ impl<'a> Visitor<'a> {
let prefix = self.prefix(&info);
let pretty_prefix = self.color_cache.prefix_with_color(&task_hash, &prefix);
let ui = self.ui;
let silent = self.silent;

tasks.push(tokio::spawn(async move {
let _task_cache = task_cache;
if !silent {
let mut prefixed_ui =
Self::prefixed_ui(ui, is_github_actions, &output_client, pretty_prefix);
prefixed_ui.output(command);
}
let mut prefixed_ui =
Self::prefixed_ui(ui, is_github_actions, &output_client, pretty_prefix);
prefixed_ui.output(command);
callback.send(Ok(())).unwrap();
}));
}
Expand All @@ -214,18 +204,15 @@ impl<'a> Visitor<'a> {
Ok(())
}

fn sink(opts: &Opts) -> OutputSink<StdWriter> {
let err_writer = match matches!(
opts.run_opts.log_order,
crate::opts::ResolvedLogOrder::Grouped
) && opts.run_opts.is_github_actions
{
// If we're running on Github Actions, force everything to stdout
// so as not to have out-of-order log lines
true => std::io::stdout().into(),
false => std::io::stderr().into(),
fn sink(opts: &Opts, silent: bool) -> OutputSink<StdWriter> {
let (out, err) = if silent {
(std::io::sink().into(), std::io::sink().into())
} else if opts.run_opts.should_redirect_stderr_to_stdout() {
(std::io::stdout().into(), std::io::stdout().into())
} else {
(std::io::stdout().into(), std::io::stderr().into())
};
OutputSink::new(std::io::stdout().into(), err_writer)
OutputSink::new(out, err)
}

fn output_client(&self) -> OutputClient<impl std::io::Write> {
Expand Down Expand Up @@ -283,13 +270,15 @@ impl<'a> Visitor<'a> {
enum StdWriter {
Out(std::io::Stdout),
Err(std::io::Stderr),
Null(std::io::Sink),
}

impl StdWriter {
fn writer(&mut self) -> &mut dyn std::io::Write {
match self {
StdWriter::Out(out) => out,
StdWriter::Err(err) => err,
StdWriter::Null(null) => null,
}
}
}
Expand All @@ -306,6 +295,12 @@ impl From<std::io::Stderr> for StdWriter {
}
}

impl From<std::io::Sink> for StdWriter {
fn from(value: std::io::Sink) -> Self {
Self::Null(value)
}
}

impl std::io::Write for StdWriter {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
self.writer().write(buf)
Expand Down