|
@@ -1,11 +1,18 @@
|
|
-use std::{path::PathBuf, process::exit};
|
|
|
|
|
|
+use std::{
|
|
|
|
+ path::PathBuf,
|
|
|
|
+ process::exit,
|
|
|
|
+ sync::{Arc, Mutex, Weak},
|
|
|
|
+};
|
|
|
|
|
|
use derive_builder::Builder;
|
|
use derive_builder::Builder;
|
|
use log::error;
|
|
use log::error;
|
|
#[cfg(test)]
|
|
#[cfg(test)]
|
|
use test_base::{test_context::TestContext, BaseTestContext};
|
|
use test_base::{test_context::TestContext, BaseTestContext};
|
|
|
|
|
|
-use crate::{console::Action, executor::cache::cache_root_init, scheduler::task_deque::TASK_DEQUE};
|
|
|
|
|
|
+use crate::{
|
|
|
|
+ console::Action, executor::cache::cache_root_init, parser::task::TargetArch,
|
|
|
|
+ scheduler::task_deque::TASK_DEQUE,
|
|
|
|
+};
|
|
|
|
|
|
#[derive(Debug, Builder)]
|
|
#[derive(Debug, Builder)]
|
|
#[builder(setter(into))]
|
|
#[builder(setter(into))]
|
|
@@ -21,12 +28,21 @@ pub struct DadkExecuteContext {
|
|
/// dadk缓存根目录
|
|
/// dadk缓存根目录
|
|
cache_dir: Option<PathBuf>,
|
|
cache_dir: Option<PathBuf>,
|
|
|
|
|
|
|
|
+ /// 目标架构
|
|
|
|
+ #[builder(default = "crate::DADKTask::default_target_arch()")]
|
|
|
|
+ target_arch: TargetArch,
|
|
|
|
+
|
|
#[cfg(test)]
|
|
#[cfg(test)]
|
|
base_test_context: Option<BaseTestContext>,
|
|
base_test_context: Option<BaseTestContext>,
|
|
|
|
+
|
|
|
|
+ #[builder(setter(skip), default = "Mutex::new(Weak::new())")]
|
|
|
|
+ self_ref: Mutex<Weak<Self>>,
|
|
}
|
|
}
|
|
|
|
|
|
impl DadkExecuteContext {
|
|
impl DadkExecuteContext {
|
|
- pub fn init(&self) {
|
|
|
|
|
|
+ pub fn init(&self, self_arc: Arc<Self>) {
|
|
|
|
+ self.set_self_ref(Arc::downgrade(&self_arc));
|
|
|
|
+
|
|
// 初始化缓存目录
|
|
// 初始化缓存目录
|
|
let r: Result<(), crate::executor::ExecutorError> =
|
|
let r: Result<(), crate::executor::ExecutorError> =
|
|
cache_root_init(self.cache_dir().cloned());
|
|
cache_root_init(self.cache_dir().cloned());
|
|
@@ -56,6 +72,20 @@ impl DadkExecuteContext {
|
|
exit(1);
|
|
exit(1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ #[allow(dead_code)]
|
|
|
|
+ pub fn self_ref(&self) -> Option<Arc<Self>> {
|
|
|
|
+ self.self_ref.lock().unwrap().upgrade()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fn set_self_ref(&self, self_ref: Weak<Self>) {
|
|
|
|
+ *self.self_ref.lock().unwrap() = self_ref;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pub fn target_arch(&self) -> &TargetArch {
|
|
|
|
+ &self.target_arch
|
|
|
|
+ }
|
|
|
|
+
|
|
pub fn sysroot_dir(&self) -> Option<&PathBuf> {
|
|
pub fn sysroot_dir(&self) -> Option<&PathBuf> {
|
|
self.sysroot_dir.as_ref()
|
|
self.sysroot_dir.as_ref()
|
|
}
|
|
}
|
|
@@ -84,41 +114,65 @@ pub trait TestContextExt: TestContext {
|
|
fn execute_context(&self) -> &DadkExecuteContext;
|
|
fn execute_context(&self) -> &DadkExecuteContext;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+impl DadkExecuteContextBuilder {
|
|
|
|
+ /// 用于测试的默认构建器
|
|
|
|
+ #[cfg(test)]
|
|
|
|
+ fn default_test_execute_context_builder(
|
|
|
|
+ base_context: &BaseTestContext,
|
|
|
|
+ ) -> DadkExecuteContextBuilder {
|
|
|
|
+ DadkExecuteContextBuilder::default()
|
|
|
|
+ .sysroot_dir(Some(base_context.fake_dragonos_sysroot()))
|
|
|
|
+ .action(Action::Build)
|
|
|
|
+ .thread_num(None)
|
|
|
|
+ .cache_dir(Some(base_context.fake_dadk_cache_root()))
|
|
|
|
+ .base_test_context(Some(base_context.clone()))
|
|
|
|
+ .clone()
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
#[cfg(test)]
|
|
#[cfg(test)]
|
|
-pub struct DadkExecuteContextTestBuildV1 {
|
|
|
|
- context: DadkExecuteContext,
|
|
|
|
|
|
+pub struct DadkExecuteContextTestBuildX86_64V1 {
|
|
|
|
+ context: Arc<DadkExecuteContext>,
|
|
}
|
|
}
|
|
|
|
|
|
#[cfg(test)]
|
|
#[cfg(test)]
|
|
-impl TestContext for DadkExecuteContextTestBuildV1 {
|
|
|
|
|
|
+impl TestContext for DadkExecuteContextTestBuildX86_64V1 {
|
|
fn setup() -> Self {
|
|
fn setup() -> Self {
|
|
let base_context = BaseTestContext::setup();
|
|
let base_context = BaseTestContext::setup();
|
|
- let context = DadkExecuteContextBuilder::default()
|
|
|
|
- .sysroot_dir(Some(base_context.fake_dragonos_sysroot()))
|
|
|
|
- .config_dir(Some(base_context.config_v1_dir()))
|
|
|
|
- .action(Action::Build)
|
|
|
|
- .thread_num(None)
|
|
|
|
- .cache_dir(Some(base_context.fake_dadk_cache_root()))
|
|
|
|
- .base_test_context(Some(base_context))
|
|
|
|
- .build()
|
|
|
|
- .expect("Failed to build DadkExecuteContextTestBuildV1");
|
|
|
|
- context.init();
|
|
|
|
- DadkExecuteContextTestBuildV1 { context }
|
|
|
|
|
|
+ let context =
|
|
|
|
+ DadkExecuteContextBuilder::default_test_execute_context_builder(&base_context)
|
|
|
|
+ .target_arch(TargetArch::X86_64)
|
|
|
|
+ .config_dir(Some(base_context.config_v1_dir()))
|
|
|
|
+ .build()
|
|
|
|
+ .expect("Failed to build DadkExecuteContextTestBuildX86_64V1");
|
|
|
|
+ let context = Arc::new(context);
|
|
|
|
+ context.init(context.clone());
|
|
|
|
+ DadkExecuteContextTestBuildX86_64V1 { context }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#[cfg(test)]
|
|
#[cfg(test)]
|
|
-impl TestContextExt for DadkExecuteContextTestBuildV1 {
|
|
|
|
- fn base_context(&self) -> &BaseTestContext {
|
|
|
|
- self.base_test_context.as_ref().unwrap()
|
|
|
|
- }
|
|
|
|
|
|
+pub struct DadkExecuteContextTestBuildRiscV64V1 {
|
|
|
|
+ context: Arc<DadkExecuteContext>,
|
|
|
|
+}
|
|
|
|
|
|
- fn execute_context(&self) -> &DadkExecuteContext {
|
|
|
|
- &self.context
|
|
|
|
|
|
+#[cfg(test)]
|
|
|
|
+impl TestContext for DadkExecuteContextTestBuildRiscV64V1 {
|
|
|
|
+ fn setup() -> Self {
|
|
|
|
+ let base_context = BaseTestContext::setup();
|
|
|
|
+ let context =
|
|
|
|
+ DadkExecuteContextBuilder::default_test_execute_context_builder(&base_context)
|
|
|
|
+ .target_arch(TargetArch::RiscV64)
|
|
|
|
+ .config_dir(Some(base_context.config_v1_dir()))
|
|
|
|
+ .build()
|
|
|
|
+ .expect("Failed to build DadkExecuteContextTestBuildRiscV64V1");
|
|
|
|
+ let context = Arc::new(context);
|
|
|
|
+ context.init(context.clone());
|
|
|
|
+ DadkExecuteContextTestBuildRiscV64V1 { context }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-macro_rules! impl_deref_for_test_context {
|
|
|
|
|
|
+macro_rules! impl_for_test_context {
|
|
($context:ty) => {
|
|
($context:ty) => {
|
|
#[cfg(test)]
|
|
#[cfg(test)]
|
|
impl std::ops::Deref for $context {
|
|
impl std::ops::Deref for $context {
|
|
@@ -130,12 +184,17 @@ macro_rules! impl_deref_for_test_context {
|
|
}
|
|
}
|
|
|
|
|
|
#[cfg(test)]
|
|
#[cfg(test)]
|
|
- impl std::ops::DerefMut for $context {
|
|
|
|
- fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
- &mut self.context
|
|
|
|
|
|
+ impl TestContextExt for $context {
|
|
|
|
+ fn base_context(&self) -> &BaseTestContext {
|
|
|
|
+ self.base_test_context.as_ref().unwrap()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fn execute_context(&self) -> &DadkExecuteContext {
|
|
|
|
+ &self.context
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
-impl_deref_for_test_context!(DadkExecuteContextTestBuildV1);
|
|
|
|
|
|
+impl_for_test_context!(DadkExecuteContextTestBuildX86_64V1);
|
|
|
|
+impl_for_test_context!(DadkExecuteContextTestBuildRiscV64V1);
|