diff --git a/src/recipe/menu.c b/src/recipe/menu.c index c31da9d704f702b8aa1e40be0fd508026fbfb31e..f49094db11571a34039ba9d24bbd7716836d1f6a 100644 --- a/src/recipe/menu.c +++ b/src/recipe/menu.c @@ -103,6 +103,8 @@ #include "ware/Flatpak.c" #include "ware/Docker/Docker.c" #include "ware/Anaconda/Anaconda.c" +#include "ware/Android-SDK.c" +#include "ware/Android-CLI.c" void @@ -183,6 +185,8 @@ chsrc_init_menu () add (emacs); add (tex); add (anaconda); + add (android_sdk); + add (android_cli); #undef add // Internal Target 不会由用户使用,需要特殊对待 diff --git a/src/recipe/ware/Android-CLI.c b/src/recipe/ware/Android-CLI.c new file mode 100644 index 0000000000000000000000000000000000000000..f6b4121bf21055c76546e2ff285c831d09ed6957 --- /dev/null +++ b/src/recipe/ware/Android-CLI.c @@ -0,0 +1,122 @@ +/** ------------------------------------------------------------ + * SPDX-License-Identifier: GPL-3.0-or-later + * ------------------------------------------------------------*/ + +static MirrorSite_t AndroidCLI_Alibaba = +{ + IS_DedicatedMirrorSite, + "aliyun", "Alibaba Cloud", "阿里云", "https://mirrors.aliyun.com/android.googlesource.com/", + {NotSkip, NA, NA, "https://mirrors.aliyun.com/android.googlesource.com/platform-tools", ACCURATE} +}; + +static MirrorSite_t AndroidCLI_Tencent = +{ + IS_DedicatedMirrorSite, + "tencent", "Tencent Cloud", "腾讯云", "https://mirrors.cloud.tencent.com/AndroidSDK/", + {NotSkip, NA, NA, "https://mirrors.cloud.tencent.com/AndroidSDK/repository2-1.xml", ACCURATE} +}; + +def_target(wr_android_cli, "android-cli"); + +void +wr_android_cli_prelude () +{ + chef_prep_this (wr_android_cli, gsr); + + chef_set_recipe_created_on (this, "2025-04-29"); + chef_set_recipe_last_updated (this, "2025-04-29"); + chef_set_sources_last_updated (this, "2025-04-29"); + + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); + + chef_set_scope_cap (this, ProjectScope, ScopeCap_Unable); + chef_set_scope_cap (this, UserScope, ScopeCap_Able_And_Implemented); + chef_set_scope_cap (this, SystemScope, ScopeCap_Unable); + chef_set_default_scope (this, UserScope); + + chef_deny_english(this); + chef_allow_user_define(this); + + chef_set_note (this, NULL, NULL); + + def_sources_begin() + {&UpstreamProvider, "https://dl.google.com/android/repository/", DelegateToUpstream}, + {&AndroidCLI_Alibaba, "https://mirrors.aliyun.com/android.googlesource.com/", DelegateToMirror}, + {&AndroidCLI_Tencent, "https://mirrors.cloud.tencent.com/AndroidSDK/", DelegateToMirror} + def_sources_end() +} + + +void +wr_android_cli_getsrc (char *option) +{ + char *android_cfg = xy_normalize_path ("~/.android/repositories.cfg"); + if (chsrc_check_file (android_cfg)) + chsrc_view_file (android_cfg); + else + chsrc_note2 ("未找到配置文件,请先运行 sdkmanager"); +} + + +static void +android_cli_write_cfg (char *path, char *url) +{ + FILE *fp = fopen (path, "w"); + if (fp == NULL) + return; + + fprintf (fp, "# Android SDK repositories.cfg\n"); + fprintf (fp, "%s\n", url); + fclose (fp); +} + + +/** + * @consult + * 1. https://developer.aliyun.com/mirror/android + * 2. https://mirrors.ustc.edu.cn/help/android/ + */ +void +wr_android_cli_setsrc (char *option) +{ + chsrc_use_this_source (wr_android_cli); + + char *android_dir = xy_normalize_path ("~/.android/"); + + chsrc_ensure_dir (android_dir); + + char *cfg_path = xy_strcat (2, android_dir, "repositories.cfg"); + + if (chsrc_check_file (cfg_path)) + { + chsrc_backup (cfg_path); + chsrc_note2 ("已找到配置文件,将自动换源"); + + char *cmd = xy_strcat (3, "sed -E -i 's#https?://[^/]+#", source.url, "#g' ", cfg_path); + chsrc_run (cmd, RunOpt_Default); + } + else + { + chsrc_note2 ("未找到配置文件,将创建新文件"); + android_cli_write_cfg (cfg_path, source.url); + } + + chsrc_note2 ("Android CLI 镜像源配置完成"); + + if (chsrc_check_program_quietly ("sdkmanager")) + { + chsrc_alert2 ("请手动运行: sdkmanager --update 以更新组件列表"); + } + + chsrc_determine_chgtype (ChgType_SemiAuto); + chsrc_conclude (&source); +} + + +void +wr_android_cli_resetsrc (char *option) +{ + wr_android_cli_setsrc (option); +} diff --git a/src/recipe/ware/Android-SDK.c b/src/recipe/ware/Android-SDK.c new file mode 100644 index 0000000000000000000000000000000000000000..e532e91f203ac84934dc7741e8e7081c93d6bb08 --- /dev/null +++ b/src/recipe/ware/Android-SDK.c @@ -0,0 +1,139 @@ +/** ------------------------------------------------------------ + * SPDX-License-Identifier: GPL-3.0-or-later + * ------------------------------------------------------------*/ + +static MirrorSite_t AndroidSDK_Tencent = +{ + IS_DedicatedMirrorSite, + "tencent", "Tencent Cloud", "腾讯云", "https://mirrors.cloud.tencent.com/AndroidSDK/", + {NotSkip, NA, NA, "https://mirrors.cloud.tencent.com/AndroidSDK/repository2-1.xml", ACCURATE} +}; + +static MirrorSite_t AndroidSDK_Alibaba = +{ + IS_DedicatedMirrorSite, + "aliyun", "Alibaba Cloud", "阿里云", "https://developer.aliyun.com/mirror/android", + {NotSkip, NA, NA, "https://developer.aliyun.com/mirror/android/repository2-1.xml", ACCURATE} +}; + +static MirrorSite_t AndroidSDK_Huawei = +{ + IS_DedicatedMirrorSite, + "huawei", "Huawei Cloud", "华为云", "https://developer.huawei.com/repo/", + {NotSkip, NA, NA, "https://developer.huawei.com/repo/repository2-1.xml", ACCURATE} +}; + +def_target(wr_android_sdk, "android"); + +void +wr_android_sdk_prelude () +{ + chef_prep_this (wr_android_sdk, gsr); + + chef_set_recipe_created_on (this, "2025-04-29"); + chef_set_recipe_last_updated (this, "2025-04-29"); + chef_set_sources_last_updated (this, "2025-04-29"); + + chef_set_chef (this, NULL); + chef_set_cooks (this, 1, "@ccmywish"); + chef_set_sauciers (this, 0); + + chef_set_scope_cap (this, ProjectScope, ScopeCap_Unable); + chef_set_scope_cap (this, UserScope, ScopeCap_Able_And_Implemented); + chef_set_scope_cap (this, SystemScope, ScopeCap_Unable); + chef_set_default_scope (this, UserScope); + + chef_deny_english(this); + chef_allow_user_define(this); + + chef_set_note (this, NULL, NULL); + + def_sources_begin() + {&UpstreamProvider, "https://dl.google.com/android/repository/repository2-1.xml", DelegateToUpstream}, + {&AndroidSDK_Tencent, "https://mirrors.cloud.tencent.com/AndroidSDK/", DelegateToMirror}, + {&AndroidSDK_Alibaba, "https://developer.aliyun.com/mirror/android", DelegateToMirror}, + {&AndroidSDK_Huawei, "https://developer.huawei.com/repo/", DelegateToMirror} + def_sources_end() +} + + +void +wr_android_sdk_getsrc (char *option) +{ + char *android_sdk_root = getenv ("ANDROID_SDK_ROOT"); + if (android_sdk_root == NULL) + android_sdk_root = getenv ("ANDROID_HOME"); + + if (android_sdk_root != NULL) + { + char *cfg_path = xy_strcat (3, android_sdk_root, "/", "repositories.cfg"); + if (chsrc_check_file (cfg_path)) + chsrc_view_file (cfg_path); + else + chsrc_note2 ("未找到 repositories.cfg 配置文件"); + } + else + { + chsrc_note2 ("请设置 ANDROID_SDK_ROOT 或 ANDROID_HOME 环境变量"); + } +} + + +/** + * @consult + * 1. https://mirrors.ustc.edu.cn/help/android/ + * 2. https://developer.aliyun.com/mirror/android + */ +void +wr_android_sdk_setsrc (char *option) +{ + chsrc_use_this_source (wr_android_sdk); + + char *android_sdk_root = getenv ("ANDROID_SDK_ROOT"); + if (android_sdk_root == NULL) + android_sdk_root = getenv ("ANDROID_HOME"); + + if (android_sdk_root == NULL) + { + chsrc_alert2 ("未设置 ANDROID_SDK_ROOT 或 ANDROID_HOME 环境变量"); + chsrc_alert2 ("请先安装 Android SDK 并设置环境变量"); + chsrc_alert2 ("或使用 chsrc set android-cli 仅为命令行工具换源"); + chsrc_determine_chgtype (ChgType_Manual); + chsrc_conclude (&source); + return; + } + + char *cfg_path = xy_strcat (3, android_sdk_root, "/", "repositories.cfg"); + + if (chsrc_check_file (cfg_path)) + { + chsrc_backup (cfg_path); + chsrc_note2 ("已找到 Android SDK 配置文件,将自动换源"); + + char *cmd = xy_strcat (3, "sed -E -i 's#https?://[^/]+#", source.url, "#g' ", cfg_path); + chsrc_run (cmd, RunOpt_Default); + } + else + { + chsrc_alert2 ("未找到 repositories.cfg,将创建新文件"); + chsrc_ensure_dir (android_sdk_root); + chsrc_append_to_file (source.url, cfg_path); + } + + chsrc_note2 ("Android SDK 镜像源配置完成"); + + if (chsrc_check_program_quietly ("sdkmanager")) + { + chsrc_note2 ("如需更新已安装组件,请运行: sdkmanager --update"); + } + + chsrc_determine_chgtype (ChgType_SemiAuto); + chsrc_conclude (&source); +} + + +void +wr_android_sdk_resetsrc (char *option) +{ + wr_android_sdk_setsrc (option); +}