From ae1049f5203fd3b4c19cb63303463dbe06499aa4 Mon Sep 17 00:00:00 2001 From: mzz2017 Date: Fri, 17 Sep 2021 17:04:42 +0800 Subject: [PATCH] chore: refine build scripts --- build-in-pwsh.ps1 | 32 ++++++++++++++++++-------------- build.sh | 11 ++++++----- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/build-in-pwsh.ps1 b/build-in-pwsh.ps1 index 0ed576fe..99dd8e70 100644 --- a/build-in-pwsh.ps1 +++ b/build-in-pwsh.ps1 @@ -1,23 +1,17 @@ -## Check OS -$TestWinDir = Test-Path $env:windir -ErrorAction Ignore - -if ([String]::IsNullOrEmpty($TestWinDir)) { - $v2rayaBin = "v2raya" -} -else { - $v2rayaBin = "v2raya.exe" -} +Set-PSDebug -Trace 1 ## Get current folder -$SHELL_FOLDER = Get-Item -LiteralPath .\ | ForEach-Object -Process { $_.FullName } +$CWD = Get-Location +$shell_path = Resolve-Path -Path $PSCommandPath +$SHELL_FOLDER = Split-Path $shell_path ## Get date -$DateLong = git log -1 --format="%cd" --date=short +$DateLong = git -C "$SHELL_FOLDER" log -1 --format="%cd" --date=short $Date = $DateLong -replace "-"; "" ## Other info -$count = git rev-list --count HEAD -$commit = git rev-parse --short HEAD +$count = git -C "$SHELL_FOLDER" rev-list --count HEAD +$commit = git -C "$SHELL_FOLDER" rev-parse --short HEAD ## Version $version = "unstable-$date.r$count.$commit" @@ -39,6 +33,15 @@ else { Write-Output "You don't install golang, please install it and add it to your path." } else { + ## Check OS + $TestWinDir = Test-Path $env:windir -ErrorAction Ignore + + if ([String]::IsNullOrEmpty($TestWinDir)) { + $v2rayaBin = "v2raya" + } + else { + $v2rayaBin = "v2raya.exe" + } ${env:CGO_ENABLED} = "0" ${env:OUTPUT_DIR} = "$SHELL_FOLDER/service/server/router/web" $guiPath = $SHELL_FOLDER + "/gui" @@ -47,7 +50,8 @@ else { yarn build $corePath = $SHELL_FOLDER + "/service" Set-Location -path "$corePath" - go build -ldflags "-X github.com/v2rayA/v2rayA/conf.Version=$version -s -w" -o "$SHELL_FOLDER/$v2rayaBin" + go build -ldflags "-X github.com/v2rayA/v2rayA/conf.Version=$version -s -w" -o "$CWD/$v2rayaBin" } } } +Set-Location -path "$CWD" diff --git a/build.sh b/build.sh index 8f88d011..74003bc5 100755 --- a/build.sh +++ b/build.sh @@ -1,13 +1,14 @@ #!/bin/bash set -ex -SHELL_FOLDER="$(pwd)"/"$(dirname $0)" +CWD="$(pwd)" +SHELL_FOLDER="$(dirname $(realpath $0))" if [ -d "$SHELL_FOLDER/.git" ]; then - date=$(git log -1 --format="%cd" --date=short | sed s/-//g) - count=$(git rev-list --count HEAD) - commit=$(git rev-parse --short HEAD) + date=$(git -C "$SHELL_FOLDER" log -1 --format="%cd" --date=short | sed s/-//g) + count=$(git -C "$SHELL_FOLDER" rev-list --count HEAD) + commit=$(git -C "$SHELL_FOLDER" rev-parse --short HEAD) version="unstable-$date.r${count}.$commit" else version="unstable" fi cd "$SHELL_FOLDER"/gui && yarn && OUTPUT_DIR="$SHELL_FOLDER"/service/server/router/web yarn build -cd "$SHELL_FOLDER"/service && CGO_ENABLED=0 go build -ldflags "-X github.com/v2rayA/v2rayA/conf.Version=$version -s -w" -o "$SHELL_FOLDER"/v2raya +cd "$SHELL_FOLDER"/service && CGO_ENABLED=0 go build -ldflags "-X github.com/v2rayA/v2rayA/conf.Version=$version -s -w" -o "$CWD"/v2raya