Add a script for exporting VMR as a source archive (#15226)
Co-authored-by: Michael Simons <msimons@microsoft.com>
This commit is contained in:
parent
a768243c3c
commit
2e488c8320
3 changed files with 106 additions and 4 deletions
|
@ -139,6 +139,12 @@ ln -s $HOME/.dotnet/dotnet /usr/bin/dotnet
|
|||
|
||||
You can also utilize [GitHub Codespaces](https://github.com/features/codespaces) where you can find preset containers in this repository.
|
||||
|
||||
### Exporting a source archive
|
||||
|
||||
In case you'd like to export a more lightweight archive of sources that can be built outside of this git repository, a simple copy of the working tree won't do.
|
||||
The build is using some git metadata (information from the `.git` directory) that are needed to be kept with the sources.
|
||||
To export a `tar.gz` archive of the sources, you need to use the `eng/pack-sources.sh` script from within a clone of the VMR checked out at the revision that you're interested in.
|
||||
|
||||
## List of components
|
||||
|
||||
To enable full offline source-building of the VMR, we have no other choice than to synchronize all the necessary code into the VMR. This also includes any code referenced via git submodules. More details on why and how this is done can be found here:
|
||||
|
|
96
src/SourceBuild/content/eng/pack-sources.sh
Executable file
96
src/SourceBuild/content/eng/pack-sources.sh
Executable file
|
@ -0,0 +1,96 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
### This script exports the sources of VMR (dotnet/dotnet) as an archive that can be used
|
||||
### to build the .NET SDK.
|
||||
### It expects you clone the dotnet/dotnet repo locally and check out the desired revision.
|
||||
###
|
||||
### USAGE:
|
||||
### ./pack-sources.sh -o dotnet.tar.gz
|
||||
### Options:
|
||||
### -o, --output PATH
|
||||
### Optional. Path or dir where the archive is created.
|
||||
### Defaults to artifacts/packages/dotnet-[SHA].tar.gz
|
||||
|
||||
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-
|
||||
}
|
||||
|
||||
GIT_ROOT=$(realpath "$scriptroot/../")
|
||||
|
||||
output=''
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
opt="$(echo "$1" | tr "[:upper:]" "[:lower:]")"
|
||||
case "$opt" in
|
||||
-o|--output)
|
||||
output=$2
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
print_help
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
fail "Invalid argument: $1"
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
shift
|
||||
done
|
||||
|
||||
revision=$(git -C "$GIT_ROOT" rev-parse HEAD)
|
||||
filename="dotnet-$revision"
|
||||
|
||||
if [[ -z "$output" ]]; then
|
||||
output="$GIT_ROOT/artifacts/packages/$filename.tar.gz"
|
||||
fi
|
||||
|
||||
# If output is directory, use the default filename
|
||||
if [[ -d "$output" ]]; then
|
||||
output="$output/$filename.tar.gz"
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
||||
echo "Packing sources of $revision to $output.."
|
||||
mkdir -p "$(dirname "$output")"
|
||||
rm -f "$output"
|
||||
|
||||
tmp="$GIT_ROOT/artifacts/tmp"
|
||||
mkdir -p "$tmp"
|
||||
config_file="$tmp/config"
|
||||
HEAD_file="$tmp/HEAD"
|
||||
|
||||
start_time=$(date +%s)
|
||||
|
||||
# We need to had `.git/HEAD` and `.git/config` to the archive as the build expects those
|
||||
echo $'[remote "origin"]\nurl="http://github.com/dotnet/dotnet"' > "$config_file"
|
||||
echo "$revision" > "$HEAD_file"
|
||||
|
||||
git -C "$GIT_ROOT" archive \
|
||||
-o "$output" \
|
||||
--prefix "$filename/.git/" \
|
||||
--add-file "$config_file" \
|
||||
--add-file "$HEAD_file" \
|
||||
--prefix "$filename/" \
|
||||
"$revision" "$GIT_ROOT"
|
||||
|
||||
end_time=$(date +%s)
|
||||
elapsed=$(( end_time - start_time ))
|
||||
|
||||
duration=$(date -u +%H:%M:%S "-d@$elapsed")
|
||||
echo "Archive created in $duration"
|
|
@ -70,15 +70,15 @@
|
|||
<MSBuildExtensionsOutputDirectory>$(LayoutDirectory)MSBuildExtensions</MSBuildExtensionsOutputDirectory>-->
|
||||
</PropertyGroup>
|
||||
|
||||
<Error Condition=" '$(OfficialBuild)' == 'true' AND '$(_PatchNumber)' == '' "
|
||||
Text="_PatchNumber should not be empty in an official build. Check if there were changes in Arcade." />
|
||||
|
||||
<Exec Command="git rev-list --count HEAD"
|
||||
ConsoleToMSBuild="true"
|
||||
Condition=" '$(GitCommitCount)' == '' ">
|
||||
Condition=" '$(GitCommitCount)' == '' AND '$(_PatchNumber)' == '' ">
|
||||
<Output TaskParameter="ConsoleOutput" PropertyName="GitCommitCount" />
|
||||
</Exec>
|
||||
|
||||
<Error Condition=" '$(OfficialBuild)' == 'true' And '$(_PatchNumber)' == '' "
|
||||
Text="_PatchNumber should not be empty in an official build. Check if there were changes in Arcade." />
|
||||
|
||||
<PropertyGroup>
|
||||
<GitCommitCount>$(GitCommitCount.PadLeft(6,'0'))</GitCommitCount>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue