Skip to content

Commit 7b71fd7

Browse files
authored
Merge pull request #498 from AppFlowy-IO/opti_protoc_msg
chore: optimazing install protoc message
2 parents f8d6aa3 + 0d40817 commit 7b71fd7

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

.github/workflows/dart_lint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
uses: actions/checkout@v2
2424
- uses: subosito/flutter-action@v1
2525
with:
26+
flutter-version: '2.10.0'
2627
channel: "stable"
2728
- name: Deps Flutter
2829
run: flutter packages pub get

shared-lib/lib-infra/src/code_gen/protobuf_file/mod.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod proto_info;
77
mod template;
88

99
use crate::code_gen::util::path_string_with_component;
10+
use itertools::Itertools;
1011
use log::info;
1112
pub use proto_gen::*;
1213
pub use proto_info::*;
@@ -132,7 +133,7 @@ fn generate_dart_protobuf_files(
132133
}
133134
}
134135

135-
fn check_pb_dart_plugin() {
136+
pub fn check_pb_dart_plugin() {
136137
if cfg!(target_os = "windows") {
137138
//Command::new("cmd")
138139
// .arg("/C")
@@ -141,15 +142,39 @@ fn check_pb_dart_plugin() {
141142
// .expect("failed to execute process");
142143
//panic!("{}", format!("\n❌ The protoc-gen-dart was not installed correctly."))
143144
} else {
144-
let is_success = Command::new("sh")
145+
let exit_result = Command::new("sh")
145146
.arg("-c")
146147
.arg("command -v protoc-gen-dart")
147148
.status()
148-
.expect("failed to execute process")
149-
.success();
149+
.expect("failed to execute process");
150+
151+
if !exit_result.success() {
152+
let mut msg = "\n❌ Can't find protoc-gen-dart in $PATH:\n".to_string();
153+
let output = Command::new("sh").arg("-c").arg("echo $PATH").output();
154+
let paths = String::from_utf8(output.unwrap().stdout)
155+
.unwrap()
156+
.split(":")
157+
.map(|s| s.to_string())
158+
.collect::<Vec<String>>();
159+
160+
paths.iter().for_each(|s| msg.push_str(&format!("{}\n", s)));
161+
162+
match Command::new("sh").arg("-c").arg("which protoc-gen-dart").output() {
163+
Ok(output) => {
164+
msg.push_str(&format!(
165+
"Installed protoc-gen-dart path: {:?}\n",
166+
String::from_utf8(output.stdout).unwrap()
167+
));
168+
}
169+
Err(_) => {}
170+
}
150171

151-
if !is_success {
152-
panic!("{}", format!("\n❌ The protoc-gen-dart was not installed correctly. \n✅ You can fix that by adding \"{}\" to your shell's config file.(.bashrc, .bash, etc.)", "dart pub global activate protoc_plugin"))
172+
msg.push_str(&format!("✅ You can fix that by adding:"));
173+
msg.push_str(&format!("\n\texport PATH=\"$PATH\":\"$HOME/.pub-cache/bin\"\n",));
174+
msg.push_str(&format!(
175+
"to your shell's config file.(.bashrc, .bash, .profile, .zshrc etc.)"
176+
));
177+
panic!("{}", msg)
153178
}
154179
}
155180
}

0 commit comments

Comments
 (0)