Compare commits
3 Commits
xbzk-saf-r
...
selfhost0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4da9c6303b | ||
|
|
5478ddde87 | ||
|
|
8f1d895932 |
@@ -13,6 +13,11 @@ option(CPMUTIL_FORCE_BUNDLED
|
||||
option(CPMUTIL_FORCE_SYSTEM
|
||||
"Force system packages for all CPM dependencies (NOT RECOMMENDED)" OFF)
|
||||
|
||||
set(CPMUTIL_DEFAULT_HOST github.com CACHE STRING "Sets the default host when 'git_host' isn't defined")
|
||||
|
||||
option(CPMUTIL_FORCE_HOST
|
||||
"Force host CPMUTIL_DEFAULT_HOST to be used for all CPM dependencies even when 'git_host' is defined" OFF)
|
||||
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
include(CPM)
|
||||
|
||||
@@ -293,8 +298,8 @@ function(AddPackage)
|
||||
option(${PKG_ARGS_NAME}_FORCE_SYSTEM "Force the system package for ${PKG_ARGS_NAME}")
|
||||
option(${PKG_ARGS_NAME}_FORCE_BUNDLED "Force the bundled package for ${PKG_ARGS_NAME}")
|
||||
|
||||
if (NOT DEFINED PKG_ARGS_GIT_HOST)
|
||||
set(git_host github.com)
|
||||
if (CPMUTIL_FORCE_HOST OR NOT DEFINED PKG_ARGS_GIT_HOST)
|
||||
set(git_host ${CPMUTIL_DEFAULT_HOST})
|
||||
else()
|
||||
set(git_host ${PKG_ARGS_GIT_HOST})
|
||||
endif()
|
||||
|
||||
@@ -7,6 +7,8 @@ Global Options:
|
||||
- `CPMUTIL_FORCE_SYSTEM` (default `OFF`): Require all CPM dependencies to use system packages. NOT RECOMMENDED!
|
||||
* You may optionally override this (section)
|
||||
- `CPMUTIL_FORCE_BUNDLED` (default `ON` on MSVC and Android, `OFF` elsewhere): Require all CPM dependencies to use bundled packages.
|
||||
- `CPMUTIL_DEFAULT_HOST`: (default `github.com`): Sets the default `git_host`.
|
||||
- `CPMUTIL_FORCE_HOST`: (default `OFF`): Forces all CPM packages to use `CPMUTIL_DEFAULT_HOST` instead, even if they have `git_host` defined.
|
||||
|
||||
You are highly encouraged to read AddPackage first, even if you plan to only interact with CPMUtil via `AddJsonPackage`.
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ Tools for Eden and other subprojects.
|
||||
- `find-unused-strings.sh`: Find any unused strings in the Android app (XML -> Kotlin).
|
||||
|
||||
## Android
|
||||
|
||||
It's recommended to run these scritps after almost any Android change, as they are relatively fast and important both for APK bloat and CI.
|
||||
|
||||
- `unused-strings.sh`: Finds unused strings in `strings.xml` files.
|
||||
@@ -32,3 +33,7 @@ It's recommended to run these scritps after almost any Android change, as they a
|
||||
## Translations
|
||||
|
||||
- [Translation Scripts](./translations)
|
||||
|
||||
## Mirror
|
||||
|
||||
- [Mirroring scripts](./mirror)
|
||||
|
||||
@@ -13,7 +13,7 @@ MAXDEPTH=3
|
||||
# For your project you'll want to change this to define what dirs you have cpmfiles in
|
||||
# Remember to account for the MAXDEPTH variable!
|
||||
# Adding ./ before each will help to remove duplicates
|
||||
[ -z "$CPMFILES" ] && CPMFILES=$(find . ./src -maxdepth "$MAXDEPTH" -name cpmfile.json | sort | uniq)
|
||||
[ -z "$CPMFILES" ] && CPMFILES=$(find . ./src -maxdepth "$MAXDEPTH" -name cpmfile.json -not -path build | sort | uniq)
|
||||
|
||||
# shellcheck disable=SC2016
|
||||
[ -z "$PACKAGES" ] && PACKAGES=$(echo "$CPMFILES" | xargs jq -s 'reduce .[] as $item ({}; . * $item)')
|
||||
|
||||
6
tools/mirror/README.md
Normal file
6
tools/mirror/README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# Mirroring scripts
|
||||
|
||||
Scripts for setting up a Git mirror or performing offline work (i.e no GitHub) when using systems like CPM.
|
||||
|
||||
- `helper.sh`: Mini helper script - made for `cgit` jails but may work for Forgejo as well.
|
||||
- `common.sh`: Common functions and stuff.
|
||||
30
tools/mirror/common.sh
Normal file
30
tools/mirror/common.sh
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/bin/sh -e
|
||||
# SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
git_clone_mirror_repo() {
|
||||
NAME=$(echo "$1" | cut -d '/' -f 5)
|
||||
ORG=$(echo "$1" | cut -d '/' -f 4)
|
||||
git clone --mirror $1 $ORG/$NAME
|
||||
}
|
||||
git_retrieve_file() {
|
||||
TMPDIR=$1
|
||||
BRANCH=$(cd $TMPDIR && git rev-parse --abbrev-ref HEAD)
|
||||
cd $1 && git show $BRANCH:$2 2>/dev/null | git lfs smudge 2>/dev/null
|
||||
}
|
||||
git_retrieve_gitmodules() {
|
||||
TMP=$1
|
||||
git_retrieve_file $TMP '.gitmodules' | awk '{$1=$1};1' \
|
||||
| grep "url = " | sed "s,url = ,," \
|
||||
| while IFS= read -r line; do
|
||||
case "$line" in
|
||||
../*)
|
||||
# TODO: maybe one day handle case where its NOT ALL GITHUB - thanks boost
|
||||
ORGAN=$(echo "$TMP" | awk -F'/' '{print $2}')
|
||||
echo "$line" | sed "s|../|https://github.com/$ORGAN/|"
|
||||
;;
|
||||
http*)
|
||||
echo "$line"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
84
tools/mirror/helper.sh
Executable file
84
tools/mirror/helper.sh
Executable file
@@ -0,0 +1,84 @@
|
||||
#!/bin/sh -e
|
||||
# SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
# You must run this at the root of the eden git repo
|
||||
CPM_DIR=$PWD
|
||||
NPROC=$(nproc || echo 8)
|
||||
. ./tools/mirror/common.sh
|
||||
. ./tools/cpm/common.sh
|
||||
die() {
|
||||
echo "$@" >&2
|
||||
exit 1
|
||||
}
|
||||
help() {
|
||||
cat << EOF
|
||||
--path <path> Specify the given path (must be the root of your SCM folder)
|
||||
--initial Initial cloning (no submodules) - fetched from cpmfiles
|
||||
--clone-submodules Clones submodules, can also be used multiple times to clone
|
||||
newly referenced submodules
|
||||
--remote-update Update all remotes (of the repos) - aka. sync with remote
|
||||
--mirror Perform a mirror clone; URL must be specified before,
|
||||
if name or organisation are not specified, it is derived from URL
|
||||
--url Set URL of clone
|
||||
--org Set organisation folder of clone
|
||||
--name Set name of clone
|
||||
EOF
|
||||
}
|
||||
[ -z "$SCM_ROOT_DIR" ] && SCM_ROOT_DIR="/usr/local/jails/containers/cgit-www/srv/git/repos"
|
||||
|
||||
op_initial() {
|
||||
sudo chmod 777 $SCM_ROOT_DIR
|
||||
# stuff to parse the cpmfile json and then spit out full repo path
|
||||
REPOS=$(echo "$PACKAGES" \
|
||||
| jq -r 'reduce .[] as $i (""; . + (if $i.git_host == null then "https://github.com" else "https://" + $i.git_host end) + "/" + $i.repo + " ")' \
|
||||
| tr ' ' '\n' | xargs -I {} echo {})
|
||||
# clone the stuff
|
||||
cd $SCM_ROOT_DIR && echo "$REPOS" \
|
||||
| xargs -P $NPROC -I {} sh -c ". $CPM_DIR/tools/mirror/common.sh && git_clone_mirror_repo {}"
|
||||
sudo chmod 755 $SCM_ROOT_DIR
|
||||
}
|
||||
op_clone_submodules() {
|
||||
sudo chmod 777 $SCM_ROOT_DIR
|
||||
cd $SCM_ROOT_DIR && find . -maxdepth 2 -type d -name '*.git' -print0 \
|
||||
| xargs -0 -I {} sh -c ". $CPM_DIR/tools/mirror/common.sh && git_retrieve_gitmodules {}" \
|
||||
| while IFS= read -r url; do
|
||||
git_clone_mirror_repo $url || echo "skipped $url"
|
||||
done
|
||||
sudo chmod 755 $SCM_ROOT_DIR
|
||||
}
|
||||
op_remote_update() {
|
||||
sudo chmod 777 $SCM_ROOT_DIR
|
||||
cd $SCM_ROOT_DIR && find . -maxdepth 3 -type d -name '*.git' -print0 \
|
||||
| xargs -0 -P $NPROC -I {} sh -c 'cd {} && git remote update && echo {}'
|
||||
sudo chmod 755 $SCM_ROOT_DIR
|
||||
}
|
||||
op_mirror() {
|
||||
sudo chmod 777 $SCM_ROOT_DIR
|
||||
[ -z "$URL" ] && die "Specify repo --url"
|
||||
[ -z "$NAME" ] && NAME=$(echo "$URL" | cut -d '/' -f 5)
|
||||
[ -z "$ORG" ] && ORG=$(echo "$URL" | cut -d '/' -f 4)
|
||||
cd $SCM_ROOT_DIR && git clone --mirror $URL $ORG/$NAME || echo "skipped $URL"
|
||||
sudo chmod 755 $SCM_ROOT_DIR
|
||||
}
|
||||
|
||||
while true; do
|
||||
case "$1" in
|
||||
--path) shift; SCM_ROOT_DIR=$1; [ -z "$SCM_ROOT_DIR" ] && die "Empty target root dir";;
|
||||
--initial) OP_INITIAL=1;;
|
||||
--clone-submodules) OP_CLONE_SUBMODULES=1;;
|
||||
--remote-update) OP_REMOTE_UPDATE=1;;
|
||||
--mirror) OP_MIRROR=1;;
|
||||
--url) shift; URL=$1; [ -z "$URL" ] && die "Expected url";;
|
||||
--name) shift; NAME=$1; [ -z "$NAME" ] && die "Expected name";;
|
||||
--org) shift; ORG=$1; [ -z "$ORG" ] && die "Expected organisation";;
|
||||
--help) help "$@";;
|
||||
--*) die "Invalid option $1" ;;
|
||||
"$0" | "") break;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
[ "$OP_INITIAL" = 1 ] && op_initial
|
||||
[ "$OP_CLONE_SUBMODULES" = 1 ] && op_clone_submodules
|
||||
[ "$OP_REMOTE_UPDATE" = 1 ] && op_remote_update
|
||||
[ "$OP_MIRROR" = 1 ] && op_mirror
|
||||
Reference in New Issue
Block a user