Skip to content

Commit 0210656

Browse files
committed
Capture module repo verions and binary lib info (file hash)
1 parent ad799f8 commit 0210656

File tree

45 files changed

+269
-112
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+269
-112
lines changed

cli/build/manifest.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type FWAppManifestLibHandled struct {
5555
Deps []string `yaml:"deps,omitempty" json:"deps"`
5656
InitDeps []string `yaml:"init_deps,omitempty" json:"init_deps"`
5757
Sources []string `yaml:"sources,omitempty" json:"sources"`
58+
BinaryLibs []string `yaml:"binary_libs,omitempty" json:"binary_libs"`
5859
Version string `yaml:"version,omitempty" json:"version"`
5960
RepoVersion string `yaml:"repo_version,omitempty" json:"version"`
6061
Manifest *FWAppManifest `yaml:"-" json:"-"`

cli/manifest_parser/bindata.go

Lines changed: 22 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/manifest_parser/data/mgos_deps_init.c.tmpl

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,59 @@
1414
struct mgos_lib_info {
1515
const char *name;
1616
const char *version;
17+
const char *repo_version;
18+
const char *binary_libs;
1719
bool (*init)(void);
1820
};
21+
#define MGOS_LIB_INFO_VERSION 2
1922
#endif
23+
2024
#ifndef MGOS_MODULE_INFO_VERSION
2125
struct mgos_module_info {
2226
const char *name;
2327
const char *version;
2428
};
29+
#define MGOS_MODULE_INFO_VERSION 1
2530
#endif
2631

2732
const struct mgos_lib_info mgos_libs_info[] = {
2833
{{range .Libs}}
29-
// "{{.Name}}". deps: [ {{range .Deps}}"{{.}}" {{end}}]
30-
{.name = "{{.Name}}", .version = "{{.Version}}", .init = {{.InitFunc}}},
34+
// {{.Name}}. deps: [ {{range .Deps}}"{{.}}" {{end}}]
35+
#if MGOS_LIB_INFO_VERSION == 1
36+
{.name = {{.Name}}, .version = {{.Version}}, .init = {{.InitFunc}}},
37+
#else
38+
{.name = {{.Name}}, .version = {{.Version}}, .repo_version = {{.RepoVersion}}, .binary_libs = {{.BinaryLibs}}, .init = {{.InitFunc}}},
39+
#endif
3140
{{end}}
3241
// Last entry.
3342
{.name = NULL},
3443
};
3544

3645
const struct mgos_module_info mgos_modules_info[] = {
3746
{{range .Modules}}
38-
{.name = "{{.Name}}", .version = "{{.Version}}"},
47+
{.name = {{.Name}}, .repo_version = {{.RepoVersion}}},
3948
{{end}}
4049
// Last entry.
4150
{.name = NULL},
4251
};
4352

4453
bool mgos_deps_init(void) {
4554
for (const struct mgos_lib_info *l = mgos_libs_info; l->name != NULL; l++) {
46-
LOG(LL_DEBUG, ("Init %s %s...", l->name, l->version));
55+
#if MGOS_LIB_INFO_VERSION == 1
56+
LOG(LL_DEBUG, ("Init %s %s...", l->name, (l->version ? l->version : "")));
57+
#else
58+
LOG(LL_DEBUG, ("Init %s %s (%s)...",
59+
l->name,
60+
(l->version ? l->version : ""),
61+
(l->repo_version ? l->repo_version : "")));
62+
#endif
4763
if (l->init != NULL && !l->init()) {
4864
LOG(LL_ERROR, ("%s init failed", l->name));
4965
return false;
5066
}
5167
}
5268
for (const struct mgos_module_info *m = mgos_modules_info; m->name != NULL; m++) {
53-
LOG(LL_DEBUG, ("Module %s %s", m->name, m->version));
69+
LOG(LL_DEBUG, ("Module %s %s", m->name, (m->repo_version ? m->repo_version : "")));
5470
}
5571
return true;
5672
}

cli/manifest_parser/manifest_parser.go

Lines changed: 69 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package manifest_parser
2222

2323
import (
2424
"bytes"
25+
"crypto/sha256"
2526
"fmt"
2627
"io"
2728
"io/ioutil"
@@ -282,35 +283,6 @@ func ReadManifestFinal(
282283
gitinst := mosgit.NewOurGit(nil)
283284
mosHash, _ := gitinst.GetCurrentHash(fp.MosDirEffective)
284285

285-
if manifest.Type == build.AppTypeApp {
286-
// Generate deps_init C code, and if it's not empty, write it to the temp
287-
// file and add to sources
288-
depsCCode, err := getDepsInitCCode(manifest, mosHash)
289-
if err != nil {
290-
return nil, nil, errors.Trace(err)
291-
}
292-
293-
if len(depsCCode) != 0 {
294-
fname := moscommon.GetDepsInitCFilePath(buildDirAbs)
295-
296-
if err := os.MkdirAll(moscommon.GetGeneratedFilesDir(buildDirAbs), 0777); err != nil {
297-
return nil, nil, errors.Trace(err)
298-
}
299-
300-
if err = ioutil.WriteFile(fname, depsCCode, 0666); err != nil {
301-
return nil, nil, errors.Trace(err)
302-
}
303-
304-
// The modification time of autogenerated file should be set to that of
305-
// the manifest itself, so that make handles dependencies correctly.
306-
if err := os.Chtimes(fname, mtime, mtime); err != nil {
307-
return nil, nil, errors.Trace(err)
308-
}
309-
310-
manifest.Sources = append(manifest.Sources, fname)
311-
}
312-
}
313-
314286
// Convert manifest.Sources into paths to concrete existing source files.
315287
manifest.Sources, fp.AppSourceDirs, err = resolvePaths(manifest.Sources, *sourceGlobs)
316288
if err != nil {
@@ -421,6 +393,7 @@ func ReadManifestFinal(
421393
if binaryLib != "" {
422394
// We should use binary lib instead of sources
423395
manifest.LibsHandled[k].Sources = []string{}
396+
manifest.LibsHandled[k].BinaryLibs = append(manifest.LibsHandled[k].BinaryLibs, binaryLib)
424397
manifest.BinaryLibs = append(manifest.BinaryLibs, binaryLib)
425398
} else {
426399
// Use lib sources, not prebuilt binary
@@ -440,6 +413,34 @@ func ReadManifestFinal(
440413

441414
fp.AppSourceDirs = append(fp.AppSourceDirs, libSourceDirs...)
442415
}
416+
417+
// Generate deps_init C code, and if it's not empty, write it to the temp
418+
// file and add to sources
419+
depsCCode, err := getDepsInitCCode(manifest, mosHash)
420+
if err != nil {
421+
return nil, nil, errors.Trace(err)
422+
}
423+
424+
if len(depsCCode) != 0 {
425+
fname := moscommon.GetDepsInitCFilePath(buildDirAbs)
426+
427+
if err := os.MkdirAll(moscommon.GetGeneratedFilesDir(buildDirAbs), 0777); err != nil {
428+
return nil, nil, errors.Trace(err)
429+
}
430+
431+
if err = ioutil.WriteFile(fname, depsCCode, 0666); err != nil {
432+
return nil, nil, errors.Trace(err)
433+
}
434+
435+
// The modification time of autogenerated file should be set to that of
436+
// the manifest itself, so that make handles dependencies correctly.
437+
if err := os.Chtimes(fname, mtime, mtime); err != nil {
438+
return nil, nil, errors.Trace(err)
439+
}
440+
441+
manifest.Sources = append(manifest.Sources, fname)
442+
}
443+
443444
}
444445

445446
manifest.BinaryLibs, fp.AppBinLibDirs, err = resolvePaths(manifest.BinaryLibs, []string{"*.a"})
@@ -1650,23 +1651,32 @@ func mergeSupportedPlatforms(p1, p2 []string) []string {
16501651
}
16511652

16521653
type libInfo struct {
1653-
Name string
1654-
Version string
1655-
HaveInit bool
1656-
InitFunc string
1657-
Deps []string
1654+
Name string
1655+
Version string
1656+
RepoVersion string
1657+
BinaryLibs string
1658+
HaveInit bool
1659+
InitFunc string
1660+
Deps []string
16581661
}
16591662

16601663
type moduleInfo struct {
1661-
Name string
1662-
Version string
1664+
Name string
1665+
RepoVersion string
16631666
}
16641667

16651668
type libsInitData struct {
16661669
Libs []libInfo
16671670
Modules []moduleInfo
16681671
}
16691672

1673+
func quoteOrNULL(s string) string {
1674+
if s == "" {
1675+
return "NULL"
1676+
}
1677+
return fmt.Sprintf("%q", s)
1678+
}
1679+
16701680
func getDepsInitCCode(manifest *build.FWAppManifest, mosHash string) ([]byte, error) {
16711681
if len(manifest.LibsHandled) == 0 {
16721682
return nil, nil
@@ -1681,34 +1691,44 @@ func getDepsInitCCode(manifest *build.FWAppManifest, mosHash string) ([]byte, er
16811691
break
16821692
}
16831693
}
1684-
lv := lh.Version
1685-
if lh.RepoVersion != "" {
1686-
lv = fmt.Sprintf("%s/%s", lv, lh.RepoVersion)
1687-
}
16881694
initFunc := "NULL"
1689-
if len(lh.Sources) > 0 {
1695+
if len(lh.Sources) > 0 || len(lh.BinaryLibs) > 0 {
16901696
initFunc = fmt.Sprintf("mgos_%s_init", ourutil.IdentifierFromString(lh.Lib.Name))
16911697
}
1698+
var blHashes []string
1699+
for _, fname := range lh.BinaryLibs {
1700+
data, err := ioutil.ReadFile(fname)
1701+
if err != nil {
1702+
return nil, errors.Annotatef(err, "failed to checksum binary lib file")
1703+
}
1704+
dataHash := sha256.Sum256(data)
1705+
blHashes = append(blHashes, fmt.Sprintf("%s:%x", filepath.Base(fname), dataHash))
1706+
}
16921707
tplData.Libs = append(tplData.Libs, libInfo{
1693-
Name: lh.Lib.Name,
1694-
Version: lv,
1695-
HaveInit: initFunc != "NULL",
1696-
InitFunc: initFunc,
1697-
Deps: lh.InitDeps,
1708+
Name: quoteOrNULL(lh.Lib.Name),
1709+
Version: quoteOrNULL(lh.Version),
1710+
RepoVersion: quoteOrNULL(lh.RepoVersion),
1711+
BinaryLibs: quoteOrNULL(strings.Join(blHashes, ",")),
1712+
HaveInit: initFunc != "NULL",
1713+
InitFunc: initFunc,
1714+
Deps: lh.InitDeps,
16981715
})
16991716
}
17001717

17011718
tplData.Modules = []moduleInfo{
1702-
moduleInfo{Name: "mongoose-os", Version: mosHash},
1719+
moduleInfo{
1720+
Name: quoteOrNULL("mongoose-os"),
1721+
RepoVersion: quoteOrNULL(mosHash),
1722+
},
17031723
}
17041724
for _, m := range manifest.Modules {
17051725
mv := ""
17061726
if lmv, err := m.GetLocalVersion(); err == nil {
17071727
mv = lmv
17081728
}
17091729
tplData.Modules = append(tplData.Modules, moduleInfo{
1710-
Name: m.Name,
1711-
Version: mv,
1730+
Name: quoteOrNULL(m.Name),
1731+
RepoVersion: quoteOrNULL(mv),
17121732
})
17131733
}
17141734

cli/manifest_parser/test_manifests/test_02_weak_dep_unused/expected/esp8266/mos_final.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ __ALL_PLATFORMS__
66
author: mongoose-os
77
description: My test app
88
sources:
9-
- __APP_ROOT__/app/build/gen/mgos_deps_init.c
109
- __APP_ROOT__/libs/mylib1/src/mylib1_src1.c
1110
- __APP_ROOT__/libs/mylib2/src/mylib2_src1.c
1211
- __APP_ROOT__/libs/mylib3/src/mylib3_src1.c
12+
- __APP_ROOT__/app/build/gen/mgos_deps_init.c
1313
includes:
1414
- __APP_ROOT__/libs/mylib2/include
1515
- __APP_ROOT__/libs/mylib3/include

0 commit comments

Comments
 (0)