Files
carbon-lang/toolchain/driver/tool_runner_base.h
T
Chandler CarruthandGeoff Romer ff8ce31e1b Factor out C-string argv building and simplify vlogs (#6478)
This extracts the C-string `argv`-like building routine to a more
broadly reusable location. It also sinks the verbose logging logic out
of it and into the relevant runners. In turn, it simplifies the verbose
logging logic significantly.

The biggest functional change is removing the implicit synthesis of a
tool's `-v` verbose flag from the presence of a `vlog` stream. I thought
this would be helpful, but in practice of debugging these layers it has
been more of a hindrance than a help -- I pretty often only want verbose
logging on one side or the other, and we have ways of explicitly passing
a `-v` flag to the underlying tools already. I think my instinct to do
this was just wrong, so rip it out and simplify.

This does add an unused feature -- prepending a prefix of arguments
while building the C-string variant. This isn't used in this PR but will
be used in subsequent PRs and it seemed more disruptive to undo that
logic and then re-do it in a later PR. Let me know if it's too confusing
here.

Assisted-by: Gemini Code Assist

---------

Co-authored-by: Geoff Romer <gromer@google.com>
2025-12-10 22:07:01 +00:00

47 lines
1.7 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_TOOLCHAIN_DRIVER_TOOL_RUNNER_BASE_H_
#define CARBON_TOOLCHAIN_DRIVER_TOOL_RUNNER_BASE_H_
#include <optional>
#include "common/ostream.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "toolchain/base/install_paths.h"
namespace Carbon {
// Base that factors out common utilities needed when implementing a runner of
// an external tool, especially tools part of the LLVM and Clang C++ toolchain
// that Carbon will end up wrapping.
//
// Note that this struct just collects common data and helper methods, and does
// not itself impose any invariants or form a meaningful API. It should be used
// as an implementation detail only.
class ToolRunnerBase {
public:
// Construct the tool runner bas.
//
// If `vlog_stream` is provided, it will be used for `CARBON_VLOG`s. If it is
// also equal to `&llvm::errs()`, and so tied to stderr, that will be used by
// verbose flag injection helpers in this class.
explicit ToolRunnerBase(const InstallPaths* install_paths,
llvm::raw_ostream* vlog_stream = nullptr);
protected:
// We use protected members as this base is just factoring out common
// implementation details of other runners.
//
// NOLINTBEGIN(misc-non-private-member-variables-in-classes)
const InstallPaths* installation_;
llvm::raw_ostream* vlog_stream_;
// NOLINTEND(misc-non-private-member-variables-in-classes)
};
} // namespace Carbon
#endif // CARBON_TOOLCHAIN_DRIVER_TOOL_RUNNER_BASE_H_