blob: 6ed3f5b684c61bf475ea9d11eab175fb0fb13ebc [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package fuchsia
import (
"encoding/json"
"os"
)
// PackageManifest is a JSON structure that's produced by a Fuchsia build and
// describes which packages were built and where they're located.
type PackageManifest struct {
Available []string `json:"available"`
Monolith []string `json:"monolith"`
Preinstall []string `json:"preinstall"`
Packages []PackageDescriptor
}
// PackageDescriptor provides information about a package.
type PackageDescriptor struct {
// BuildDir is a relative path in the Fuchsia build directory to the location
// of the built package.
BuildDir string `json:"build_dir"`
// Dir is the GN-relative location of the package (part of the build target
// name).
Dir string `json:"dir"`
// Name is the basename of the package.
Name string `json:"name"`
}
// LoadPackageManifest loads a PackageManifest specified in JSON at a given
// filepath.
func LoadPackageManifest(pkgManifestPath string) (*PackageManifest, error) {
manifestFile, err := os.Open(pkgManifestPath)
if err != nil {
return nil, err
}
defer manifestFile.Close()
var manifest PackageManifest
err = json.NewDecoder(manifestFile).Decode(&manifest)
return &manifest, err
}