Contributing to Newt or Newtmgr Tools

Newt and Newtmgr are written in Go (golang). This guide shows you how to install Go and setup your environment to update and build the tools if you want to:

  • Build the tools with latest updates from the master branch on Linux or Windows platforms.

    Note: For Mac OS, you can use the brew install mynewt-newt -HEAD and the brew install mynewt-newtmgr --HEAD commands.

  • Contribute to newt or newtmgr features or fix bugs.

This guide shows you how to perform the following:

  1. Install Mac OS X, Linux, Windows. (Tasks that are specific to each platform are called out.)
  2. Setup the Go environment.
  3. Download the source, build, and install the newt or newtmgr tools.
  4. Update and rebuild the tools.

Note: You will also need to read and follow the instructions from the FAQ to set up your git repos to submit changes.

Step 1: Installing Go

The latest master branch of newt and newtmgr requires GO version 1.10.3 or higher. You can skip this step and proceed to Step 2 if you already have Go version 1.10.3 or higher installed.

If you do not have Homebrew installed, run the following command. You will be prompted for your sudo password.

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

You can also extract (or git clone) Homebrew and install it to /usr/local.

$ brew install go
==> 
...
... 
==> Summary
🍺  /usr/local/Cellar/go/1.10.3: 8,170 files, 336.8MB

You can also download the Go package directly from (https://golang.org/dl/) and install it in /usr/local/bin instead of brewing it.

This section describes the Go environment and how to setup a Go workspace. If you already have a Go workspace for your other Go projects, you can skip this step and proceed to Step 3.

Go provides an environment to compile Go code, construct Go packages, and import Go code. You will use Go commands to import the newt or newtmgr package repository into your local Go environment. The Go language environment dictates a specific directory structure, or workspace in Go parlance. It must contain three sibling directories with the names src, pkg and bin:

  • src contains Go source files organized into packages (one package per directory)
  • pkg contains package objects
  • bin contains the Go application executables that Go builds and installs.

The GOPATH environment variable specifies the location of your workspace. To setup this workspace environment, create a dev directory and then a go directory under it. Set the GOPATH environment variable to this directory where you will clone the newt and newtmgr repositories.

$ cd $HOME
$ mkdir -p dev/go  
$ cd dev/go
$ export GOPATH=`pwd`

Step 3: Downloading the Source and Installing the Tools

Newt and newtmgr are individual Go packages and have their own git repositories. You can download the source and install one or both tools.

We use the go get command to download the source, build, and install the binary in the $GOPATH/bin directory.

The newt Go package is mynewt.apache.org/newt/newt and is stored in the Apache Mynewt newt tool repository mirrored on github.

Download the newt package source and install the tool:

$cd $GOPATH
$go get mynewt.apache.org/newt/newt
$cd $GOPATH/src/mynewt.apache.org/newt
$ls 
DISCLAIMER		RELEASE_NOTES.md	util
INSTALLING.md		build.sh		viper
LICENSE			newt			yaml
NOTICE			newtmgr
README.md		newtvm
$git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
$ls $GOPATH/bin/newt
~/dev/go/bin/newt
$which newt
~/dev/go/bin/newt
$newt version
Apache Newt version: 1.1.0-dev

The newtmgr Go package is mynewt.apache.org/newtmgr/newtmgr. It is stored in the Apache Mynewt newtmgr tool repository mirrored on github.

Download the newtmgr package and install the tool:

$cd $GOPATH
$go get mynewt.apache.org/newtmgr/newtmgr
$cd $GOPATH/src/mynewt.apache.org/newtmgr
$ls
LICENSE		NOTICE		README.md	newtmgr		nmxact
$git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
$ls $GOPATH/bin/newtmgr
~/dev/go/bin/newtmgr
$which newtmgr
~/dev/go/bin/newtmgr

Here is the general procedure to rebuild either the newt or newtmgr tool. The only difference is the directory where you will be executing the commands from. You will need to repeat the procedure to rebuild both tools.

  1. Change to the directory where the local Git repository for the tool is installed.
  2. Pull the latest changes from the master branch. If you made changes you will need to rebase with origin master (See FAQ).
  3. Build and install the tool.

For the newt tool:

$cd $GOPATH/src/mynewt.apache.org/newt/newt

For the newtmgr tool:

$cd $GOPATH/src/mynewt.apache.org/newtmgr/newtmgr
$git pull 
$go install

You can run the ls -l command to check the modification time for the binary to ensure the new version is installed.