[testsharder] Load packages like platforms

Load packages as a function of the build directory root, as we do for
platforms.

Test: run locally.
Change-Id: I387a21842f51f223056c277d7a836e3fbcbc5ffa
diff --git a/cmd/testsharder/main.go b/cmd/testsharder/main.go
index f0a57e4..9f61797 100644
--- a/cmd/testsharder/main.go
+++ b/cmd/testsharder/main.go
@@ -8,7 +8,6 @@
 	"flag"
 	"log"
 	"os"
-	"path/filepath"
 
 	"fuchsia.googlesource.com/infra/infra/fuchsia"
 	"fuchsia.googlesource.com/infra/infra/fuchsia/testexec"
@@ -39,10 +38,9 @@
 	}
 
 	// Load spec files.
-	pkgManifestPath := filepath.Join(fuchsiaBuildDir, fuchsia.PackageManifestName)
-	pkgs, err := fuchsia.LoadPackages(pkgManifestPath)
+	pkgs, err := fuchsia.LoadPackages(fuchsiaBuildDir)
 	if err != nil {
-		log.Fatalf("failed to load package manifest from %s: %v", pkgManifestPath, err)
+		log.Fatal(err)
 	}
 	specs, err := testexec.LoadTestSpecs(fuchsiaBuildDir, pkgs)
 	if err != nil {
@@ -50,10 +48,9 @@
 	}
 
 	// Load test platform environments.
-	platformManifestPath := filepath.Join(fuchsiaBuildDir, fuchsia.PlatformManifestName)
-	platforms, err := testexec.LoadPlatforms(platformManifestPath)
+	platforms, err := testexec.LoadPlatforms(fuchsiaBuildDir)
 	if err != nil {
-		log.Fatalf("failed to load test platforms from %s: %v", platformManifestPath, err)
+		log.Fatal(err)
 	}
 
 	// Verify that the produced specs specify valid test environments.
diff --git a/fuchsia/build.go b/fuchsia/build.go
index 3744984..f0d75b9 100644
--- a/fuchsia/build.go
+++ b/fuchsia/build.go
@@ -9,6 +9,7 @@
 import (
 	"encoding/json"
 	"os"
+	"path/filepath"
 )
 
 const (
@@ -40,8 +41,9 @@
 }
 
 // LoadPackages loads a list of packages targets from JSON package manifest
-// produced by the build.
-func LoadPackages(manifestPath string) ([]Target, error) {
+// produced by the build, given the root of the build directory.
+func LoadPackages(fuchsiaBuildDir string) ([]Target, error) {
+	manifestPath := filepath.Join(fuchsiaBuildDir, PackageManifestName)
 	manifestFile, err := os.Open(manifestPath)
 	if err != nil {
 		return nil, err
diff --git a/fuchsia/testexec/environment.go b/fuchsia/testexec/environment.go
index e4aac01..3d29147 100644
--- a/fuchsia/testexec/environment.go
+++ b/fuchsia/testexec/environment.go
@@ -13,6 +13,9 @@
 import (
 	"encoding/json"
 	"io/ioutil"
+	"path/filepath"
+
+	"fuchsia.googlesource.com/infra/infra/fuchsia"
 )
 
 // Environment describes the full environment a test requires.
@@ -46,9 +49,10 @@
 	return true
 }
 
-// LoadPlatforms loads the list of test platform dimension sets specified as a
-// JSON list at a given filepath.
-func LoadPlatforms(platformManifestPath string) ([]DimensionSet, error) {
+// LoadPlatforms loads the list of test platforms specified as a JSON list
+// produced by a build, given the root of the build directory.
+func LoadPlatforms(fuchsiaBuildDir string) ([]DimensionSet, error) {
+	platformManifestPath := filepath.Join(fuchsiaBuildDir, fuchsia.PlatformManifestName)
 	bytes, err := ioutil.ReadFile(platformManifestPath)
 	if err != nil {
 		return nil, err