Rewrite Homebrew

This commit is contained in:
Aoran Zeng 2025-07-14 01:56:09 +08:00
parent e3dd337b28
commit 34c90e13f4
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
6 changed files with 152 additions and 123 deletions

11
rawstr4c.h Normal file
View File

@ -0,0 +1,11 @@
#pragma once
/**
* Generated by rawstr4c
*
* Date: 2025-07-13T23:31:21.307736+08:00
*/
char RAWSTR_wr_homebrew_read_config_cmd[] = "echo HOMEBREW_API_DOMAIN=$HOMEBREW_API_DOMAIN;\necho HOMEBREW_BOTTLE_DOMAIN=$HOMEBREW_BOTTLE_DOMAIN;\necho HOMEBREW_BREW_GIT_REMOTE=$HOMEBREW_BREW_GIT_REMOTE;\necho HOMEBREW_CORE_GIT_REMOTE=$HOMEBREW_CORE_GIT_REMOTE;\n";
char RAWSTR_wr_homebrew_config_in_bash[] = "# ------ chsrc BLOCK BEGIN for Homebrew ------\nexport HOMEBREW_BREW_GIT_REMOTE=\"@1@/git/homebrew/brew.git\"\nexport HOMEBREW_CORE_GIT_REMOTE=\"@1@/git/homebrew/homebrew-core.git\"\n# For Bottles\nexport HOMEBREW_API_DOMAIN=\"@1@/homebrew-bottles/api\"\nexport HOMEBREW_BOTTLE_DOMAIN=\"@1@/homebrew-bottles\"\n# ------ chsrc BLOCK ENDIN for Homebrew ------\n";
char RAWSTR_wr_homebrew_config_in_fish[] = "# ------ chsrc BLOCK BEGIN for Homebrew ------\nset -x HOMEBREW_BREW_GIT_REMOTE \"@1@/git/homebrew/brew.git\"\nset -x HOMEBREW_CORE_GIT_REMOTE \"@1@/git/homebrew/homebrew-core.git\"\n# For Bottles\nset -x HOMEBREW_API_DOMAIN \"@1@/homebrew-bottles/api\"\nset -x HOMEBREW_BOTTLE_DOMAIN \"@1@/homebrew-bottles\"\n# ------ chsrc BLOCK ENDIN for Homebrew ------\n";

View File

@ -30,7 +30,7 @@
* | Rui Yang <techoc@foxmail.com> * | Rui Yang <techoc@foxmail.com>
* | * |
* Created On : <2023-08-28> * Created On : <2023-08-28>
* Last Modified : <2025-07-12> * Last Modified : <2025-07-13>
* *
* chsrc: Change Source * chsrc: Change Source
* ------------------------------------------------------------*/ * ------------------------------------------------------------*/
@ -128,7 +128,7 @@
#include "recipe/ware/TeX-Live.c" #include "recipe/ware/TeX-Live.c"
#include "recipe/ware/Emacs.c" #include "recipe/ware/Emacs.c"
#include "recipe/ware/WinGet.c" #include "recipe/ware/WinGet.c"
#include "recipe/ware/Homebrew.c" #include "recipe/ware/Homebrew/Homebrew.c"
#include "recipe/ware/CocoaPods.c" #include "recipe/ware/CocoaPods.c"
#include "recipe/ware/Nix.c" #include "recipe/ware/Nix.c"
#include "recipe/ware/Guix.c" #include "recipe/ware/Guix.c"

View File

@ -1,111 +0,0 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Aoran Zeng <ccmywish@qq.com>
* Contributors : Nil Null <nil@null.org>
* Created On : <2023-09-10>
* Major Revision : 3
* Last Modified : <2025-06-16>
* ------------------------------------------------------------*/
/**
* @update 2023-09-10
* @note {
* 1. setsrc函数中补充完整
* 2. Sustech
* }
*/
static Source_t wr_homebrew_sources[] =
{
{&UpstreamProvider, NULL},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/"},
{&Zju, "https://mirrors.zju.edu.cn/"},
{&Sustech, "https://mirrors.sustech.edu.cn/"}
};
def_sources_n(wr_homebrew);
void
wr_homebrew_getsrc (char *option)
{
char *cmd = "echo HOMEBREW_API_DOMAIN=$HOMEBREW_API_DOMAIN;"
"echo HOMEBREW_BOTTLE_DOMAIN=$HOMEBREW_BOTTLE_DOMAIN;"
"echo HOMEBREW_BREW_GIT_REMOTE=$HOMEBREW_BREW_GIT_REMOTE;"
"echo HOMEBREW_CORE_GIT_REMOTE=$HOMEBREW_CORE_GIT_REMOTE;";
int status = system (cmd);
if (status != 0) { /* NOOP */ }
}
/**
* : https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/
*
* brew 4.0.0 (2023 2 16)
* HOMEBREW_INSTALL_FROM_API homebrew-core HOMEBREW_CORE_GIT_REMOTE
*
*/
void
wr_homebrew_setsrc (char *option)
{
chsrc_yield_source_and_confirm (wr_homebrew);
char *splitter = "\n# --- chsrc BLOCK BEGIN for Homebrew ---\n";
char *w1 = xy_strjoin (4, "export HOMEBREW_API_DOMAIN=\"", source.url, "homebrew-bottles/api", "\"\n");
char *w2 = xy_strjoin (4, "export HOMEBREW_BOTTLE_DOMAIN=\"", source.url, "homebrew-bottles", "\"\n");
char *w3 = xy_strjoin (4, "export HOMEBREW_BREW_GIT_REMOTE=\"", source.url, "git/homebrew/brew.git", "\"\n");
char *w4 = xy_strjoin (4, "export HOMEBREW_CORE_GIT_REMOTE=\"", source.url, "git/homebrew/homebrew-core.git", "\"\n");
char *end = "# --- chsrc BLOCK ENDIN for Homebrew ---\n";
char *w = xy_strjoin (6, splitter, w1, w2, w3, w4, end);
char *zshrc = xy_zshrc;
chsrc_backup (zshrc);
chsrc_append_to_file (w, zshrc);
char *bashrc = xy_bashrc;
if (xy_file_exist (bashrc))
{
chsrc_backup (bashrc);
chsrc_append_to_file (w, bashrc);
}
char *fishrc = xy_fishrc;
if (xy_file_exist (fishrc))
{
char *w1 = xy_strjoin(4, "set -x HOMEBREW_API_DOMAIN \"", source.url, "homebrew-bottles/api", "\"\n");
char *w2 = xy_strjoin(4, "set -x HOMEBREW_BOTTLE_DOMAIN \"", source.url, "homebrew-bottles", "\"\n");
char *w3 = xy_strjoin(4, "set -x HOMEBREW_BREW_GIT_REMOTE \"",source.url, "git/homebrew/brew.git", "\"\n");
char *w4 = xy_strjoin(4, "set -x HOMEBREW_CORE_GIT_REMOTE \"",source.url, "git/homebrew/homebrew-core.git", "\"\n");
char *w = xy_strjoin (6, splitter, w1, w2, w3, w4, end);
chsrc_backup (fishrc);
chsrc_append_to_file (w, fishrc);
}
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
chsrc_note2 ("请重启终端使Homebrew环境变量生效");
}
Feature_t
wr_homebrew_feat (char *option)
{
Feature_t f = {0};
f.can_get = true;
f.can_reset = false;
f.cap_locally = CanNot;
f.cap_locally_explain = NULL;
f.can_english = true;
/* 该换源方案中URL存在拼凑因此不能让用户手动使用某URL来换源 */
f.can_user_define = false;
f.note = "该换源通过写入环境变量实现若多次换源请手动清理profile文件";
return f;
}
def_target_gsf(wr_homebrew);

View File

@ -0,0 +1,102 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Aoran Zeng <ccmywish@qq.com>
* Contributors : Nil Null <nil@null.org>
* Created On : <2023-09-10>
* Major Revision : 3
* Last Modified : <2025-07-14>
* ------------------------------------------------------------*/
#include "rawstr4c.h"
/**
* @update 2025-07-13
*
* @note setsrc函数中补充完整
*/
static Source_t wr_homebrew_sources[] =
{
{&UpstreamProvider, NULL, NULL},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/", DelegateToMirror},
{&Bfsu, "https://mirrors.bfsu.edu.cn/", DelegateToMirror},
{&Nju, "https://mirror.nju.edu.cn/", DelegateToMirror},
{&Nyist, "https://mirror.nyist.edu.cn/", DelegateToMirror},
/* 注释原因: 这两者和其他镜像站URL补全结果不一样(2025-07-13) */
// {&Zju, "https://mirrors.zju.edu.cn/", DelegateToMirror},
// {&Cqu, "https://mirrors.cqu.edu.cn/", DelegateToMirror},
/* 注释原因: 该源已不存在(2025-07-13) */
// {&Sustech, "https://mirrors.sustech.edu.cn/", DelegateToMirror}
};
def_sources_n(wr_homebrew);
void
wr_homebrew_getsrc (char *option)
{
int status = system (RAWSTR_wr_homebrew_read_config_cmd);
if (status != 0) { /* NOOP */ }
}
/**
* @consult https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/
*
* brew 4.0.0 (2023 2 16)
* HOMEBREW_INSTALL_FROM_API homebrew-core HOMEBREW_CORE_GIT_REMOTE
*
*/
void
wr_homebrew_setsrc (char *option)
{
chsrc_yield_source_and_confirm (wr_homebrew);
char *w = RAWSTR_wr_homebrew_config_in_bash;
char *zshrc = xy_zshrc;
chsrc_backup (zshrc);
chsrc_append_to_file (w, zshrc);
char *bashrc = xy_bashrc;
if (xy_file_exist (bashrc))
{
chsrc_backup (bashrc);
chsrc_append_to_file (w, bashrc);
}
char *fishrc = xy_fishrc;
if (xy_file_exist (fishrc))
{
char *w = RAWSTR_wr_homebrew_config_in_fish;
chsrc_backup (fishrc);
chsrc_append_to_file (w, fishrc);
}
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
chsrc_note2 ("请重启终端使Homebrew环境变量生效");
}
Feature_t
wr_homebrew_feat (char *option)
{
Feature_t f = {0};
f.can_get = true;
f.can_reset = false;
f.cap_locally = CanNot;
f.cap_locally_explain = NULL;
f.can_english = true;
/* 该换源方案中URL存在拼凑因此不能让用户手动使用某URL来换源 */
f.can_user_define = false;
f.note = "该换源通过写入环境变量实现若多次换源请手动清理profile文件";
return f;
}
def_target_gsf(wr_homebrew);

View File

@ -0,0 +1,14 @@
#pragma once
/**
* Generated by rawstr4c
*
* Date: 2025-07-14T01:43:40.689870+08:00
*/
char RAWSTR_wr_homebrew_read_config_cmd[] = "echo HOMEBREW_API_DOMAIN=$HOMEBREW_API_DOMAIN;\necho HOMEBREW_BOTTLE_DOMAIN=$HOMEBREW_BOTTLE_DOMAIN;\necho HOMEBREW_BREW_GIT_REMOTE=$HOMEBREW_BREW_GIT_REMOTE;\necho HOMEBREW_CORE_GIT_REMOTE=$HOMEBREW_CORE_GIT_REMOTE;\n";
char RAWSTR_wr_homebrew_config_in_bash[] = "# ------ chsrc BLOCK BEGIN for Homebrew ------\nexport HOMEBREW_BREW_GIT_REMOTE=\"@1@/git/homebrew/brew.git\"\nexport HOMEBREW_CORE_GIT_REMOTE=\"@1@/git/homebrew/homebrew-core.git\"\n# For Bottles\nexport HOMEBREW_API_DOMAIN=\"@1@/homebrew-bottles/api\"\nexport HOMEBREW_BOTTLE_DOMAIN=\"@1@/homebrew-bottles\"\n# ------ chsrc BLOCK ENDIN for Homebrew ------\n";
char RAWSTR_wr_homebrew_config_in_fish[] = "# ------ chsrc BLOCK BEGIN for Homebrew ------\nset -x HOMEBREW_BREW_GIT_REMOTE \"@1@/git/homebrew/brew.git\"\nset -x HOMEBREW_CORE_GIT_REMOTE \"@1@/git/homebrew/homebrew-core.git\"\n# For Bottles\nset -x HOMEBREW_API_DOMAIN \"@1@/homebrew-bottles/api\"\nset -x HOMEBREW_BOTTLE_DOMAIN \"@1@/homebrew-bottles\"\n# ------ chsrc BLOCK ENDIN for Homebrew ------\n";

View File

@ -1,19 +1,30 @@
# rawstr4c input # rawstr4c input
- prefix = `_rawstr` 该文件尽可能测试 `rawstr4c` 的多个功能,以下三个变量的输出,将分别为:
1. `RAWSTR_wr_homebrew_read_config_cmd`
2. `RAWSTR_wr_homebrew_config_in_bash`
3. `RAWSTR_wr_homebrew_config_in_fish`
若不同,则生成有问题。
- prefix = `RAWSTR_wr_homebrew`
- postfix = `:use-language` - postfix = `:use-language`
- translate = `:escape` - translate = `:escape`
- output = `:terminal` - output = `:global-variable-only-header`
## Homebrew ## Homebrew
### read user config (for both Bash and Fish) ### read user env
- name = `read_config_cmd` 下面的命令对于 `Bash``Zsh``Fish` 都适用
- name = `RAWSTR_wr_homebrew_read_config_cmd`
- name-literally = `true` - name-literally = `true`
测试一下 name-literally 功能
```bash ```bash
echo HOMEBREW_API_DOMAIN=$HOMEBREW_API_DOMAIN; echo HOMEBREW_API_DOMAIN=$HOMEBREW_API_DOMAIN;
echo HOMEBREW_BOTTLE_DOMAIN=$HOMEBREW_BOTTLE_DOMAIN; echo HOMEBREW_BOTTLE_DOMAIN=$HOMEBREW_BOTTLE_DOMAIN;
@ -24,16 +35,16 @@ echo HOMEBREW_CORE_GIT_REMOTE=$HOMEBREW_CORE_GIT_REMOTE;
### Bash config ### Bash config
- keep-prefix = `true` - keep-prefix = `true`
- keep-postfix = `true` - keep-postfix = `false`
- name = `config` - name = `config_in_bash`
最终输出变量将会成为 `_rawstr4c_config_in_bash` 测试一下 keep-postfix 功能
```bash ```bash
# ------ chsrc BLOCK BEGIN for Homebrew ------ # ------ chsrc BLOCK BEGIN for Homebrew ------
export HOMEBREW_BREW_GIT_REMOTE="@1@/git/homebrew/brew.git" export HOMEBREW_BREW_GIT_REMOTE="@1@/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="@1@/git/homebrew/homebrew-core.git" export HOMEBREW_CORE_GIT_REMOTE="@1@/git/homebrew/homebrew-core.git"
# for bottles # For Bottles
export HOMEBREW_API_DOMAIN="@1@/homebrew-bottles/api" export HOMEBREW_API_DOMAIN="@1@/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="@1@/homebrew-bottles" export HOMEBREW_BOTTLE_DOMAIN="@1@/homebrew-bottles"
# ------ chsrc BLOCK ENDIN for Homebrew ------ # ------ chsrc BLOCK ENDIN for Homebrew ------
@ -44,11 +55,13 @@ export HOMEBREW_BOTTLE_DOMAIN="@1@/homebrew-bottles"
- name = `config` - name = `config`
- language = `fish` - language = `fish`
`Fish` 没有高亮,所以我们这里的 code block 用 `bash` 指示 ,我们刚好测试一下 language 功能
```bash ```bash
# ------ chsrc BLOCK BEGIN for Homebrew ------ # ------ chsrc BLOCK BEGIN for Homebrew ------
set -x HOMEBREW_BREW_GIT_REMOTE "@1@/git/homebrew/brew.git" set -x HOMEBREW_BREW_GIT_REMOTE "@1@/git/homebrew/brew.git"
set -x HOMEBREW_CORE_GIT_REMOTE "@1@/git/homebrew/homebrew-core.git" set -x HOMEBREW_CORE_GIT_REMOTE "@1@/git/homebrew/homebrew-core.git"
# for bottles # For Bottles
set -x HOMEBREW_API_DOMAIN "@1@/homebrew-bottles/api" set -x HOMEBREW_API_DOMAIN "@1@/homebrew-bottles/api"
set -x HOMEBREW_BOTTLE_DOMAIN "@1@/homebrew-bottles" set -x HOMEBREW_BOTTLE_DOMAIN "@1@/homebrew-bottles"
# ------ chsrc BLOCK ENDIN for Homebrew ------ # ------ chsrc BLOCK ENDIN for Homebrew ------