Skip to content

Commit

Permalink
Fix path problem while cloning/pulling
Browse files Browse the repository at this point in the history
  • Loading branch information
aeris170 committed Nov 17, 2024
1 parent 323b3f2 commit b118242
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 85 deletions.
77 changes: 37 additions & 40 deletions scripts/vcpkg.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,43 @@ if (-not $args[1]) {
Write-Host "Clonemode: $clonemode" -ForegroundColor white -BackgroundColor black
Write-Host "vcpkg path: $path" -ForegroundColor white -BackgroundColor black

# Create the directory if it doesn't exist
if (-not (Test-Path -Path $path)) {
Write-Host "Creating directory: $path" -ForegroundColor white -BackgroundColor black
New-Item -Path $path -ItemType Directory | Out-Null
} else {
# Check if the directory exists
if (Test-Path -Path $path) {
# If the directory exists, go inside and pull the latest changes
Write-Host "Directory already exists: $path" -ForegroundColor yellow -BackgroundColor black
}
Write-Host "Changing to directory: $path" -ForegroundColor white -BackgroundColor black
Set-Location -Path $path

# Change directory to the vcpkg path
Write-Host "Changing to directory: $path" -ForegroundColor white -BackgroundColor black
Set-Location -Path $path

# Clone vcpkg using the provided clonemode
Write-Host "Cloning vcpkg..." -ForegroundColor white -BackgroundColor black
if ($clonemode -eq "ssh") {
Start-Process -FilePath "git" -ArgumentList "clone git@github.com:microsoft/vcpkg.git ." `
-NoNewWindow -Wait -PassThru | Tee-Object -Variable cloneOutput
} elseif ($clonemode -eq "https") {
Start-Process -FilePath "git" -ArgumentList "clone https://github.com/Microsoft/vcpkg.git ." `
-NoNewWindow -Wait -PassThru | Tee-Object -Variable cloneOutput
Write-Host "Pulling latest vcpkg changes..." -ForegroundColor white -BackgroundColor black
$pullOutput = Start-Process -FilePath "git" -ArgumentList "pull" -NoNewWindow -Wait -PassThru
if ($pullOutput.ExitCode -ne 0) {
Write-Host "Error during git pull: $($pullOutput.StandardError)" -ForegroundColor red -BackgroundColor black
Set-Location -Path ..
exit 1
}
} else {
Write-Host "Incorrect clonemode! Expected https or ssh, got something else" -ForegroundColor red -BackgroundColor black
Set-Location -Path ..
exit 1
}

# Check if clone was successful
if ($cloneOutput.ExitCode -ne 0) {
Write-Host "Error during git clone: $($cloneOutput.StandardError)" -ForegroundColor red -BackgroundColor black
Set-Location -Path ..
exit 1
}
# If the directory doesn't exist, go to the parent directory and clone the repo
Write-Host "Directory does not exist: $path" -ForegroundColor white -BackgroundColor black
Write-Host "Changing to parent directory and cloning vcpkg..." -ForegroundColor white -BackgroundColor black
Set-Location -Path (Split-Path -Path $path -Parent)

if ($clonemode -eq "ssh") {
Start-Process -FilePath "git" -ArgumentList "clone git@github.com:microsoft/vcpkg.git $(Split-Path -Leaf $path)" -NoNewWindow -Wait -PassThru | Tee-Object -Variable cloneOutput
} elseif ($clonemode -eq "https") {
Start-Process -FilePath "git" -ArgumentList "clone https://github.com/Microsoft/vcpkg.git $(Split-Path -Leaf $path)" -NoNewWindow -Wait -PassThru | Tee-Object -Variable cloneOutput
} else {
Write-Host "Incorrect clonemode! Expected https or ssh, got something else" -ForegroundColor red -BackgroundColor black
Set-Location -Path ..
exit 1
}

# Pull the latest changes
Write-Host "Pulling latest vcpkg changes..." -ForegroundColor white -BackgroundColor black
$pullOutput = Start-Process -FilePath "git" -ArgumentList "pull" -NoNewWindow -Wait -PassThru
if ($pullOutput.ExitCode -ne 0) {
Write-Host "Error during git pull: $($pullOutput.StandardError)" -ForegroundColor red -BackgroundColor black
Set-Location -Path ..
exit 1
# Check if clone was successful
if ($cloneOutput.ExitCode -ne 0) {
Write-Host "Error during git clone: $($cloneOutput.StandardError)" -ForegroundColor red -BackgroundColor black
Set-Location -Path ..
exit 1
}
Set-Location -Path $path
}

# Run the bootstrap script
Expand All @@ -70,12 +67,12 @@ if (Test-Path -Path "./bootstrap-vcpkg.bat") {
$bootstrapOutput = Start-Process -FilePath "./bootstrap-vcpkg.bat" -NoNewWindow -Wait -PassThru
if ($bootstrapOutput.ExitCode -ne 0) {
Write-Host "Error during bootstrap: $($bootstrapOutput.StandardError)" -ForegroundColor red -BackgroundColor black
Set-Location -Path ..
Set-Location -Path ..
exit 1
}
} else {
Write-Host "Bootstrap script not found!" -ForegroundColor red -BackgroundColor black
Set-Location -Path ..
Set-Location -Path ..
exit 1
}

Expand All @@ -102,7 +99,7 @@ $installOutput = Start-Process -FilePath "./vcpkg.exe" -ArgumentList @(
) -NoNewWindow -Wait -PassThru
if ($installOutput.ExitCode -ne 0) {
Write-Host "Error during vcpkg install: $($installOutput.StandardError)" -ForegroundColor red -BackgroundColor black
Set-Location -Path ..
Set-Location -Path ..
exit 1
}

Expand All @@ -111,7 +108,7 @@ Write-Host "Integrating vcpkg..." -ForegroundColor white -BackgroundColor black
$integrateOutput = Start-Process -FilePath "./vcpkg.exe" -ArgumentList 'integrate', 'install' -NoNewWindow -Wait -PassThru
if ($integrateOutput.ExitCode -ne 0) {
Write-Host "Error during vcpkg integrate: $($integrateOutput.StandardError)" -ForegroundColor red -BackgroundColor black
Set-Location -Path ..
Set-Location -Path ..
exit 1
}

Expand Down
88 changes: 43 additions & 45 deletions scripts/vcpkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,65 @@ RESET="\033[0m"
# Check if clonemode argument is provided
if [ -z "$1" ]; then
echo -e "${YELLOW}No clonemode supplied, defaulting to https${RESET}"
clonemode="https"
clonemode="https"
else
clonemode=$1
clonemode=$1
fi

# Check if vcpkg path argument is provided
if [ -z "$2" ]; then
echo -e "${YELLOW}No vcpkg path supplied, defaulting to ./vcpkg${RESET}"
path="./vcpkg"
path="./vcpkg"
else
path=$2
path=$2
fi

echo -e "${WHITE}Clonemode: $clonemode${RESET}"
echo -e "${WHITE}vcpkg path: $path${RESET}"

# Check if the directory exists, if not, create it
if [ ! -d "$path" ]; then
echo -e "${WHITE}Creating directory: $path${RESET}"
mkdir -p "$path"
else
echo -e "${YELLOW}Directory already exists: $path${RESET}"
fi

# Change directory to the vcpkg path
echo -e "${WHITE}Changing to directory: $path${RESET}"
cd "$path"

# Clone vcpkg using the provided clonemode
echo -e "${WHITE}Cloning vcpkg...${RESET}"
if [ "$clonemode" = "ssh" ]; then
git clone git@github.com:microsoft/vcpkg.git . 2>&1 | tee cloneOutput.log
elif [ "$clonemode" = "https" ]; then
git clone https://github.com/Microsoft/vcpkg.git . 2>&1 | tee cloneOutput.log
# Check if the directory exists
if [ -d "$path" ]; then
# If the directory exists, go inside and pull the latest changes
echo -e "${WHITE}Directory already exists: $path${RESET}"
echo -e "${WHITE}Changing to directory: $path${RESET}"
cd "$path"
echo -e "${WHITE}Pulling latest vcpkg changes...${RESET}"
git pull 2>&1 | tee pullOutput.log
if [ $? -ne 0 ]; then
echo -e "${RED}Error during git pull.${RESET}"
cat pullOutput.log
rm pullOutput.log
cd ..
exit 1
fi
rm pullOutput.log
else
echo -e "${RED}Incorrect clonemode! Expected https or ssh, got something else${RESET}"
cd ..
exit 1
fi
# If the directory doesn't exist, go to the parent directory and clone the repo
echo -e "${WHITE}Directory does not exist: $path${RESET}"
echo -e "${WHITE}Changing to parent directory and cloning vcpkg...${RESET}"
cd "$(dirname "$path")"
if [ "$clonemode" = "ssh" ]; then
git clone git@github.com:microsoft/vcpkg.git "$(basename "$path")" 2>&1 | tee cloneOutput.log
elif [ "$clonemode" = "https" ]; then
git clone https://github.com/Microsoft/vcpkg.git "$(basename "$path")" 2>&1 | tee cloneOutput.log
else
echo -e "${RED}Incorrect clonemode! Expected https or ssh, got something else${RESET}"
cd ..
exit 1
fi

# Check if clone was successful
if [ $? -ne 0 ]; then
echo -e "${RED}Error during git clone.${RESET}"
cat cloneOutput.log
# Check if clone was successful
if [ $? -ne 0 ]; then
echo -e "${RED}Error during git clone.${RESET}"
cat cloneOutput.log
rm cloneOutput.log
cd ..
exit 1
fi
rm cloneOutput.log
cd ..
exit 1
fi
rm cloneOutput.log

# Pull the latest changes
echo -e "${WHITE}Pulling latest vcpkg changes...${RESET}"
git pull 2>&1 | tee pullOutput.log
if [ $? -ne 0 ]; then
echo -e "${RED}Error during git pull.${RESET}"
cat pullOutput.log
rm pullOutput.log
cd ..
exit 1
# Change to the newly cloned vcpkg directory
cd "$path"
fi
rm pullOutput.log

# Run the bootstrap script
if [ -f "./bootstrap-vcpkg.sh" ]; then
Expand Down

0 comments on commit b118242

Please sign in to comment.