Skip to content

Commit

Permalink
[rust] Include debug info in release artifact and enable backtrace by…
Browse files Browse the repository at this point in the history
… default
  • Loading branch information
bonigarcia committed Oct 4, 2023
1 parent c9c1849 commit aa57f2a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion rust/Cargo.Bazel.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "4745128072794bf6ed7da8d621ea818d5d0e11d98386c45fd55852bd6ca41af8",
"checksum": "ac879e4513ac137fb555c16e74c747e59a78e2847d2a1121f432e73c4c37ad81",
"crates": {
"addr2line 0.19.0": {
"name": "addr2line",
Expand Down
2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ opt-level = 'z' # Optimize for size
lto = true # Enable Link Time Optimization
codegen-units = 1 # Reduce number of codegen units to increase optimizations
panic = 'abort' # Abort on panic
strip = true # Strip symbols from binary*
debug = true # Full debug info
23 changes: 8 additions & 15 deletions rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

use std::backtrace::{Backtrace, BacktraceStatus};
use std::env;
use std::path::Path;
use std::process::exit;

Expand Down Expand Up @@ -129,6 +129,8 @@ struct Cli {
}

fn main() {
env::set_var("RUST_BACKTRACE", "1"); // Enable capture backtrace by default

let mut cli = Cli::parse();
let cache_path =
StringKey(vec![CACHE_PATH_KEY], &cli.cache_path.unwrap_or_default()).get_value();
Expand Down Expand Up @@ -203,11 +205,7 @@ fn main() {
.and_then(|_| selenium_manager.setup())
.map(|driver_path| {
let log = selenium_manager.get_logger();
log_driver_and_browser_path(
log,
&driver_path,
selenium_manager.get_browser_path(),
);
log_driver_and_browser_path(log, &driver_path, selenium_manager.get_browser_path());
flush_and_exit(OK, log, None);
})
.unwrap_or_else(|err| {
Expand Down Expand Up @@ -236,11 +234,7 @@ fn main() {
});
}

fn log_driver_and_browser_path(
log: &Logger,
driver_path: &Path,
browser_path: &str,
) {
fn log_driver_and_browser_path(log: &Logger, driver_path: &Path, browser_path: &str) {
if driver_path.exists() {
log.info(format!("{}{}", DRIVER_PATH, driver_path.display()));
} else {
Expand All @@ -254,10 +248,9 @@ fn log_driver_and_browser_path(

fn flush_and_exit(code: i32, log: &Logger, err: Option<Error>) -> ! {
if let Some(error) = err {
let backtrace = Backtrace::capture();
let backtrace_status = backtrace.status();
if backtrace_status == BacktraceStatus::Captured {
log.debug(format!("Backtrace:\n{}", error.backtrace()));
let backtrace = error.backtrace();
if !backtrace.to_string().ends_with("backtrace") {
log.debug(format!("Backtrace:\n{}", backtrace));
}
}
log.set_code(code);
Expand Down

0 comments on commit aa57f2a

Please sign in to comment.