Skip to content

Commit

Permalink
unify version package and move it to top level
Browse files Browse the repository at this point in the history
  • Loading branch information
frapposelli committed Feb 12, 2019
1 parent 04deec0 commit 099cd92
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 18 deletions.
15 changes: 13 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ builds:
- CGO_ENABLED=0
main: ./govc/
flags: -compiler gc -tags 'netgo'
ldflags: -X github.com/vmware/govmomi/govc/flags.GitVersion={{.Version}} -s -w
ldflags: -X github.com/vmware/govmomi/version.GitVersion={{.Version}} -s -w
goos:
- linux
- darwin
Expand All @@ -22,7 +22,7 @@ builds:
- CGO_ENABLED=0
main: ./vcsim/
flags: -compiler gc -tags 'netgo'
ldflags: github.com/vmware/govmomi/vcsim=-X main.GitVersion={{.Version}} -s -w
ldflags: -X github.com/vmware/govmomi/version.GitVersion={{.Version}} -s -w
goos:
- linux
- darwin
Expand All @@ -33,6 +33,17 @@ builds:
- 386
- arm
- arm64
- binary: toolbox
env:
- CGO_ENABLED=0
main: ./toolbox/toolbox/
flags: -compiler gc -tags 'netgo'
ldflags: -X github.com/vmware/govmomi/version.GitVersion={{.Version}} -s -w
goos:
- linux
goarch:
- amd64
- 386
archive:
name_template: '{{ .Binary }}_{{ .Os }}_{{ .Arch }}'
format: gz
Expand Down
4 changes: 3 additions & 1 deletion govc/flags/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import (
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/soap"
"github.com/vmware/govmomi/vim25/types"

gv "github.com/vmware/govmomi/version"
)

const (
Expand Down Expand Up @@ -287,7 +289,7 @@ func (flag *ClientFlag) configure(sc *soap.Client) (soap.RoundTripper, error) {
sc.Namespace = "urn:" + flag.vimNamespace
sc.Version = flag.vimVersion

sc.UserAgent = fmt.Sprintf("govc/%s", Version)
sc.UserAgent = fmt.Sprintf("govc/%s", gv.Version)

if err := flag.SetRootCAs(sc); err != nil {
return nil, err
Expand Down
4 changes: 0 additions & 4 deletions govc/flags/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import (
"strings"
)

const Version = "0.20.0"

var GitVersion string

type version []int

func ParseVersion(s string) (version, error) {
Expand Down
6 changes: 4 additions & 2 deletions govc/version/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (

"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"

gv "github.com/vmware/govmomi/version"
)

type version struct {
Expand All @@ -40,9 +42,9 @@ func (cmd *version) Register(ctx context.Context, f *flag.FlagSet) {
}

func (cmd *version) Run(ctx context.Context, f *flag.FlagSet) error {
ver := flags.GitVersion
ver := gv.GitVersion
if ver == "" {
ver = flags.Version
ver = gv.Version
}

if cmd.require != "" {
Expand Down
11 changes: 10 additions & 1 deletion scripts/contributors.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#!/bin/bash -e

# standardize on gnu sort where available
ssort() {
if hash gsort 2>/dev/null; then
gsort "$@"
else
sort "$@"
fi
}

file="$(git rev-parse --show-toplevel)/CONTRIBUTORS"

cat <<EOF > "$file"
Expand All @@ -10,4 +19,4 @@ cat <<EOF > "$file"
EOF

git log --format='%aN <%aE>' | sort -uf >> "$file"
git log --format='%aN <%aE>' | ssort -uf >> "$file"
13 changes: 13 additions & 0 deletions toolbox/toolbox/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,31 @@ package main

import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall"

"github.com/vmware/govmomi/toolbox"
gv "github.com/vmware/govmomi/version"
)

// This example can be run on a VM hosted by ESX, Fusion or Workstation
func main() {
ver := flag.Bool("version", false, "Show vcsim version number")
flag.Parse()

// if -version is requested, print it and exit cleanly
if *ver {
v := gv.GitVersion
if v == "" {
v = gv.Version
}
fmt.Printf("toolbox %s\n", v)
os.Exit(0)
}

in := toolbox.NewBackdoorChannelIn()
out := toolbox.NewBackdoorChannelOut()

Expand Down
11 changes: 3 additions & 8 deletions vcsim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,10 @@ import (
"github.com/vmware/govmomi/simulator/vpx"
sts "github.com/vmware/govmomi/sts/simulator"
vapi "github.com/vmware/govmomi/vapi/simulator"
gv "github.com/vmware/govmomi/version"
"github.com/vmware/govmomi/vim25/types"
)

// vcsim does not track versions like govc does, it only shows if a binary was
// built during a tag event or from a git checkout.
const Version = "dev"

var GitVersion string

func main() {
model := simulator.VPX()

Expand Down Expand Up @@ -83,9 +78,9 @@ func main() {

// if -version is requested, print it and exit cleanly
if *ver {
v := GitVersion
v := gv.GitVersion
if v == "" {
v = Version
v = gv.Version
}
fmt.Printf("vcsim %s\n", v)
os.Exit(0)
Expand Down
25 changes: 25 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright (c) 2014-2017 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package version

// Version is the current development version, it is used if GitVersion is not
// populated.
const Version = "0.20.0"

// GitVersion is populated via ldflags at compile time, with the version coming
// from `git tag`.
var GitVersion string

0 comments on commit 099cd92

Please sign in to comment.