Skip to content

Commit

Permalink
Generate deps manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
rojer committed Mar 28, 2021
1 parent d9c1619 commit 098c1d8
Show file tree
Hide file tree
Showing 58 changed files with 952 additions and 112 deletions.
2 changes: 1 addition & 1 deletion cli/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ func (lpr *compProviderReal) GetLibLocalPath(
}

if m.GetType() == build.SWModuleTypeGit && updateIntvl != 0 {
if newHash, err := m.GetLocalVersion(); err == nil && newHash != curHash {
if newHash, _, err := m.GetRepoVersion(); err == nil && newHash != curHash {
freportf(logWriter, "%s: Hash is updated: %s -> %s", name, curHash, newHash)
// The current repo hash has changed after the pull, so we need to
// vanish binary lib(s) we might have downloaded before
Expand Down
106 changes: 106 additions & 0 deletions cli/build/deps_manifest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//
// Copyright (c) 2014-2019 Cesanta Software Limited
// All rights reserved
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package build

import (
"crypto/sha256"
"fmt"
"io/ioutil"
"path/filepath"
"sort"
"strings"

"github.com/juju/errors"
)

const DepsManifestVersion = "2021-03-26"

// DepsManifest describes exact versions of libraries, modules and binary blobs that went into firmware.
type DepsManifest struct {
AppName string `yaml:"app_name,omitempty" json:"app_name,omitempty"`

Libs []*DepsManifestEntry `yaml:"libs,omitempty" json:"libs,omitempty"`
Modules []*DepsManifestEntry `yaml:"modules,omitempty" json:"modules,omitempty"`

ManifestVersion string `yaml:"manifest_version,omitempty" json:"manifest_version,omitempty"`
}

type DepsManifestEntry struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Location string `yaml:"location,omitempty" json:"location,omitempty"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
RepoVersion string `yaml:"repo_version,omitempty" json:"repo_version,omitempty"`
RepoDirty bool `yaml:"repo_dirty,omitempty" json:"repo_dirty,omitempty"`
Blobs []*DepsBlobEntry `yaml:"blobs,omitempty" json:"blobs,omitempty"`
}

type DepsBlobEntry struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Size int `yaml:"size,omitempty" json:"size,omitempty"`
SHA256 string `yaml:"cs_sha256,omitempty" json:"cs_sha256,omitempty"`
}

func GenerateDepsManifest(m *FWAppManifest) (*DepsManifest, error) {
res := &DepsManifest{
AppName: m.Name,
ManifestVersion: DepsManifestVersion,
}

for _, lh := range m.LibsHandled {
e := &DepsManifestEntry{
Name: lh.Lib.Name,
Location: lh.Lib.Location,
Version: lh.Version,
RepoVersion: lh.RepoVersion,
RepoDirty: lh.RepoDirty,
}
for _, fname := range lh.BinaryLibs {
data, err := ioutil.ReadFile(fname)
if err != nil {
return nil, errors.Annotatef(err, "failed to checksum binary lib file")
}
dataHash := sha256.Sum256(data)
e.Blobs = append(e.Blobs, &DepsBlobEntry{
Name: filepath.Base(fname),
Size: len(data),
SHA256: fmt.Sprintf("%x", dataHash),
})
}
sort.Slice(e.Blobs, func(i, j int) bool {
return strings.Compare(e.Blobs[i].Name, e.Blobs[j].Name) < 0
})
res.Libs = append(res.Libs, e)
}
sort.Slice(res.Libs, func(i, j int) bool {
return strings.Compare(res.Libs[i].Name, res.Libs[j].Name) < 0
})

for _, m := range m.Modules {
rv, dirty, _ := m.GetRepoVersion()
res.Modules = append(res.Modules, &DepsManifestEntry{
Name: m.Name,
Location: m.Location,
RepoVersion: rv,
RepoDirty: dirty,
})
}
sort.Slice(res.Modules, func(i, j int) bool {
return strings.Compare(res.Modules[i].Name, res.Modules[j].Name) < 0
})

return res, nil
}
1 change: 1 addition & 0 deletions cli/build/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type FWAppManifestLibHandled struct {
BinaryLibs []string `yaml:"binary_libs,omitempty" json:"binary_libs"`
Version string `yaml:"version,omitempty" json:"version"`
RepoVersion string `yaml:"repo_version,omitempty" json:"version"`
RepoDirty bool `yaml:"repo_dirty,omitempty" json:"repo_dirty"`
Manifest *FWAppManifest `yaml:"-" json:"-"`
}

Expand Down
Loading

0 comments on commit 098c1d8

Please sign in to comment.