mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2024-11-23 07:10:29 +00:00
Replace anyhow dependency with a handwritten reporter
This commit is contained in:
parent
b87d70f08c
commit
bb3ba50a8c
3
BUCK
3
BUCK
@ -16,7 +16,6 @@ rust_binary(
|
||||
crate = "cxxbridge",
|
||||
visibility = ["PUBLIC"],
|
||||
deps = [
|
||||
"//third-party:anyhow",
|
||||
"//third-party:clap",
|
||||
"//third-party:codespan-reporting",
|
||||
"//third-party:proc-macro2",
|
||||
@ -60,7 +59,6 @@ rust_library(
|
||||
srcs = glob(["gen/build/src/**"]),
|
||||
visibility = ["PUBLIC"],
|
||||
deps = [
|
||||
"//third-party:anyhow",
|
||||
"//third-party:cc",
|
||||
"//third-party:codespan-reporting",
|
||||
"//third-party:proc-macro2",
|
||||
@ -74,7 +72,6 @@ rust_library(
|
||||
srcs = glob(["gen/lib/src/**"]),
|
||||
visibility = ["PUBLIC"],
|
||||
deps = [
|
||||
"//third-party:anyhow",
|
||||
"//third-party:cc",
|
||||
"//third-party:codespan-reporting",
|
||||
"//third-party:proc-macro2",
|
||||
|
3
BUILD
3
BUILD
@ -19,7 +19,6 @@ rust_binary(
|
||||
data = ["gen/cmd/src/gen/include/cxx.h"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//third-party:anyhow",
|
||||
"//third-party:clap",
|
||||
"//third-party:codespan-reporting",
|
||||
"//third-party:proc-macro2",
|
||||
@ -59,7 +58,6 @@ rust_library(
|
||||
data = ["gen/build/src/gen/include/cxx.h"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//third-party:anyhow",
|
||||
"//third-party:cc",
|
||||
"//third-party:codespan-reporting",
|
||||
"//third-party:proc-macro2",
|
||||
@ -74,7 +72,6 @@ rust_library(
|
||||
data = ["gen/lib/src/gen/include/cxx.h"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//third-party:anyhow",
|
||||
"//third-party:cc",
|
||||
"//third-party:codespan-reporting",
|
||||
"//third-party:proc-macro2",
|
||||
|
@ -10,7 +10,6 @@ keywords = ["ffi"]
|
||||
categories = ["development-tools::ffi"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
cc = "1.0.49"
|
||||
codespan-reporting = "0.9"
|
||||
proc-macro2 = { version = "1.0.17", default-features = false, features = ["span-locations"] }
|
||||
|
@ -58,8 +58,8 @@ mod paths;
|
||||
mod syntax;
|
||||
|
||||
use crate::error::Result;
|
||||
use crate::gen::error::report;
|
||||
use crate::gen::Opt;
|
||||
use anyhow::anyhow;
|
||||
use std::fs;
|
||||
use std::io::{self, Write};
|
||||
use std::iter;
|
||||
@ -93,7 +93,7 @@ pub fn bridges(rust_source_files: impl IntoIterator<Item = impl AsRef<Path>>) ->
|
||||
|
||||
for path in rust_source_files {
|
||||
if let Err(err) = try_generate_bridge(&mut build, path.as_ref()) {
|
||||
let _ = writeln!(io::stderr(), "\n\ncxxbridge error: {:?}\n\n", anyhow!(err));
|
||||
let _ = writeln!(io::stderr(), "\n\ncxxbridge error: {}\n\n", report(err));
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ name = "cxxbridge"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
clap = "2.33"
|
||||
codespan-reporting = "0.9"
|
||||
proc-macro2 = { version = "1.0.17", default-features = false, features = ["span-locations"] }
|
||||
|
@ -10,7 +10,6 @@ keywords = ["ffi"]
|
||||
categories = ["development-tools::ffi"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
cc = "1.0.49"
|
||||
codespan-reporting = "0.9"
|
||||
proc-macro2 = { version = "1.0.17", default-features = false, features = ["span-locations"] }
|
||||
|
@ -1,5 +1,4 @@
|
||||
use crate::syntax;
|
||||
use anyhow::anyhow;
|
||||
use codespan_reporting::diagnostic::{Diagnostic, Label};
|
||||
use codespan_reporting::files::SimpleFiles;
|
||||
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream, WriteColor};
|
||||
@ -63,11 +62,34 @@ pub(super) fn format_err(path: &Path, source: &str, error: Error) -> ! {
|
||||
display_syn_error(stderr, path, source, error);
|
||||
}
|
||||
}
|
||||
_ => eprintln!("cxxbridge: {:?}", anyhow!(error)),
|
||||
_ => {
|
||||
let _ = writeln!(io::stderr(), "cxxbridge: {}", report(error));
|
||||
}
|
||||
}
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
pub(crate) fn report(error: impl StdError) -> impl Display {
|
||||
struct Report<E>(E);
|
||||
|
||||
impl<E: StdError> Display for Report<E> {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
Display::fmt(&self.0, formatter)?;
|
||||
let mut error: &dyn StdError = &self.0;
|
||||
|
||||
while let Some(cause) = error.source() {
|
||||
formatter.write_str("\n\nCaused by:\n ")?;
|
||||
Display::fmt(cause, formatter)?;
|
||||
error = cause;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Report(error)
|
||||
}
|
||||
|
||||
fn sort_syn_errors(error: syn::Error) -> Vec<syn::Error> {
|
||||
let mut errors: Vec<_> = error.into_iter().collect();
|
||||
errors.sort_by_key(|e| {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Functionality that is shared between the cxx_build::bridge entry point and
|
||||
// the cxxbridge CLI command.
|
||||
|
||||
mod error;
|
||||
pub(super) mod error;
|
||||
mod file;
|
||||
pub(super) mod include;
|
||||
pub(super) mod out;
|
||||
|
7
third-party/BUCK
vendored
7
third-party/BUCK
vendored
@ -1,12 +1,5 @@
|
||||
# To be generated by Facebook's `reindeer` tool once that is open source.
|
||||
|
||||
rust_library(
|
||||
name = "anyhow",
|
||||
srcs = glob(["vendor/anyhow-1.0.32/src/**"]),
|
||||
visibility = ["PUBLIC"],
|
||||
features = ["std"],
|
||||
)
|
||||
|
||||
rust_library(
|
||||
name = "bitflags",
|
||||
srcs = glob(["vendor/bitflags-1.2.1/src/**"]),
|
||||
|
7
third-party/BUILD
vendored
7
third-party/BUILD
vendored
@ -5,13 +5,6 @@ load(
|
||||
)
|
||||
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
|
||||
|
||||
rust_library(
|
||||
name = "anyhow",
|
||||
srcs = glob(["vendor/anyhow-1.0.32/src/**"]),
|
||||
crate_features = ["std"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
rust_library(
|
||||
name = "bitflags",
|
||||
srcs = glob(["vendor/bitflags-1.2.1/src/**"]),
|
||||
|
9
third-party/Cargo.lock
generated
vendored
9
third-party/Cargo.lock
generated
vendored
@ -9,12 +9,6 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b"
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
@ -81,7 +75,6 @@ dependencies = [
|
||||
name = "cxx-build"
|
||||
version = "0.3.7"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cc",
|
||||
"codespan-reporting",
|
||||
"cxx-gen",
|
||||
@ -94,7 +87,6 @@ dependencies = [
|
||||
name = "cxx-gen"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cc",
|
||||
"codespan-reporting",
|
||||
"proc-macro2",
|
||||
@ -115,7 +107,6 @@ dependencies = [
|
||||
name = "cxxbridge-cmd"
|
||||
version = "0.3.7"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"codespan-reporting",
|
||||
"proc-macro2",
|
||||
|
Loading…
Reference in New Issue
Block a user