build.ps1 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. $ORG_PATH="github.com/coreos"
  2. $REPO_PATH="$ORG_PATH/etcd"
  3. $PWD = $((Get-Item -Path ".\" -Verbose).FullName)
  4. # rebuild symlinks
  5. echo "Rebuilding symlinks"
  6. git ls-files -s cmd | select-string -pattern 120000 | ForEach {
  7. $l = $_.ToString()
  8. $lnkname = $l.Split(' ')[1]
  9. $target = "$(git log -p HEAD -- $lnkname | select -last 2 | select -first 1)"
  10. $target = $target.SubString(1,$target.Length-1).Replace("/","\")
  11. $lnkname = $lnkname.Replace("/","\")
  12. $terms = $lnkname.Split("\")
  13. $dirname = $terms[0..($terms.length-2)] -join "\"
  14. $lnkname = "$PWD\$lnkname"
  15. $targetAbs = "$((Get-Item -Path "$dirname\$target").FullName)"
  16. $targetAbs = $targetAbs.Replace("/", "\")
  17. if (test-path -pathtype container "$targetAbs") {
  18. # rd so deleting junction doesn't take files with it
  19. cmd /c rd "$lnkname"
  20. cmd /c del /A /F "$lnkname"
  21. cmd /c mklink /J "$lnkname" "$targetAbs"
  22. } else {
  23. cmd /c del /A /F "$lnkname"
  24. cmd /c mklink /H "$lnkname" "$targetAbs"
  25. }
  26. }
  27. if (-not $env:GOPATH) {
  28. $orgpath="$PWD\gopath\src\" + $ORG_PATH.Replace("/", "\")
  29. cmd /c rd "$orgpath\etcd"
  30. cmd /c del "$orgpath"
  31. cmd /c mkdir "$orgpath"
  32. cmd /c mklink /J "$orgpath\etcd" "$PWD"
  33. $env:GOPATH = "$PWD\gopath"
  34. }
  35. # Static compilation is useful when etcd is run in a container
  36. $env:CGO_ENABLED = 0
  37. $env:GO15VENDOREXPERIMENT = 1
  38. $GIT_SHA="$(git rev-parse --short HEAD)"
  39. go build -a -installsuffix cgo -ldflags "-s -X $REPO_PATH/cmd/vendor/$REPO_PATH/version.GitSHA=$GIT_SHA" -o bin\etcd.exe "$REPO_PATH\cmd"
  40. go build -a -installsuffix cgo -ldflags "-s" -o bin\etcdctl.exe "$REPO_PATH\cmd\etcdctl"