2022-12-07 19:06:24 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-02-17 16:39:17 +00:00
|
|
|
### This script is used for synchronizing the dotnet/dotnet VMR locally. This means pulling new
|
|
|
|
### code from various repositories into the 'dotnet/dotnet' repository.
|
2022-12-07 19:06:24 +00:00
|
|
|
###
|
2023-02-17 16:39:17 +00:00
|
|
|
### The script is used during CI to ingest new code based on dotnet/installer but it can also help
|
|
|
|
### for reproducing potential failures during installer's PRs, namely to fix the Source-Build.
|
|
|
|
### Another usecase is to try manually synchronizing a given commit of some repo into the VMR and
|
|
|
|
### trying to Source-Build the VMR. This can help when fixing the Source-Build but using a commit
|
|
|
|
### from a not-yet merged branch (or fork) to test the fix will help.
|
2022-12-07 19:06:24 +00:00
|
|
|
###
|
2023-02-17 16:39:17 +00:00
|
|
|
### The tooling that synchronizes the VMR will need to clone the various repositories into a temporary
|
|
|
|
### folder. These clones can be re-used in future synchronizations so it is advised you dedicate a
|
|
|
|
### folder to this to speed up your re-runs.
|
2022-12-07 19:06:24 +00:00
|
|
|
###
|
|
|
|
### USAGE:
|
2023-02-17 16:39:17 +00:00
|
|
|
### Synchronize the VMR to a specific commit of dotnet/runtime using custom fork:
|
|
|
|
### ./vmr-sync.sh \
|
|
|
|
### --repository runtime:e7e71da303af8dc97df99b098f21f526398c3943 \
|
2023-03-13 13:44:42 +00:00
|
|
|
### --remote runtime:https://github.com/yourfork/runtime \
|
|
|
|
### --tmp-dir "$HOME/repos/tmp"
|
2023-02-17 16:39:17 +00:00
|
|
|
###
|
2022-12-07 19:06:24 +00:00
|
|
|
### Options:
|
2023-03-13 13:44:42 +00:00
|
|
|
### -r, --repository name:GIT_REF
|
|
|
|
### Required. Repository + git ref separated by colon to synchronize to.
|
|
|
|
### This can be a specific commit, branch, tag..
|
|
|
|
###
|
2022-12-07 19:06:24 +00:00
|
|
|
### -t, --tmp, --tmp-dir PATH
|
|
|
|
### Required. Path to the temporary folder where repositories will be cloned
|
2023-03-13 13:44:42 +00:00
|
|
|
###
|
2022-12-07 19:06:24 +00:00
|
|
|
### -b, --branch, --vmr-branch BRANCH_NAME
|
2023-03-13 13:44:42 +00:00
|
|
|
### Optional. Branch of the 'dotnet/dotnet' repo to synchronize. The VMR will be checked out to this branch
|
|
|
|
###
|
|
|
|
### --debug
|
|
|
|
### Optional. Turns on the most verbose logging for the VMR tooling
|
|
|
|
###
|
2023-02-09 09:40:04 +00:00
|
|
|
### --readme-template
|
2023-02-17 16:39:17 +00:00
|
|
|
### Optional. Template for VMRs README.md used for regenerating the file to list the newest versions of
|
|
|
|
### components.
|
2023-02-09 09:40:04 +00:00
|
|
|
### Defaults to src/VirtualMonoRepo/README.template.md
|
2023-03-13 13:44:42 +00:00
|
|
|
###
|
|
|
|
### --recursive
|
|
|
|
### Optional. Recursively synchronize all the source build dependencies (declared in Version.Details.xml)
|
|
|
|
### This is used when performing the full synchronization during installer's CI and the final VMR sync.
|
|
|
|
### Defaults to false unless no repository is supplied in which case a recursive sync of installer is performed.
|
|
|
|
###
|
|
|
|
### --remote name:URI
|
|
|
|
### Optional. Additional remote to use during the synchronization
|
|
|
|
### This can be used to synchronize to a commit from a fork of the repository
|
|
|
|
### Example: 'runtime:https://github.com/yourfork/runtime'
|
|
|
|
###
|
2023-02-09 09:40:04 +00:00
|
|
|
### --tpn-template
|
|
|
|
### Optional. Template for the header of VMRs THIRD-PARTY-NOTICES file.
|
|
|
|
### Defaults to src/VirtualMonoRepo/THIRD-PARTY-NOTICES.template.txt
|
2023-03-13 13:44:42 +00:00
|
|
|
###
|
|
|
|
### -v, --vmr, --vmr-dir PATH
|
|
|
|
### Optional. Path to the dotnet/dotnet repository. When null, gets cloned to the temporary folder
|
2022-12-07 19:06:24 +00:00
|
|
|
|
|
|
|
source="${BASH_SOURCE[0]}"
|
|
|
|
|
|
|
|
# resolve $source until the file is no longer a symlink
|
|
|
|
while [[ -h "$source" ]]; do
|
|
|
|
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
|
|
|
|
source="$(readlink "$source")"
|
|
|
|
# if $source was a relative symlink, we need to resolve it relative to the path where the
|
|
|
|
# symlink file was located
|
|
|
|
[[ $source != /* ]] && source="$scriptroot/$source"
|
|
|
|
done
|
|
|
|
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
|
|
|
|
|
|
|
|
function print_help () {
|
|
|
|
sed -n '/^### /,/^$/p' "$source" | cut -b 5-
|
|
|
|
}
|
|
|
|
|
|
|
|
COLOR_RED=$(tput setaf 1 2>/dev/null || true)
|
|
|
|
COLOR_CYAN=$(tput setaf 6 2>/dev/null || true)
|
|
|
|
COLOR_CLEAR=$(tput sgr0 2>/dev/null || true)
|
|
|
|
COLOR_RESET=uniquesearchablestring
|
|
|
|
FAILURE_PREFIX='> '
|
|
|
|
|
|
|
|
function fail () {
|
|
|
|
echo "${COLOR_RED}$FAILURE_PREFIX${1//${COLOR_RESET}/${COLOR_RED}}${COLOR_CLEAR}" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
function highlight () {
|
|
|
|
echo "${COLOR_CYAN}$FAILURE_PREFIX${1//${COLOR_RESET}/${COLOR_CYAN}}${COLOR_CLEAR}"
|
|
|
|
}
|
|
|
|
|
2023-01-13 15:00:30 +00:00
|
|
|
installer_dir=$(realpath "$scriptroot/../")
|
2023-03-13 13:44:42 +00:00
|
|
|
|
2022-12-07 19:06:24 +00:00
|
|
|
tmp_dir=''
|
|
|
|
vmr_dir=''
|
2023-03-13 13:44:42 +00:00
|
|
|
vmr_branch=''
|
2023-02-17 16:39:17 +00:00
|
|
|
repository=''
|
2023-03-13 13:44:42 +00:00
|
|
|
additional_remotes=''
|
2023-02-17 16:39:17 +00:00
|
|
|
recursive=false
|
2022-12-07 19:06:24 +00:00
|
|
|
verbosity=verbose
|
2023-02-17 16:39:17 +00:00
|
|
|
readme_template="$installer_dir/src/VirtualMonoRepo/README.template.md"
|
|
|
|
tpn_template="$installer_dir/src/VirtualMonoRepo/THIRD-PARTY-NOTICES.template.txt"
|
2022-12-07 19:06:24 +00:00
|
|
|
|
2023-03-13 13:44:42 +00:00
|
|
|
# If installer is a repo, we're in an installer and not in the dotnet/dotnet repo
|
|
|
|
if [[ -d "$installer_dir/.git" ]]; then
|
|
|
|
additional_remotes="installer:$installer_dir"
|
|
|
|
fi
|
|
|
|
|
2022-12-07 19:06:24 +00:00
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
opt="$(echo "$1" | tr "[:upper:]" "[:lower:]")"
|
|
|
|
case "$opt" in
|
|
|
|
-t|--tmp|--tmp-dir)
|
|
|
|
tmp_dir=$2
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-v|--vmr|--vmr-dir)
|
|
|
|
vmr_dir=$2
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-b|--branch|--vmr-branch)
|
|
|
|
vmr_branch=$2
|
|
|
|
shift
|
|
|
|
;;
|
2023-03-13 13:44:42 +00:00
|
|
|
-r|--repository)
|
2023-02-17 16:39:17 +00:00
|
|
|
repository=$2
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--recursive)
|
|
|
|
recursive=true
|
2022-12-07 19:06:24 +00:00
|
|
|
;;
|
2023-02-17 16:39:17 +00:00
|
|
|
--remote)
|
|
|
|
additional_remotes="$additional_remotes,$2"
|
2023-01-09 13:28:34 +00:00
|
|
|
shift
|
|
|
|
;;
|
2023-02-08 12:44:25 +00:00
|
|
|
--readme-template)
|
|
|
|
readme_template=$2
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--tpn-template)
|
|
|
|
tpn_template=$2
|
|
|
|
shift
|
|
|
|
;;
|
2023-02-17 16:39:17 +00:00
|
|
|
-d|--debug)
|
|
|
|
verbosity=debug
|
|
|
|
;;
|
2022-12-07 19:06:24 +00:00
|
|
|
-h|--help)
|
|
|
|
print_help
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
fail "Invalid argument: $1"
|
2023-03-13 13:44:42 +00:00
|
|
|
print_help
|
2022-12-07 19:06:24 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2023-02-17 16:39:17 +00:00
|
|
|
# Validation
|
|
|
|
|
2022-12-07 19:06:24 +00:00
|
|
|
if [[ ! -d "$installer_dir" ]]; then
|
|
|
|
fail "Directory '$installer_dir' does not exist. Please specify the path to the dotnet/installer repo"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "$tmp_dir" ]]; then
|
|
|
|
fail "Missing --tmp-dir argument. Please specify the path to the temporary folder where the repositories will be cloned"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-02-09 09:40:04 +00:00
|
|
|
if [[ ! -f "$readme_template" ]]; then
|
|
|
|
fail "File '$readme_template' does not exist. Please specify a valid path to the README template"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -f "$tpn_template" ]]; then
|
|
|
|
fail "File '$tpn_template' does not exist. Please specify a valid path to the THIRD-PARTY-NOTICES template"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-02-17 16:39:17 +00:00
|
|
|
# Sanitize the input
|
|
|
|
|
|
|
|
if [[ -z "$repository" ]]; then
|
2023-03-13 13:44:42 +00:00
|
|
|
fail "No repository to synchronize specified"
|
|
|
|
exit 1
|
2023-02-17 16:39:17 +00:00
|
|
|
fi
|
|
|
|
|
2022-12-07 19:06:24 +00:00
|
|
|
if [[ -z "$vmr_dir" ]]; then
|
|
|
|
vmr_dir="$tmp_dir/dotnet"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -d "$tmp_dir" ]]; then
|
|
|
|
mkdir -p "$tmp_dir"
|
|
|
|
fi
|
|
|
|
|
2023-01-09 13:28:34 +00:00
|
|
|
if [[ "$verbosity" == "debug" ]]; then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
2023-02-17 16:39:17 +00:00
|
|
|
# Prepare the VMR
|
|
|
|
|
2022-12-07 19:06:24 +00:00
|
|
|
if [[ ! -d "$vmr_dir" ]]; then
|
|
|
|
highlight "Cloning 'dotnet/dotnet' into $vmr_dir.."
|
|
|
|
git clone https://github.com/dotnet/dotnet "$vmr_dir"
|
2023-03-13 13:44:42 +00:00
|
|
|
|
|
|
|
if [[ -n "$vmr_branch" ]]; then
|
|
|
|
git -C "$vmr_dir" switch -c "$vmr_branch"
|
|
|
|
fi
|
2022-12-07 19:06:24 +00:00
|
|
|
else
|
|
|
|
if ! git -C "$vmr_dir" diff --quiet; then
|
|
|
|
fail "There are changes in the working tree of $vmr_dir. Please commit or stash your changes"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-03-13 13:44:42 +00:00
|
|
|
if [[ -n "$vmr_branch" ]]; then
|
|
|
|
highlight "Preparing $vmr_dir"
|
|
|
|
git -C "$vmr_dir" checkout "$vmr_branch"
|
|
|
|
git -C "$vmr_dir" pull
|
|
|
|
fi
|
2022-12-07 19:06:24 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Prepare darc
|
2023-02-17 16:39:17 +00:00
|
|
|
|
2022-12-07 19:06:24 +00:00
|
|
|
highlight 'Installing .NET, preparing the tooling..'
|
|
|
|
source "$scriptroot/common/tools.sh"
|
|
|
|
InitializeDotNetCli true
|
2023-03-13 13:44:42 +00:00
|
|
|
dotnet=$(realpath "$scriptroot/../.dotnet/dotnet")
|
2022-12-07 19:06:24 +00:00
|
|
|
"$dotnet" tool restore
|
|
|
|
|
2023-03-13 13:44:42 +00:00
|
|
|
highlight "Starting the synchronization of '$repository'.."
|
2023-02-17 16:39:17 +00:00
|
|
|
set +e
|
|
|
|
|
|
|
|
recursive_arg=''
|
|
|
|
if [[ "$recursive" == "true" ]]; then
|
|
|
|
recursive_arg="--recursive"
|
2023-01-09 13:28:34 +00:00
|
|
|
fi
|
|
|
|
|
2023-03-13 13:44:42 +00:00
|
|
|
if [[ -n "$additional_remotes" ]]; then
|
|
|
|
additional_remotes="--additional-remotes $additional_remotes"
|
|
|
|
fi
|
|
|
|
|
2023-02-17 16:39:17 +00:00
|
|
|
# Synchronize the VMR
|
|
|
|
|
|
|
|
"$dotnet" darc vmr update \
|
|
|
|
--vmr "$vmr_dir" \
|
|
|
|
--tmp "$tmp_dir" \
|
|
|
|
--$verbosity \
|
|
|
|
$recursive_arg \
|
|
|
|
--readme-template "$readme_template" \
|
|
|
|
--tpn-template "$tpn_template" \
|
2023-03-13 13:44:42 +00:00
|
|
|
$additional_remotes \
|
2023-02-17 16:39:17 +00:00
|
|
|
"$repository"
|
2022-12-07 19:06:24 +00:00
|
|
|
|
2023-02-17 16:39:17 +00:00
|
|
|
if [[ $? == 0 ]]; then
|
2022-12-07 19:06:24 +00:00
|
|
|
highlight "Synchronization succeeded"
|
|
|
|
else
|
2023-02-17 16:39:17 +00:00
|
|
|
fail "Synchronization of dotnet/dotnet to '$repository' failed!"
|
2023-01-09 13:28:34 +00:00
|
|
|
fail "'$vmr_dir' is left in its last state (re-run of this script will reset it)."
|
2022-12-07 19:06:24 +00:00
|
|
|
fail "Please inspect the logs which contain path to the failing patch file (use --debug to get all the details)."
|
|
|
|
fail "Once you make changes to the conflicting VMR patch, commit it locally and re-run this script."
|
|
|
|
exit 1
|
|
|
|
fi
|