You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/09/04 23:21:11 UTC

[GitHub] [incubator-tvm] jroesch opened a new pull request #6401: [Rust] Improve the error reporting in build.rs files by using anyhow.

jroesch opened a new pull request #6401:
URL: https://github.com/apache/incubator-tvm/pull/6401


   This improves errors when build.rs scripts fail. cc @robo-corg, @mwillsey and @areusch 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] tqchen merged pull request #6401: [Rust] Improve the error reporting in build.rs files by using anyhow.

Posted by GitBox <gi...@apache.org>.
tqchen merged pull request #6401:
URL: https://github.com/apache/incubator-tvm/pull/6401


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] imalsogreg commented on a change in pull request #6401: [Rust] Improve the error reporting in build.rs files by using anyhow.

Posted by GitBox <gi...@apache.org>.
imalsogreg commented on a change in pull request #6401:
URL: https://github.com/apache/incubator-tvm/pull/6401#discussion_r485301026



##########
File path: rust/tvm-sys/build.rs
##########
@@ -19,22 +19,39 @@
 
 extern crate bindgen;
 
+use std::env;
 use std::path::PathBuf;
 
-use std::env;
+use anyhow::{Context, Result};
 
-fn main() {
+fn main() -> Result<()> {
     let tvm_home = option_env!("TVM_HOME").map(str::to_string).unwrap_or({
         let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
             .canonicalize()
-            .unwrap();
+            .with_context(|| {
+                format!(
+                    "failed to cannonicalize() CARGO MANIFEST_DIR={}",

Review comment:
       Dropped the `_` between `CARGO` and `MANIFEST_DIR`
   ```suggestion
                       "failed to cannonicalize() CARGO_MANIFEST_DIR={}",
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] imalsogreg commented on a change in pull request #6401: [Rust] Improve the error reporting in build.rs files by using anyhow.

Posted by GitBox <gi...@apache.org>.
imalsogreg commented on a change in pull request #6401:
URL: https://github.com/apache/incubator-tvm/pull/6401#discussion_r485301026



##########
File path: rust/tvm-sys/build.rs
##########
@@ -19,22 +19,39 @@
 
 extern crate bindgen;
 
+use std::env;
 use std::path::PathBuf;
 
-use std::env;
+use anyhow::{Context, Result};
 
-fn main() {
+fn main() -> Result<()> {
     let tvm_home = option_env!("TVM_HOME").map(str::to_string).unwrap_or({
         let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
             .canonicalize()
-            .unwrap();
+            .with_context(|| {
+                format!(
+                    "failed to cannonicalize() CARGO MANIFEST_DIR={}",

Review comment:
       Dropped the `_` between `CARGO` and `MANIFEST_DIR`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] imalsogreg commented on a change in pull request #6401: [Rust] Improve the error reporting in build.rs files by using anyhow.

Posted by GitBox <gi...@apache.org>.
imalsogreg commented on a change in pull request #6401:
URL: https://github.com/apache/incubator-tvm/pull/6401#discussion_r485301592



##########
File path: rust/tvm-sys/build.rs
##########
@@ -19,22 +19,39 @@
 
 extern crate bindgen;
 
+use std::env;
 use std::path::PathBuf;
 
-use std::env;
+use anyhow::{Context, Result};
 
-fn main() {
+fn main() -> Result<()> {
     let tvm_home = option_env!("TVM_HOME").map(str::to_string).unwrap_or({

Review comment:
       (Not really related to `anyhow`)
   `unwrap_or` will do the `CARGO_MANIFEST_DIR` work even if `TVM_HOME` is set (because `unwrap_or` is strict). `.unwrap_or_else(|| { ... ` will skip that work, if that's the desired behavior. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] imalsogreg commented on a change in pull request #6401: [Rust] Improve the error reporting in build.rs files by using anyhow.

Posted by GitBox <gi...@apache.org>.
imalsogreg commented on a change in pull request #6401:
URL: https://github.com/apache/incubator-tvm/pull/6401#discussion_r485301592



##########
File path: rust/tvm-sys/build.rs
##########
@@ -19,22 +19,39 @@
 
 extern crate bindgen;
 
+use std::env;
 use std::path::PathBuf;
 
-use std::env;
+use anyhow::{Context, Result};
 
-fn main() {
+fn main() -> Result<()> {
     let tvm_home = option_env!("TVM_HOME").map(str::to_string).unwrap_or({

Review comment:
       (Not really related to `anyhow`)
   `unwrap_or` will do the `CARGO_MANIFEST_DIR` work even if `TVM_HOME` is set (because `unwrap_or` is strict). `.unwrap_or_else(|| { ... ` will skip that work, if that's the desired behavior. 
   ```suggestion
       let tvm_home = option_env!("TVM_HOME").map(str::to_string).unwrap_or_else(|| {
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] imalsogreg commented on a change in pull request #6401: [Rust] Improve the error reporting in build.rs files by using anyhow.

Posted by GitBox <gi...@apache.org>.
imalsogreg commented on a change in pull request #6401:
URL: https://github.com/apache/incubator-tvm/pull/6401#discussion_r485665297



##########
File path: rust/tvm-sys/build.rs
##########
@@ -19,22 +19,39 @@
 
 extern crate bindgen;
 
+use std::env;
 use std::path::PathBuf;
 
-use std::env;
+use anyhow::{Context, Result};
 
-fn main() {
+fn main() -> Result<()> {
     let tvm_home = option_env!("TVM_HOME").map(str::to_string).unwrap_or({
         let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
             .canonicalize()
-            .unwrap();
+            .with_context(|| {
+                format!(
+                    "failed to cannonicalize() CARGO MANIFEST_DIR={}",
+                    env!("CARGO_MANIFEST_DIR")
+                )
+            })?;
+
         crate_dir
             .parent()
-            .unwrap()
+            .with_context(|| {
+                format!(
+                    "failed to find parent of CARGO MANIFEST_DIR={}",

Review comment:
       ```suggestion
                       "failed to find parent of CARGO_MANIFEST_DIR={}",
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] tqchen commented on pull request #6401: [Rust] Improve the error reporting in build.rs files by using anyhow.

Posted by GitBox <gi...@apache.org>.
tqchen commented on pull request #6401:
URL: https://github.com/apache/incubator-tvm/pull/6401#issuecomment-690364824


   Thanks @imalsogreg @adelbertc @jroesch !


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-tvm] jroesch commented on a change in pull request #6401: [Rust] Improve the error reporting in build.rs files by using anyhow.

Posted by GitBox <gi...@apache.org>.
jroesch commented on a change in pull request #6401:
URL: https://github.com/apache/incubator-tvm/pull/6401#discussion_r485975879



##########
File path: rust/tvm-sys/build.rs
##########
@@ -19,22 +19,39 @@
 
 extern crate bindgen;
 
+use std::env;
 use std::path::PathBuf;
 
-use std::env;
+use anyhow::{Context, Result};
 
-fn main() {
+fn main() -> Result<()> {
     let tvm_home = option_env!("TVM_HOME").map(str::to_string).unwrap_or({

Review comment:
       These are from the "old" bindings so I don't even know who wrote all this code originally, but this seems like better behavior. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org