samples: zephyr: Separate build commands

Instead of just having the build commands part of the test execution,
separate them into a separate value.  This will facilitate having an
option that doesn't actually build the tests, but extracts them from an
archive.

Signed-off-by: David Brown <david.brown@linaro.org>
diff --git a/samples/zephyr/run-tests.go b/samples/zephyr/run-tests.go
index 9b57664..8124f9f 100644
--- a/samples/zephyr/run-tests.go
+++ b/samples/zephyr/run-tests.go
@@ -41,6 +41,8 @@
 // Output from this test run is written to the given log file.
 var logOut = flag.String("logout", "tests.log", "Log file to write to")
 
+var preBuilt = flag.String("prebuilt", "", "Name of file with prebuilt tests")
+
 func main() {
 	err := run()
 	if err != nil {
@@ -69,13 +71,20 @@
 		fmt.Fprintf(lg, "---- Running %q\n", group.Name)
 
 		for _, test := range group.Tests {
-			for _, cmd := range test.Commands {
-				fmt.Printf("    %s\n", cmd)
-				fmt.Fprintf(lg, "---- Run: %s\n", cmd)
-				err = runCommand(cmd, lg)
+			if *preBuilt == "" {
+				// No prebuilt, build the tests
+				// ourselves.
+				err = runCommands(test.Build, lg)
 				if err != nil {
 					return err
 				}
+			} else {
+				panic("TODO")
+			}
+
+			err = runCommands(test.Commands, lg)
+			if err != nil {
+				return err
 			}
 
 			err = expect(lg, lines, test.Expect)
@@ -91,6 +100,20 @@
 	return nil
 }
 
+// Run a set of commands
+func runCommands(cmds [][]string, lg io.Writer) error {
+	for _, cmd := range cmds {
+		fmt.Printf("    %s\n", cmd)
+		fmt.Fprintf(lg, "---- Run: %s\n", cmd)
+		err := runCommand(cmd, lg)
+		if err != nil {
+			return err
+		}
+	}
+
+	return nil
+}
+
 // Run a single command.
 func runCommand(cmd []string, lg io.Writer) error {
 	c := exec.Command(cmd[0], cmd[1:]...)