Skip to content

Commit

Permalink
TOOLS-378: create GOPATH setup scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
deafgoat committed Jan 6, 2015
1 parent b247d2f commit ac04c9b
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 198 deletions.
2 changes: 1 addition & 1 deletion Godeps
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ github.com/jacobsa/oglematchers 4fc24f97b5b74022c2a3f4ca7eed57ca29083d3e
github.com/smartystreets/goconvey 75bc4a2dad71e5c5b51c5009b33eba766ec57051
github.com/jessevdk/go-flags 1679536dcc895411a9f5848d9a0250be7856448c
github.com/3rf/mongo-lint 3550fdcf1f43b89aaeabaa4559eaae6dc4407e42
github.com/spacemonkeygo/openssl 500a817338511aad07db09254b7ccf6916ac6a19 github.com/gabrielrussell/openssl
github.com/spacemonkeygo/openssl 500a817338511aad07db09254b7ccf6916ac6a19 github.com/gabrielrussell/openssl
10 changes: 0 additions & 10 deletions Makefile

This file was deleted.

31 changes: 8 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,22 @@ Report any bugs, improvements, or new feature requests at https://jira.mongodb.o


####Setup

Clone the repo and set your GOPATH to include the vendored dependencies by using the helper script `set_gopath.sh`
Clone the repo and run `. ./set_gopath.sh` (`set_gopath.bat` on Windows) to setup your GOPATH:

```
git clone https://github.com/mongodb/mongo-tools
cd mongo-tools
. set_gopath.sh
. ./set_gopath.sh
```

#### Building Tools
To build the tools, you need to have Go version 1.3 and up.

To build the tools, you need to have Go version 1.3 and up. Running the `build.sh` script will install all the tools to `./bin`.

Alternatively, you can set GOBIN and use `go install`:
An additional flag, `-tags`, can be passed to the `go build` command in order to build the tools with support for SSL and/or SASL. For example:

```
export GOBIN=bin
go install mongodump/main/mongodump.go
```

An additional flag, `-tags`, can be passed to the `go install` command in order to install the tools with support for SSL and/or SASL. For example:

```
go install -tags ssl mongoimport/main/mongoimport.go # install mongoimport with SSL support enabled
go install -tags sasl mongoimport/main/mongoimport.go # install mongoimport with SASL support enabled
go install -tags "ssl sasl" mongoimport/main/mongoimport.go # install mongoimport with both SASL and SSL
```

Alternatively, you can run `build.sh` with the appropriate arguments. For example:

mkdir bin
go build -o bin/mongoimport mongoimport/main/mongoimport.go # build mongoimport
go build -o bin/mongoimport -tags ssl mongoimport/main/mongoimport.go # build mongoimport with SSL support enabled
go build -o bin/mongoimport -tags "ssl sasl" mongoimport/main/mongoimport.go # build mongoimport with SSL and SASL support enabled
```
build.sh ssl # install all the tools with SSL support enabled
build.sh sasl ssl # install all the tools with both SASL and SSL support enabled
```
5 changes: 2 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ rm -rf vendor/pkg

. ./set_gopath.sh
mkdir -p bin
export GOBIN=bin

for i in bsondump mongostat mongofiles mongoexport mongoimport mongorestore mongodump mongotop mongooplog; do
echo "Building ${i}..."
# Build the tool, using -ldflags to link in the current gitspec
go install -ldflags "-X github.com/mongodb/mongo-tools/common/options.Gitspec `git rev-parse HEAD`" -tags "$tags" "$i/main/$i.go"
# Build the tool, using -ldflags to link in the current gitspec
go build -o "bin/$i" -ldflags "-X github.com/mongodb/mongo-tools/common/options.Gitspec `git rev-parse HEAD`" -tags "$tags" "$i/main/$i.go"
done
5 changes: 2 additions & 3 deletions common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ functions:
params:
working_dir: src
script: |
chmod 700 go.sh
chmod 700 set_gopath.sh
"run tool unit tests":
Expand Down Expand Up @@ -919,7 +918,7 @@ tasks:
script: |
set -o errexit
set -o verbose
retVal=$(./go.sh run vendor/src/github.com/3rf/mongo-lint/golint/golint.go src);
retVal=$(. ./set_gopath.sh && go run vendor/src/github.com/3rf/mongo-lint/golint/golint.go mongo* bson* common/*);
if [ "$retVal" = "" ]; then exit 0; else echo $retVal; exit 1; fi;
- name: log
Expand Down Expand Up @@ -1185,7 +1184,7 @@ tasks:
working_dir: src
script: |
set -o verbose
retVal=$(./go.sh tool vet .); if [ "$retVal" = "" ]; then exit 0; else exit 1; fi;
retVal=$(. ./set_gopath.sh && go tool vet .); if [ "$retVal" = "" ]; then exit 0; else exit 1; fi;
buildvariants:
#######################################
Expand Down
3 changes: 1 addition & 2 deletions common/db/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ func (sp *SessionProvider) SupportsRepairCursor(db, collection string) (bool, er
}
if strings.Index(err.Error(), "no such cmd: repairCursor") > -1 {
// return a helpful error message for early server versions
return false, fmt.Errorf(
"--repair flag cannot be used on mongodb versions before 2.7.8.")
return false, fmt.Errorf("--repair flag cannot be used on mongodb versions before 2.7.8")
}
if strings.Index(err.Error(), "repair iterator not supported") > -1 {
// helpful error message if the storage engine does not support repair (WiredTiger)
Expand Down
35 changes: 0 additions & 35 deletions go.sh

This file was deleted.

77 changes: 0 additions & 77 deletions legacy-notes.md

This file was deleted.

59 changes: 29 additions & 30 deletions mongoimport/mongoimport.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ func (mongoImport *MongoImport) runInsertionWorker(readDocChan chan bson.D) (err
}
collection := session.DB(mongoImport.ToolOptions.DB).C(mongoImport.ToolOptions.Collection)
ignoreBlanks := mongoImport.IngestOptions.IgnoreBlanks && mongoImport.InputOptions.Type != JSON
documentBytes := make([]byte, 0)
documents := make([]bson.Raw, 0)
var documentBytes []byte
var documents []bson.Raw
numMessageBytes := 0

readLoop:
Expand Down Expand Up @@ -481,7 +481,7 @@ func (mongoImport *MongoImport) handleUpsert(documents []bson.Raw, collection *m
_, err = collection.Upsert(selector, document)
}
if err == nil {
numInserted += 1
numInserted++
}
if err = filterIngestError(stopOnError, err); err != nil {
return numInserted, err
Expand All @@ -507,34 +507,33 @@ func (mongoImport *MongoImport) insert(documents []bson.Raw, collection *mgo.Col
if mongoImport.IngestOptions.Upsert {
numInserted, err = mongoImport.handleUpsert(documents, collection)
return err
} else {
if len(documents) == 0 {
return
}
bulk := collection.Bulk()
for _, document := range documents {
bulk.Insert(document)
}
if !maintainInsertionOrder {
bulk.Unordered()
}
}
if len(documents) == 0 {
return
}
bulk := collection.Bulk()
for _, document := range documents {
bulk.Insert(document)
}
if !maintainInsertionOrder {
bulk.Unordered()
}

// mgo.Bulk doesn't currently implement write commands so mgo.BulkResult
// isn't informative
_, err = bulk.Run()

// TOOLS-349: Note that this count may not be entirely accurate if some
// ingester workers insert when another errors out.
//
// Without write commands, we can't say for sure how many documents
// were inserted when we use bulk inserts so we assume the entire batch
// insert failed if an error is returned. The result is that we may
// report that less documents - than were actually inserted - were
// inserted into the database. This will change as soon as BulkResults
// are supported by the driver
if err == nil {
numInserted = len(documents)
}
// mgo.Bulk doesn't currently implement write commands so mgo.BulkResult
// isn't informative
_, err = bulk.Run()

// TOOLS-349: Note that this count may not be entirely accurate if some
// ingester workers insert when another errors out.
//
// Without write commands, we can't say for sure how many documents
// were inserted when we use bulk inserts so we assume the entire batch
// insert failed if an error is returned. The result is that we may
// report that less documents - than were actually inserted - were
// inserted into the database. This will change as soon as BulkResults
// are supported by the driver
if err == nil {
numInserted = len(documents)
}
return filterIngestError(stopOnError, err)
}
Expand Down
6 changes: 2 additions & 4 deletions mongorestore/filepath.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ func (restore *MongoRestore) CreateAllIntents(fullpath string) error {
}
}
if restore.InputOptions.OplogReplay && !foundOplog {
return fmt.Errorf(
"no %v/oplog.bson file to replay; make sure you run mongodump with --oplog.",
fullpath)
return fmt.Errorf("no %v/oplog.bson file to replay; make sure you run mongodump with --oplog", fullpath)
}
return nil
}
Expand All @@ -104,7 +102,7 @@ func (restore *MongoRestore) CreateIntentsForDB(db, fullpath string) error {
collection, fileType := GetInfoFromFilename(entry.Name())
switch fileType {
case BSONFileType:
// Dumps of a single database (i.e. with the -d flag) may contain special
// Dumps of a single database (i.e. with the -d flag) may contain special
// db-specific collections that start with a "$" (for example, $admin.system.users
// holds the users for a database that was dumped with --dumpDbUsersAndRoles enabled).
// If these special files manage to be included in a dump directory during a full
Expand Down
1 change: 0 additions & 1 deletion mongostat/options.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Package options implements mongostat-specific command-line options.
package mongostat

import ()
Expand Down
1 change: 0 additions & 1 deletion mongotop/options.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Package options implements mongotop-specific command-line options.
package mongotop

import ()
Expand Down
6 changes: 6 additions & 0 deletions set_gopath.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@echo off
set TOOLSPKG=%cd%\.gopath\src\github.com\mongodb\mongo-tools
for %%t in (bsondump, common, mongostat, mongofiles, mongoexport, mongoimport, mongorestore, mongodump, mongotop, mongooplog) do echo d | xcopy %cd%\%%t %TOOLSPKG%\%%t /yes
REM copy vendored libraries to GOPATH
for /f %%v in ('dir /b /a:d "%cd%\vendor\src\*"') do echo d | xcopy %cd%\vendor\src\%%v %cd%\.gopath\src\%%v /yes
set GOPATH=%cd%\.gopath;%cd%\vendor
16 changes: 8 additions & 8 deletions set_gopath.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ TOOLS_PKG='github.com/mongodb/mongo-tools'

setgopath() {
if [ "Windows_NT" != "$OS" ]; then
SOURCE_GOPATH=`pwd`.gopath
VENDOR_GOPATH=`pwd`/vendor
SOURCE_GOPATH=`pwd`.gopath
VENDOR_GOPATH=`pwd`/vendor

# set up the $GOPATH to use the vendored dependencies as
# well as the source for the mongo tools
rm -rf .gopath/
mkdir -p .gopath/src/"$(dirname "${TOOLS_PKG}")"
ln -sf `pwd` .gopath/src/$TOOLS_PKG
export GOPATH=`pwd`/.gopath:`pwd`/vendor
# set up the $GOPATH to use the vendored dependencies as
# well as the source for the mongo tools
rm -rf .gopath/
mkdir -p .gopath/src/"$(dirname "${TOOLS_PKG}")"
ln -sf `pwd` .gopath/src/$TOOLS_PKG
export GOPATH=`pwd`/.gopath:`pwd`/vendor
else
local SOURCE_GOPATH=`pwd`/.gopath
local VENDOR_GOPATH=`pwd`/vendor
Expand Down

0 comments on commit ac04c9b

Please sign in to comment.