build.ps1 2.8 KB

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