build.ps1 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. $ORG_PATH="go.etcd.io"
  2. $REPO_PATH="$ORG_PATH/etcd"
  3. $PWD = $((Get-Item -Path ".\" -Verbose).FullName)
  4. $FSROOT = $((Get-Location).Drive.Name+":")
  5. $FSYS = $((Get-WMIObject win32_logicaldisk -filter "DeviceID = '$FSROOT'").filesystem)
  6. if ($FSYS.StartsWith("FAT","CurrentCultureIgnoreCase")) {
  7. echo "Error: Cannot build etcd using the $FSYS filesystem (use NTFS instead)"
  8. exit 1
  9. }
  10. # Set $Env:GO_LDFLAGS="-s" for building without symbols.
  11. $GO_LDFLAGS="$Env:GO_LDFLAGS -X $REPO_PATH/version.GitSHA=$GIT_SHA"
  12. # rebuild symlinks
  13. git ls-files -s cmd | select-string -pattern 120000 | ForEach {
  14. $l = $_.ToString()
  15. $lnkname = $l.Split(' ')[1]
  16. $target = "$(git log -p HEAD -- $lnkname | select -last 2 | select -first 1)"
  17. $target = $target.SubString(1,$target.Length-1).Replace("/","\")
  18. $lnkname = $lnkname.Replace("/","\")
  19. $terms = $lnkname.Split("\")
  20. $dirname = $terms[0..($terms.length-2)] -join "\"
  21. $lnkname = "$PWD\$lnkname"
  22. $targetAbs = "$((Get-Item -Path "$dirname\$target").FullName)"
  23. $targetAbs = $targetAbs.Replace("/", "\")
  24. if (test-path -pathtype container "$targetAbs") {
  25. if (Test-Path "$lnkname") {
  26. if ((Get-Item "$lnkname") -is [System.IO.DirectoryInfo]) {
  27. # rd so deleting junction doesn't take files with it
  28. cmd /c rd "$lnkname"
  29. }
  30. }
  31. if (Test-Path "$lnkname") {
  32. if (!((Get-Item "$lnkname") -is [System.IO.DirectoryInfo])) {
  33. cmd /c del /A /F "$lnkname"
  34. }
  35. }
  36. cmd /c mklink /J "$lnkname" "$targetAbs" ">NUL"
  37. } else {
  38. # Remove file with symlink data (first run)
  39. if (Test-Path "$lnkname") {
  40. cmd /c del /A /F "$lnkname"
  41. }
  42. cmd /c mklink /H "$lnkname" "$targetAbs" ">NUL"
  43. }
  44. }
  45. if (-not $env:GOPATH) {
  46. $orgpath="$PWD\gopath\src\" + $ORG_PATH.Replace("/", "\")
  47. if (Test-Path "$orgpath\etcd") {
  48. if ((Get-Item "$orgpath\etcd") -is [System.IO.DirectoryInfo]) {
  49. # rd so deleting junction doesn't take files with it
  50. cmd /c rd "$orgpath\etcd"
  51. }
  52. }
  53. if (Test-Path "$orgpath") {
  54. if ((Get-Item "$orgpath") -is [System.IO.DirectoryInfo]) {
  55. # rd so deleting junction doesn't take files with it
  56. cmd /c rd "$orgpath"
  57. }
  58. }
  59. if (Test-Path "$orgpath") {
  60. if (!((Get-Item "$orgpath") -is [System.IO.DirectoryInfo])) {
  61. # Remove file with symlink data (first run)
  62. cmd /c del /A /F "$orgpath"
  63. }
  64. }
  65. cmd /c mkdir "$orgpath"
  66. cmd /c mklink /J "$orgpath\etcd" "$PWD" ">NUL"
  67. $env:GOPATH = "$PWD\gopath"
  68. }
  69. # Static compilation is useful when etcd is run in a container
  70. $env:CGO_ENABLED = 0
  71. $env:GO15VENDOREXPERIMENT = 1
  72. $GIT_SHA="$(git rev-parse --short HEAD)"
  73. go build -a -installsuffix cgo -ldflags $GO_LDFLAGS -o bin\etcd.exe "$REPO_PATH"
  74. go build -a -installsuffix cgo -ldflags $GO_LDFLAGS -o bin\etcdctl.exe "$REPO_PATH\etcdctl"