Main use framework

This commit is contained in:
Aoran Zeng 2025-03-07 10:58:25 +08:00
parent bc4bf113f4
commit 05984d5710
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
24 changed files with 77 additions and 49 deletions

View File

@ -65,15 +65,15 @@ ifeq ($(STATIC), 1)
CFLAGS += -static
endif
all:
@$(CC) src/chsrc-main.c $(CFLAGS) $(_C_Warning_Flags) -o $(Target-Name)
all: framework
@$(CC) src/chsrc-main.c src/framework/core.o $(CFLAGS) $(_C_Warning_Flags) -o $(Target-Name)
@echo; echo Compile done using \'$(CC)\' $(CFLAGS)
CI: all
@mv $(Target-Name) $(CI_ARTIFACT_NAME)
framework: src/framework/core.o
src/framework/core.o:
src/framework/core.o: src/framework/core.c
@$(CC) src/framework/core.c -c $(CFLAGS) $(_C_Warning_Flags) -o src/framework/core.o
@echo; echo Compile done: core.o

View File

@ -23,17 +23,15 @@
* | juzeon <skyjuzheng@gmail.com>
* |
* Created On : <2023-08-28>
* Last Modified : <2025-03-04>
* Last Modified : <2025-03-07>
*
* chsrc: Change Source
* ------------------------------------------------------------*/
#define Chsrc_Version "0.2.0-dev1"
#define Chsrc_Release_Date "2024/12/18"
#define Chsrc_Maintain_URL "https://github.com/RubyMetric/chsrc"
#define Chsrc_Maintain_URL2 "https://gitee.com/RubyMetric/chsrc"
#include "framework/core.c"
#include "chsrc-framework.h"
#include "recipe/lang/Ruby.c"

View File

@ -14,6 +14,9 @@
* recipe include
* ------------------------------------------------------------*/
#ifndef CHSRC_FRAMEWORK_H
#define CHSRC_FRAMEWORK_H
#include <xy.h>
#include "struct.h"
#include "mirror.h"
@ -102,15 +105,12 @@ extern bool CliOpt_NoColor;
void chsrc_note2 (const char *str);
#define YesMark "✓"
#define NoMark "x"
#define HalfYesMark "⍻"
enum ChgType_t
{
ChgType_Auto,
ChgType_Reset,
ChgType_SemiAuto,
ChgType_Manual,
ChgType_Untested
};
#define hr() say ("--------------------------------");
int select_mirror_autoly (Source_t *sources, size_t size, const char *target_name);
@ -167,6 +167,12 @@ void chsrc_confirm_source (Source_t *source);
bool is_url (const char *str);
#define Quiet_When_Exist 0x00
#define Noisy_When_Exist 0x01
#define Quiet_When_NonExist 0x00
#define Noisy_When_NonExist 0x10
bool chsrc_query_program_exist (char *prog_name, char *check_cmd, int mode);
bool chsrc_check_program (char *prog_name);
bool chsrc_check_program_quietly (char *prog_name);
@ -175,29 +181,39 @@ void chsrc_ensure_program (char *prog_name);
bool chsrc_check_file (char *path);
enum ChgType_t
{
ChgType_Auto,
ChgType_Reset,
ChgType_SemiAuto,
ChgType_Manual,
ChgType_Untested
};
void chsrc_determine_chgtype (enum ChgType_t type);
void chsrc_ensure_root ();
void chsrc_conclude (Source_t *source);
#define RunOpt_Default 0x0000 // 默认若命令运行失败,直接退出
#define RunOpt_Dont_Notify_On_Success 0x0010 // 运行成功不提示用户,只有运行失败时才提示用户
#define RunOpt_No_Last_New_Line 0x0100 // 不输出最后的空行
#define RunOpt_Dont_Abort_On_Failure 0x1000 // 命令运行失败也不退出
void chsrc_run (const char *cmd, int run_option);
void chsrc_ensure_root ();
void chsrc_ensure_dir (const char *dir);
void chsrc_view_file (const char *path);
void chsrc_ensure_dir (const char *dir);
void chsrc_append_to_file (const char *str, const char *filename);
void chsrc_prepend_to_file (const char *str, const char *filename);
void chsrc_overwrite_file (const char *str, const char *filename);
void chsrc_backup (const char *path);
char * chsrc_get_cpuarch ();
int chsrc_get_cpucore ();
#endif

View File

@ -64,9 +64,6 @@ log_backup_op (const char *filename)
xy_log_brkt (blue(App_Name), bdblue(msg), xy_strjoin (3, bdyellow(filename), " -> ", bdgreen(bak)));
}
#define YesMark "✓"
#define NoMark "x"
#define HalfYesMark "⍻"
static void
@ -144,11 +141,6 @@ is_url (const char *str)
#define Quiet_When_Exist 0x00
#define Noisy_When_Exist 0x01
#define Quiet_When_NonExist 0x00
#define Noisy_When_NonExist 0x10
/**
*
*
@ -717,8 +709,6 @@ is_reset_mode ()
#define hr() say ("--------------------------------");
/**
* _setsrc

View File

@ -7,6 +7,8 @@
* Last Modified : <2024-08-09>
* ------------------------------------------------------------*/
#include <chsrc-framework.h>
/**
* @update 2023-09-10
* @note

View File

@ -9,6 +9,8 @@
* Last Modified : <2024-12-18>
* ------------------------------------------------------------*/
#include <chsrc-framework.h>
static SourceProvider_t pl_go_upstream =
{
def_upstream, "https://pkg.go.dev/",
@ -44,11 +46,11 @@ def_sources_n(pl_go);
void
static void
pl_go_check_cmd ()
{
char *check_cmd = xy_str_to_quietcmd ("go version");
bool exist = query_program_exist (check_cmd, "go", Noisy_When_Exist|Noisy_When_NonExist);
bool exist = chsrc_query_program_exist ("go", check_cmd, Noisy_When_Exist|Noisy_When_NonExist);
if (!exist)
{

View File

@ -7,6 +7,8 @@
* Last Modified : <2024-08-15>
* ------------------------------------------------------------*/
#include <chsrc-framework.h>
/**
* @update 2023-09-10
*/

View File

@ -8,6 +8,8 @@
* Last Modified : <2024-12-18>
* ------------------------------------------------------------*/
#include <chsrc-framework.h>
static SourceProvider_t pl_java_upstream =
{
def_upstream, "https://mvnrepository.com/",
@ -27,7 +29,7 @@ static Source_t pl_java_sources[] =
def_sources_n(pl_java);
void
static void
pl_java_check_cmd (bool *maven_exist, bool *gradle_exist)
{
*maven_exist = chsrc_check_program ("mvn");
@ -40,7 +42,7 @@ pl_java_check_cmd (bool *maven_exist, bool *gradle_exist)
}
}
char *
static char *
pl_java_find_maven_config ()
{
char *buf = xy_run ("mvn -v", 2);

View File

@ -7,6 +7,8 @@
* Last Modified : <2024-11-22>
* ------------------------------------------------------------*/
#include <chsrc-framework.h>
/**
* @update 2023-09-05
* @note

View File

@ -7,6 +7,8 @@
* Last Modified : <2024-08-09>
* ------------------------------------------------------------*/
#include <chsrc-framework.h>
static MirrorSite_t Api7 =
{
"api7", "api7.ai", "深圳支流科技有限公司", "https://www.apiseven.com/",

View File

@ -43,7 +43,7 @@ pl_nodejs_yarn_setsrc (char *option)
Source_t source;
chsrc_yield_for_the_source (pl_nodejs);
if (ProgMode_Target_Group!=true)
chsrc_confirm_source;
chsrc_confirm_source(&source);
char *cmd = NULL;

View File

@ -29,7 +29,7 @@ pl_nodejs_npm_setsrc (char *option)
Source_t source;
chsrc_yield_for_the_source (pl_nodejs);
if (ProgMode_Target_Group!=true)
chsrc_confirm_source;
chsrc_confirm_source(&source);
char *cmd = NULL;

View File

@ -30,7 +30,7 @@ pl_nodejs_pnpm_setsrc (char *option)
Source_t source;
chsrc_yield_for_the_source (pl_nodejs);
if (ProgMode_Target_Group!=true)
chsrc_confirm_source;
chsrc_confirm_source(&source);
char *cmd = NULL;

View File

@ -7,6 +7,8 @@
* Last Modified : <2024-08-09>
* ------------------------------------------------------------*/
#include <chsrc-framework.h>
static MirrorSite_t NugetOrg =
{
"nuget.org", "NuGet Org", "Nuget Organization", "https://www.nuget.org/",

View File

@ -7,6 +7,8 @@
* Last Modified : <2024-08-15>
* ------------------------------------------------------------*/
#include <chsrc-framework.h>
/**
* @update 2023-09-15
*/
@ -18,7 +20,7 @@ static Source_t pl_ocaml_sources[] =
def_sources_n(pl_ocaml);
void
static void
pl_ocaml_check_cmd ()
{
chsrc_ensure_program ("opam");

View File

@ -7,6 +7,8 @@
* Last Modified : <2024-11-22>
* ------------------------------------------------------------*/
#include <chsrc-framework.h>
/**
* @update 2024-09-14
* @note

View File

@ -8,6 +8,8 @@
* Last Modified : <2024-12-18>
* ------------------------------------------------------------*/
#include <chsrc-framework.h>
static SourceProvider_t pl_perl_upstream =
{
def_upstream, "https://metacpan.org/",
@ -30,7 +32,7 @@ static Source_t pl_perl_sources[] =
def_sources_n(pl_perl);
void
static void
pl_perl_check_cmd ()
{
chsrc_ensure_program ("perl");

View File

@ -31,7 +31,7 @@ pl_python_pdm_setsrc (char *option)
Source_t source;
chsrc_yield_for_the_source (pl_python);
if (ProgMode_Target_Group!=true)
chsrc_confirm_source;
chsrc_confirm_source(&source);
char *cmd = NULL;

View File

@ -30,7 +30,7 @@ pl_python_poetry_setsrc (char *option)
Source_t source;
chsrc_yield_for_the_source (pl_python);
if (ProgMode_Target_Group!=true)
chsrc_confirm_source;
chsrc_confirm_source(&source);
char *cmd = NULL;

View File

@ -41,7 +41,7 @@ pl_python_pip_setsrc (char *option)
Source_t source;
chsrc_yield_for_the_source (pl_python);
if (ProgMode_Target_Group!=true)
chsrc_confirm_source;
chsrc_confirm_source(&source);
char *py_prog_name = NULL;
pl_python_get_py_program_name (&py_prog_name);

View File

@ -7,6 +7,8 @@
* Last Modified : <2024-11-22>
* ------------------------------------------------------------*/
#include <chsrc-framework.h>
/**
* @update 2023-09-04
* @note {

View File

@ -8,6 +8,8 @@
* Last Modified : <2024-12-18>
* ------------------------------------------------------------*/
#include <chsrc-framework.h>
static SourceProvider_t pl_ruby_upstream =
{
def_upstream, "https://rubygems.org",
@ -51,7 +53,7 @@ pl_ruby_getsrc (char *option)
chsrc_run ("bundle config get mirror.https://rubygems.org", RunOpt_Default);
}
void
static void
pl_ruby_remove_gem_source (const char *source)
{
char *cmd = NULL;

View File

@ -42,7 +42,7 @@ os_freebsd_setsrc (char *option)
int index = use_specific_mirror_or_auto_select (option, os_freebsd);
Source_t source = os_freebsd_sources[index];
chsrc_confirm_source;
chsrc_confirm_source(&source);
chsrc_log2 ("1. 添加 freebsd-pkg 源 (二进制安装包)");
chsrc_ensure_dir ("/usr/local/etc/pkg/repos");
@ -67,7 +67,7 @@ os_freebsd_setsrc (char *option)
// @ccmywish: [2023-09-27] 据 @ykla , NJU的freebsd-ports源没有设置 Git
// 但是我认为由于使用Git还是要比非Git方便许多我们尽可能坚持使用Git
// 而 gitup 又要额外修改它自己的配置,比较麻烦
bool git_exist = query_program_exist (xy_str_to_quietcmd ("git version"), "git", Noisy_When_Exist|Noisy_When_NonExist);
bool git_exist = chsrc_query_program_exist ("git", xy_str_to_quietcmd ("git version"), Noisy_When_Exist|Noisy_When_NonExist);
if (git_exist)
{
if (xy_streql("nju",source.mirror->code))

View File

@ -23,7 +23,7 @@ static Source_t wr_anaconda_sources[] =
{&Zju, "https://mirrors.zju.edu.cn/anaconda/"},
{&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/anaconda"},
{&Pku, "https://mirrors.pku.edu.cn/anaconda/"},
{&NJTech, "https://mirrors.njtech.edu.cn/anaconda/"},
{&Njtech, "https://mirrors.njtech.edu.cn/anaconda/"},
};
def_sources_n(wr_anaconda);