Skip to content

Commit d0c5a9b

Browse files
committed
Make mongoose-os just another module
1 parent 6a9cce2 commit d0c5a9b

File tree

54 files changed

+198
-174
lines changed

Some content is hidden

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

54 files changed

+198
-174
lines changed

cli/build.go

+3-50
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ func buildHandler(ctx context.Context, devConn dev.DevConn) error {
172172
parts := strings.SplitN(m, ":", 2)
173173
cml[parts[0]] = parts[1]
174174
}
175+
if *mosRepo != "" {
176+
cml[build.MosModuleName] = *mosRepo
177+
}
175178

176179
buildVarsFromCLI, err := getBuildVarsFromCLI()
177180
if err != nil {
@@ -636,56 +639,6 @@ func (lpr *compProviderReal) GetModuleLocalPath(
636639
return targetDir, nil
637640
}
638641

639-
func (lpr *compProviderReal) GetMongooseOSLocalPath(
640-
rootAppDir, modulesDefVersion string,
641-
) (string, error) {
642-
targetDir, err := getMosDirEffective(modulesDefVersion, *libsUpdateInterval)
643-
if err != nil {
644-
return "", errors.Trace(err)
645-
}
646-
647-
return targetDir, nil
648-
}
649-
650-
func getMosDirEffective(mongooseOsVersion string, updateInterval time.Duration) (string, error) {
651-
var mosDirEffective string
652-
if *mosRepo != "" {
653-
freportf(logWriter, "Using mongoose-os located at %q", *mosRepo)
654-
mosDirEffective = *mosRepo
655-
} else {
656-
freportf(logWriter, "The flag --repo is not given, going to use mongoose-os repository")
657-
appDir, err := getCodeDirAbs()
658-
if err != nil {
659-
return "", errors.Trace(err)
660-
}
661-
662-
md := paths.GetModulesDir(appDir)
663-
664-
m := build.SWModule{
665-
// TODO(dfrank) get upstream repo URL from a flag
666-
// (and this flag needs to be forwarded to fwbuild as well, which should
667-
// forward it to the mos invocation)
668-
Location: "https://github.com/cesanta/mongoose-os",
669-
Version: mongooseOsVersion,
670-
}
671-
672-
if *noLibsUpdate {
673-
updateInterval = 0
674-
}
675-
676-
if mosDirEffective == "" {
677-
// NOTE: mongoose-os repo is huge, so in order to save space and time, we
678-
// do a shallow clone (--depth 1).
679-
mosDirEffective, err = m.PrepareLocalDir(md, logWriter, true, "", updateInterval, 1)
680-
if err != nil {
681-
return "", errors.Annotatef(err, "preparing local copy of the mongoose-os repo")
682-
}
683-
}
684-
}
685-
686-
return mosDirEffective, nil
687-
}
688-
689642
// }}}
690643

691644
// Thread-safe bytes.Buffer {{{

cli/build/manifest.go

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ package build
1919
const (
2020
ManifestTypeApp = "app"
2121
ManifestTypeLib = "lib"
22+
23+
MosModuleName = "mongoose-os"
24+
MosDefaultRepo = "https://github.com/cesanta/mongoose-os"
2225
)
2326

2427
// ManifestCond represents a conditional addition to the manifest.

cli/get_mos_repo_dir.go

-81
This file was deleted.

cli/main.go

-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ func init() {
161161
{"esp32-encrypt-image", esp32EncryptImage, `Encrypt a ESP32 firmware image`, []string{"esp32-encryption-key-file", "esp32-flash-address"}, nil, No, true},
162162
{"esp32-gen-key", esp32GenKey, `Generate and program an encryption key`, nil, nil, No, true},
163163
{"eval-manifest-expr", evalManifestExpr, `Evaluate the expression against the final manifest`, nil, nil, No, true},
164-
{"get-mos-repo-dir", getMosRepoDir, `Show mongoose-os repo absolute path`, nil, nil, No, true},
165164
{"git-credentials", gitCredentials, `Git credentials helper mode`, nil, nil, No, true},
166165
{"ports", showPorts, `Show serial ports`, nil, nil, No, true},
167166
}

cli/manifest_parser/manifest_parser.go

+12-30
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import (
4444
"github.com/mongoose-os/mos/cli/build"
4545
moscommon "github.com/mongoose-os/mos/cli/common"
4646
"github.com/mongoose-os/mos/cli/interpreter"
47-
"github.com/mongoose-os/mos/cli/mosgit"
4847
"github.com/mongoose-os/mos/cli/ourutil"
4948
"github.com/mongoose-os/mos/version"
5049
)
@@ -96,8 +95,6 @@ type ComponentProvider interface {
9695
GetModuleLocalPath(
9796
m *build.SWModule, rootAppDir, modulesDefVersion, platform string,
9897
) (string, error)
99-
100-
GetMongooseOSLocalPath(rootAppDir, mongooseOSVersion string) (string, error)
10198
}
10299

103100
type ReadManifestCallbacks struct {
@@ -177,6 +174,12 @@ func ReadManifestFinal(
177174
return nil, nil, errors.Annotatef(err, "while expanding description")
178175
}
179176

177+
manifest.Modules = append(manifest.Modules, build.SWModule{
178+
Name: build.MosModuleName,
179+
Location: build.MosDefaultRepo,
180+
Version: manifest.MongooseOsVersion,
181+
})
182+
180183
// Prepare local copies of all sw modules {{{
181184
// Modules are collected from the bottom of the dependency chain,
182185
// we go backwards to ensure overrides are handled first.
@@ -194,28 +197,16 @@ func ReadManifestFinal(
194197

195198
moduleDir, err := cbs.ComponentProvider.GetModuleLocalPath(m, dir, manifest.ModulesVersion, manifest.Platform)
196199
if err != nil {
197-
return nil, nil, errors.Trace(err)
200+
return nil, nil, errors.Annotatef(err, "failed to prepare module %q", name)
198201
}
199202

200203
interpreter.SetModuleVars(interp.MVars, name, moduleDir)
201204
modulesHandled[name] = true
202-
}
203-
// }}}
204205

205-
// Determine mongoose-os dir (fp.MosDirEffective) {{{
206-
fp.MosDirEffective, err = cbs.ComponentProvider.GetMongooseOSLocalPath(
207-
dir, manifest.MongooseOsVersion,
208-
)
209-
if err != nil {
210-
return nil, nil, errors.Trace(err)
211-
}
212-
213-
fp.MosDirEffective, err = filepath.Abs(fp.MosDirEffective)
214-
if err != nil {
215-
return nil, nil, errors.Annotatef(err, "getting absolute path of %q", fp.MosDirEffective)
206+
if name == build.MosModuleName {
207+
fp.MosDirEffective = moduleDir
208+
}
216209
}
217-
218-
interpreter.SetModuleVars(interp.MVars, "mongoose-os", fp.MosDirEffective)
219210
// }}}
220211

221212
// Get sources and filesystem files from the manifest, expanding expressions {{{
@@ -280,9 +271,6 @@ func ReadManifestFinal(
280271
}
281272
// }}}
282273

283-
gitinst := mosgit.NewOurGit(nil)
284-
mosHash, _ := gitinst.GetCurrentHash(fp.MosDirEffective)
285-
286274
// Convert manifest.Sources into paths to concrete existing source files.
287275
manifest.Sources, fp.AppSourceDirs, err = resolvePaths(manifest.Sources, *sourceGlobs)
288276
if err != nil {
@@ -416,7 +404,7 @@ func ReadManifestFinal(
416404

417405
// Generate deps_init C code, and if it's not empty, write it to the temp
418406
// file and add to sources
419-
depsCCode, err := getDepsInitCCode(manifest, mosHash)
407+
depsCCode, err := getDepsInitCCode(manifest)
420408
if err != nil {
421409
return nil, nil, errors.Trace(err)
422410
}
@@ -1677,7 +1665,7 @@ func quoteOrNULL(s string) string {
16771665
return fmt.Sprintf("%q", s)
16781666
}
16791667

1680-
func getDepsInitCCode(manifest *build.FWAppManifest, mosHash string) ([]byte, error) {
1668+
func getDepsInitCCode(manifest *build.FWAppManifest) ([]byte, error) {
16811669
if len(manifest.LibsHandled) == 0 {
16821670
return nil, nil
16831671
}
@@ -1715,12 +1703,6 @@ func getDepsInitCCode(manifest *build.FWAppManifest, mosHash string) ([]byte, er
17151703
})
17161704
}
17171705

1718-
tplData.Modules = []moduleInfo{
1719-
moduleInfo{
1720-
Name: quoteOrNULL("mongoose-os"),
1721-
RepoVersion: quoteOrNULL(mosHash),
1722-
},
1723-
}
17241706
for _, m := range manifest.Modules {
17251707
mv := ""
17261708
if lmv, err := m.GetLocalVersion(); err == nil {

cli/manifest_parser/manifest_parser_test.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func singleManifestTest(t *testing.T, appPath string) error {
185185
}
186186
}
187187

188-
depsInitData, err := getDepsInitCCode(manifest, "xxx")
188+
depsInitData, err := getDepsInitCCode(manifest)
189189
if err != nil {
190190
return errors.Trace(err)
191191
}
@@ -240,12 +240,6 @@ func (lpt *compProviderTest) GetModuleLocalPath(
240240
return filepath.Join(rootAppDir, "..", "modules", parts[len(parts)-1]), nil
241241
}
242242

243-
func (lpt *compProviderTest) GetMongooseOSLocalPath(
244-
rootAppDir, modulesDefVersion string,
245-
) (string, error) {
246-
return repoRoot, nil
247-
}
248-
249243
func newMosVars() *interpreter.MosVars {
250244
ret := interpreter.NewMosVars()
251245
ret.SetVar(interpreter.GetMVarNameMosVersion(), "0.01")

cli/manifest_parser/test_manifests/test_01_nolibs/app/mos.yml

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ author: mongoose-os
22
description: My nolibs app
33
version: 1.0
44

5+
mongoose_os_version: 1.2.3
6+
57
sources:
68
- src
79

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ sources:
1010
- __APP_ROOT__/app/src/foo.c
1111
filesystem:
1212
- __APP_ROOT__/app/fs/myfile
13+
modules:
14+
- location: https://github.com/cesanta/mongoose-os
15+
version: 1.2.3
16+
name: mongoose-os
1317
no_implicit_init_deps: true
1418
build_vars:
1519
BOARD: ""
@@ -18,5 +22,5 @@ cdefs:
1822
MGOS: "1"
1923
libs_version: "0.01"
2024
modules_version: "0.01"
21-
mongoose_os_version: "0.01"
25+
mongoose_os_version: 1.2.3
2226
manifest_version: "2018-06-20"

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

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ filesystem:
1717
- __APP_ROOT__/libs/mylib1/fs/mylib1_file1
1818
- __APP_ROOT__/libs/mylib2/fs/mylib2_file1
1919
- __APP_ROOT__/libs/mylib3/fs/mylib3_file1
20+
modules:
21+
- location: https://github.com/cesanta/mongoose-os
22+
version: "0.01"
23+
name: mongoose-os
2024
config_schema:
2125
- - mylib1
2226
- o

cli/manifest_parser/test_manifests/test_03_weak_dep_used/expected/esp8266/mgos_deps_init.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const struct mgos_lib_info mgos_libs_info[] = {
7575

7676
const struct mgos_module_info mgos_modules_info[] = {
7777

78-
{.name = "mongoose-os", .repo_version = "xxx"},
78+
{.name = "mongoose-os", .repo_version = NULL},
7979

8080
// Last entry.
8181
{.name = NULL},

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

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ filesystem:
2020
- __APP_ROOT__/libs/mylib2/fs/mylib2_file1
2121
- __APP_ROOT__/libs/mylib4/fs/mylib4_file1
2222
- __APP_ROOT__/libs/mylib3/fs/mylib3_file1
23+
modules:
24+
- location: https://github.com/cesanta/mongoose-os
25+
version: "0.01"
26+
name: mongoose-os
2327
config_schema:
2428
- - mylib1
2529
- o

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

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ filesystem:
2020
- __APP_ROOT__/libs/mylib2/fs/mylib2_file1
2121
- __APP_ROOT__/libs/mylib4/fs/mylib4_file1
2222
- __APP_ROOT__/libs/mylib3/fs/mylib3_file1
23+
modules:
24+
- location: https://github.com/cesanta/mongoose-os
25+
version: "0.01"
26+
name: mongoose-os
2327
config_schema:
2428
- - mylib1
2529
- o

cli/manifest_parser/test_manifests/test_05_lib_override/expected/esp8266/mgos_deps_init.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const struct mgos_lib_info mgos_libs_info[] = {
5757

5858
const struct mgos_module_info mgos_modules_info[] = {
5959

60-
{.name = "mongoose-os", .repo_version = "xxx"},
60+
{.name = "mongoose-os", .repo_version = NULL},
6161

6262
// Last entry.
6363
{.name = NULL},

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

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ author: mongoose-os
77
description: My test app
88
sources:
99
- __APP_ROOT__/app/build/gen/mgos_deps_init.c
10+
modules:
11+
- location: https://github.com/cesanta/mongoose-os
12+
version: "0.01"
13+
name: mongoose-os
1014
config_schema:
1115
- - mylib2
1216
- o

cli/manifest_parser/test_manifests/testset_01_conds_switch_with_arch_manifests/test_01_app_doesnt_override/expected/esp32/mos_final.yml

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ filesystem:
2020
- __APP_ROOT__/libs/mylib2/fs/mylib2_file1
2121
- __APP_ROOT__/libs/mylib4/fs/mylib4_file1
2222
- __APP_ROOT__/libs/mylib3/fs/mylib3_file1
23+
modules:
24+
- location: https://github.com/cesanta/mongoose-os
25+
version: "0.01"
26+
name: mongoose-os
2327
config_schema:
2428
- - mylib1
2529
- o

0 commit comments

Comments
 (0)