Procházet zdrojové kódy

增加vscode的检查、修正fmt问题 (#20)

LoGin před 1 rokem
rodič
revize
ea330323f6

+ 0 - 1
.gitignore

@@ -1,4 +1,3 @@
 /target
 Cargo.lock
 /DragonReach
-/.vscode

+ 16 - 0
.vscode/settings.json

@@ -0,0 +1,16 @@
+{
+    "rust-analyzer.check.overrideCommand": [
+        "cargo",
+        "+nightly",
+        "-Z",
+        "build-std=core,alloc,compiler_builtins",
+        "check",
+        "--workspace",
+        "--message-format=json",
+        "--target",
+        "target.json",
+    ],
+
+    "rust-analyzer.cargo.target": "x86_64-unknown-dragonos",
+    
+}

+ 2 - 2
Cargo.toml

@@ -14,12 +14,12 @@ hashbrown = "0.11"
 cfg-if = { version = "1.0"}
 
 [target.'cfg(target_os = "dragonos")'.dependencies]
-drstd = {git = "https://git.mirrors.dragonos.org/DragonOS-Community/drstd.git", revision = "a5a37880a8"}
+drstd = { git = "https://git.mirrors.dragonos.org/DragonOS-Community/drstd.git", rev = "0fe3ff0054" }
 
 lazy_static = { version = "1.4.0", default-features = false, features = ["spin_no_std"] }
 
 [target.'cfg(not(target_os = "dragonos"))'.dependencies]
-lazy_static = {version = "1.4.0"}
+lazy_static = { version = "1.4.0" }
 
 [profile.release]
 panic = 'abort'

+ 13 - 6
Makefile

@@ -1,15 +1,22 @@
 OUTPUT_DIR = $(DADK_BUILD_CACHE_DIR_DRAGONREACH_0_1_0)
+REACH_ETC_DIR=$(OUTPUT_DIR)/etc/reach
+REACH_BIN_DIR=$(OUTPUT_DIR)/bin/
+TMP_INSTALL_DIR=$(OUTPUT_DIR)/tmp_install
 
 build:
-	cargo -Z build-std=core,alloc,compiler_builtins build --target ./target.json
+	cargo -Z build-std=core,alloc,compiler_builtins build --target ./target.json --release
 
 install:
-	cp ./parse_test/shell.service $(ROOT_PATH)/bin/sysroot/etc/reach/system/shell.service
+	mkdir -p $(TMP_INSTALL_DIR)
+	mkdir -p $(REACH_ETC_DIR)
+	mkdir -p $(REACH_ETC_DIR)/system/
+	mkdir -p $(REACH_BIN_DIR)
 
-	mkdir -p $(OUTPUT_DIR)/tmp
-	cargo -Z build-std=core,alloc,compiler_builtins install --target $(TARGET) --path .  --root $(OUTPUT_DIR)/tmp
-	mv $(OUTPUT_DIR)/tmp/bin/DragonReach $(ROOT_PATH)/bin/user/DragonReach
-	rm -rf $(OUTPUT_DIR)/tmp
+	cp ./parse_test/shell.service $(REACH_ETC_DIR)/system/shell.service
+
+	cargo -Z build-std=core,alloc,compiler_builtins install --target $(TARGET) --path .  --root $(TMP_INSTALL_DIR)
+	mv $(OUTPUT_DIR)/tmp/bin/DragonReach $(REACH_BIN_DIR)/DragonReach
+	rm -rf $(TMP_INSTALL_DIR)
 
 build-linux:
 	cargo -Z build-std=core,alloc,compiler_builtins build --target x86_64-unknown-linux-gnu

+ 2 - 0
src/contants.rs

@@ -1,3 +1,5 @@
+#![allow(dead_code)]
+
 pub const AF_INET: i32 = 2;
 pub const AF_INET6: i32 = 10;
 

+ 0 - 3
src/error/mod.rs

@@ -1,6 +1,3 @@
-#[cfg(target_os = "dragonos")]
-use drstd as std;
-
 pub mod parse_error;
 pub mod runtime_error;
 

+ 0 - 2
src/error/parse_error/mod.rs

@@ -1,5 +1,3 @@
-#[cfg(target_os = "dragonos")]
-use drstd as std;
 use std::format;
 use std::string::String;
 use std::string::ToString;

+ 1 - 2
src/error/runtime_error/mod.rs

@@ -1,6 +1,5 @@
 use super::ErrorFormat;
-#[cfg(target_os = "dragonos")]
-use drstd as std;
+
 use std::format;
 use std::string::String;
 

+ 0 - 3
src/executor/dep_graph/mod.rs

@@ -1,6 +1,3 @@
-#[cfg(target_os = "dragonos")]
-use drstd as std;
-
 use std::sync::Arc;
 use std::sync::Mutex;
 use std::vec::Vec;

+ 0 - 3
src/executor/mod.rs

@@ -1,6 +1,3 @@
-#[cfg(target_os = "dragonos")]
-use drstd as std;
-
 pub mod dep_graph;
 pub mod service_executor;
 

+ 0 - 3
src/executor/service_executor/mod.rs

@@ -1,6 +1,3 @@
-#[cfg(target_os = "dragonos")]
-use drstd as std;
-
 use crate::{
     error::runtime_error::{RuntimeError, RuntimeErrorType},
     manager::{timer_manager::TimerManager, UnitManager},

+ 3 - 13
src/main.rs

@@ -3,14 +3,8 @@
 #![feature(slice_pattern)]
 #![feature(fn_traits)]
 
-use cfg_if::cfg_if;
-
-cfg_if! {
-    if #[cfg(target_os = "dragonos")]{
-        extern crate drstd;
-        use drstd as std;
-    }
-}
+#[cfg(target_os = "dragonos")]
+extern crate drstd as std;
 
 extern crate hashbrown;
 
@@ -41,11 +35,7 @@ fn main() {
     use manager::timer_manager::TimerManager;
     use parse::UnitParser;
 
-    use crate::{
-        executor::Executor,
-        manager::{Manager, UnitManager},
-        parse::parse_util::UnitParseUtil,
-    };
+    use crate::{executor::Executor, manager::Manager};
 
     let mut units_file_name = Vec::new();
     //读取目录里面的unit文件

+ 0 - 3
src/manager/mod.rs

@@ -1,6 +1,3 @@
-#[cfg(target_os = "dragonos")]
-use drstd as std;
-
 use std::{eprint, eprintln, print, println, vec::Vec};
 
 pub mod timer_manager;

+ 0 - 3
src/manager/timer_manager/mod.rs

@@ -1,6 +1,3 @@
-#[cfg(target_os = "dragonos")]
-use drstd as std;
-
 use crate::{error::runtime_error::RuntimeError, time::timer::Timer};
 use lazy_static::lazy_static;
 use std::{boxed::Box, sync::RwLock, time::Duration, vec::Vec};

+ 0 - 2
src/manager/unit_manager/mod.rs

@@ -1,5 +1,3 @@
-#[cfg(target_os = "dragonos")]
-use drstd as std;
 use std::hash::{Hash, Hasher};
 use std::{
     collections::hash_map::DefaultHasher,

+ 0 - 2
src/parse/graph/mod.rs

@@ -3,8 +3,6 @@ use crate::{
     unit::UnitType,
 };
 
-#[cfg(target_os = "dragonos")]
-use drstd as std;
 use std::io::BufRead;
 use std::string::{String, ToString};
 use std::vec::Vec;

+ 0 - 3
src/parse/mod.rs

@@ -7,9 +7,6 @@ use crate::{
     unit::{service::ServiceUnitAttr, BaseUnitAttr, InstallUnitAttr, UnitType},
 };
 
-#[cfg(target_os = "dragonos")]
-use drstd as std;
-
 use hashbrown::HashMap;
 use lazy_static::lazy_static;
 use std::format;

+ 0 - 3
src/parse/parse_service/mod.rs

@@ -4,9 +4,6 @@ use super::parse_util::UnitParseUtil;
 use crate::error::parse_error::ParseError;
 use crate::manager::UnitManager;
 
-#[cfg(target_os = "dragonos")]
-use drstd as std;
-
 use std::string::ToString;
 
 pub struct ServiceParser;

+ 0 - 3
src/parse/parse_target/mod.rs

@@ -4,9 +4,6 @@ use super::parse_util::UnitParseUtil;
 use crate::error::parse_error::ParseError;
 use crate::manager::UnitManager;
 
-#[cfg(target_os = "dragonos")]
-use drstd as std;
-
 use std::string::ToString;
 
 pub struct TargetParser;

+ 0 - 3
src/parse/parse_util/mod.rs

@@ -6,9 +6,6 @@ use crate::{
     FileDescriptor,
 };
 
-#[cfg(target_os = "dragonos")]
-use drstd as std;
-
 use std::{
     fs, io::BufRead, os::unix::prelude::PermissionsExt, path::Path, string::String,
     string::ToString, vec, vec::Vec,

+ 0 - 3
src/task/cmdtask/mod.rs

@@ -1,6 +1,3 @@
-#[cfg(target_os = "dragonos")]
-use drstd as std;
-
 use std::{eprint, eprintln, print, process::Command, string::String, vec::Vec};
 
 use crate::{

+ 0 - 2
src/time/mod.rs

@@ -1,4 +1,2 @@
-#[cfg(target_os = "dragonos")]
-use drstd as std;
 pub mod timer;
 pub mod watchdog;

+ 0 - 3
src/time/timer/mod.rs

@@ -1,6 +1,3 @@
-#[cfg(target_os = "dragonos")]
-use drstd as std;
-
 use std::boxed::Box;
 use std::time::{Duration, Instant};
 use std::{print, println};

+ 1 - 2
src/time/watchdog/mod.rs

@@ -1,2 +1 @@
-#[cfg(target_os = "dragonos")]
-use drstd as std;
+

+ 0 - 3
src/unit/mod.rs

@@ -6,9 +6,6 @@ use crate::executor::ExitStatus;
 use crate::parse::parse_util::UnitParseUtil;
 use crate::parse::Segment;
 
-#[cfg(target_os = "dragonos")]
-use drstd as std;
-
 use std::any::Any;
 use std::default::Default;
 use std::fmt::Debug;

+ 0 - 3
src/unit/service/mod.rs

@@ -9,9 +9,6 @@ use crate::parse::parse_util::UnitParseUtil;
 use crate::parse::{Segment, SERVICE_UNIT_ATTR_TABLE};
 use crate::task::cmdtask::CmdTask;
 
-#[cfg(target_os = "dragonos")]
-use drstd as std;
-
 use std::string::{String, ToString};
 
 use std::vec::Vec;

+ 1 - 2
src/unit/target/mod.rs

@@ -4,8 +4,7 @@ use crate::parse::parse_target::TargetParser;
 use crate::parse::Segment;
 
 use core::result::Result::{self, Ok};
-#[cfg(target_os = "dragonos")]
-use drstd as std;
+
 use std::marker::{Send, Sized, Sync};
 
 #[derive(Debug, Clone, Default)]