From cac80d1e3708c1067bda52219319aacc9327a5d9 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Tue, 24 Feb 2026 14:23:44 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=20`chef=5Fallow=5Flocal=5Fmo?= =?UTF-8?q?de()`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/framework/chef.c | 22 ---------------------- src/framework/core.c | 17 ----------------- src/framework/struct.h | 34 ++++++++++++++++++++++++++-------- src/recipe/recipe-template.c | 4 +--- 4 files changed, 27 insertions(+), 50 deletions(-) diff --git a/src/framework/chef.c b/src/framework/chef.c index cb9e2fe..f8a87de 100644 --- a/src/framework/chef.c +++ b/src/framework/chef.c @@ -357,28 +357,6 @@ chef_set_os_scope (Target_t *target) } -void -chef_allow_local_mode (Target_t *target, Capability_t cap, const char *explain_zh, const char *explain_en) -{ - xy_cant_be_null (target); - - target->cap_local = cap; - - if (cap == FullyCan) - { - target->cap_local_explain = xy_strdup (CHINESE ? "完全支持项目级换源" : "Supports project-level source switching"); - return; - } - - if (cap == CanNot) - { - target->cap_local_explain = xy_strdup (CHINESE ? "无法进行项目级换源" : "Unable to perform project-level source switching"); - return; - } - - target->cap_local_explain = xy_strdup (CHINESE ? explain_zh : explain_en); -} - void chef_allow_user_define (Target_t *target) diff --git a/src/framework/core.c b/src/framework/core.c index 40166f5..2576242 100644 --- a/src/framework/core.c +++ b/src/framework/core.c @@ -98,23 +98,6 @@ static bool in_dry_run_mode(){return ProgMode.DryRunMode;} */ -/** - * -local 的含义是启用 *项目级* 换源 - * - * 每个 target 对 [-local] 的支持情况可使用 | chsrc ls | 来查看 - * - * - * 1. 默认不使用该选项时,含义是 *全局* 换源, - * - * 全局分为 (1)系统级 (2)用户级 - * - * 大多数第三方配置软件往往默认进行的是 *用户级* 的配置。所以 chsrc 首先将尝试使用 *用户级* 配置 - * - * 2. 若不存在 *用户级* 的配置,chsrc 将采用 *系统级* 的配置 - * - * 3. 最终效果本质由第三方软件决定,如 poetry 默认实现的就是项目级的换源 - */ - typedef enum ChgType_t { ChgType_Auto, diff --git a/src/framework/struct.h b/src/framework/struct.h index 650dbce..1a67f35 100644 --- a/src/framework/struct.h +++ b/src/framework/struct.h @@ -95,11 +95,33 @@ Source_t; #define FeedByPrelude NULL - -/* 换源的作用域 */ -typedef enum Scope_t +/** + * 换源的作用域 + * + * 在 chsrc v0.2.4.2 以前,我们一直使用的是 `-local` 这个选项,其含义是启用 *项目级* 换源 + * + * 1. 默认不使用该选项时,含义是 *全局* 换源, + * + * 全局分为 (1)系统级 (2)用户级 + * + * 大多数第三方配置软件往往默认进行的是 *用户级* 的配置。所以 chsrc 首先将尝试使用 *用户级* 配置 + * + * 2. 若不存在 *用户级* 的配置,chsrc 将采用 *系统级* 的配置 + * + * 3. 最终效果本质由第三方软件决定,如 poetry 默认实现的就是项目级的换源 + * + * 但是后来,我们认为非 -local 时的行为(即默认时)比较模糊,所以我们现在清晰地把作用域指明出来,总共有3种类型的作用: + * 分别是 ProjectScope、UserScope 和 SystemScope,分别对应项目级、用户级和系统级的换源配置 + * + * 还有一个叫 DefaultScope 的作用域,它不是一种新类型,而只表示默认作用域,即根据实际情况最佳的作用域。 + * chsrc 将根据该 target 的实际情况来选择最合适的作用域来进行换源配置。最好的情况下,DefaultScope 是三者之一, + * 这也是这里设计的初衷。然而现在有些 recipe 的换源行为,会在某种 Scope 不能够成功时退而求其次地使用另一个 Scope + * 来进行换源配置,这时 DefaultScope 就无法用一种作用域单独描述。 + */ +#define NumberOfScopeType 3 + typedef enum Scope_t { - DefaultScope, /* 默认作用域,即根据实际情况最佳的作用域 */ + DefaultScope, /* 默认作用域,即根据实际情况最佳的作用域,它不是一种类型,只类似一个占位符 */ ProjectScope, UserScope, @@ -107,7 +129,6 @@ typedef enum Scope_t } Scope_t; -#define NumberOfScopeType 3 #define ScopeCap_Slot_Project 0 #define ScopeCap_Slot_User 1 #define ScopeCap_Slot_System 2 @@ -164,9 +185,6 @@ typedef struct Target_t bool can_user_define; /* 是否支持用户自定义URL来换源 */ char *can_user_define_explain; /* 用户自定义URL的说明 */ - Capability_t cap_local; /* 是否支持 local mode */ - char *cap_local_explain; /* local mode 的说明 */ - /** * 各作用域的支持情况 * 参考 ScopeCap_Slot_Xxx 的值 diff --git a/src/recipe/recipe-template.c b/src/recipe/recipe-template.c index cdbaa71..698ab1e 100644 --- a/src/recipe/recipe-template.c +++ b/src/recipe/recipe-template.c @@ -6,7 +6,7 @@ * Contributors : Mikachu2333 * | * Created On : <2024-08-09> - * Last Modified : <2026-02-22> + * Last Modified : <2026-02-24> * ------------------------------------------------------------- * 本文件作为一个通用模板: * @@ -70,8 +70,6 @@ void // 做了贡献?将自己的信息加在这里! chef_set_sauciers (this, 2, "@nulnone", "@someone"); - chef_allow_local_mode (this, PartiallyCan, "具体说明是否支持项目级换源...", "Tell users the local mode support"); - chef_set_scope_cap (this, ProjectScope, ScopeCap_Able_And_Implemented); chef_set_scope_cap (this, UserScope, ScopeCap_Able_But_NotImplemented); chef_set_scope_cap (this, SystemScope, ScopeCap_Unable);