Skip to content

Commit

Permalink
Override app name, description and version from app's conds
Browse files Browse the repository at this point in the history
  • Loading branch information
rojer committed Jan 29, 2020
1 parent 5ff0d91 commit bb2f974
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 12 deletions.
6 changes: 3 additions & 3 deletions cli/build_remote.go
Expand Up @@ -32,8 +32,6 @@ import (
"github.com/juju/errors"
yaml "gopkg.in/yaml.v2"

"github.com/mongoose-os/mos/common/ourfilepath"
"github.com/mongoose-os/mos/common/ourio"
"github.com/mongoose-os/mos/cli/build"
"github.com/mongoose-os/mos/cli/build/archive"
moscommon "github.com/mongoose-os/mos/cli/common"
Expand All @@ -42,6 +40,8 @@ import (
"github.com/mongoose-os/mos/cli/interpreter"
"github.com/mongoose-os/mos/cli/manifest_parser"
"github.com/mongoose-os/mos/cli/ourutil"
"github.com/mongoose-os/mos/common/ourfilepath"
"github.com/mongoose-os/mos/common/ourio"
"github.com/mongoose-os/mos/version"
)

Expand Down Expand Up @@ -121,7 +121,7 @@ func buildRemote(bParams *buildParams) error {
// manifest.Sources contain all the app's sources we need to build, so that
// they will be whitelisted (see whitelisting logic below) and thus uploaded
// to the remote builder.
if err := manifest_parser.ExpandManifestConds(manifest, manifest, interp); err != nil {
if err := manifest_parser.ExpandManifestConds(manifest, manifest, interp, true); err != nil {
return errors.Trace(err)
}

Expand Down
23 changes: 18 additions & 5 deletions cli/manifest_parser/manifest_parser.go
Expand Up @@ -62,8 +62,9 @@ const (
// - 2019-04-26: added warning and error
// - 2019-07-28: added init_before
// - 2020-01-21: added ability to override lib variants from conds in app manifest
// - 2020-01-29: added ability to override app name, description and version from app's conds
minManifestVersion = "2017-03-17"
maxManifestVersion = "2020-01-21"
maxManifestVersion = "2020-01-29"

depsApp = "app"

Expand Down Expand Up @@ -1069,7 +1070,7 @@ func expandManifestLibsAndConds(
//
// TODO(dfrank): probably make it so that if conds expression fails to
// evaluate, keep it unexpanded for now.
if err := ExpandManifestConds(rootManifest, rootManifest, interp); err != nil {
if err := ExpandManifestConds(rootManifest, rootManifest, interp, false); err != nil {
return errors.Trace(err)
}

Expand Down Expand Up @@ -1158,7 +1159,7 @@ func expandManifestLibsAndConds(
// top-level (app) conds are evaluated first, and then evaluation proceeds
// from the bottom (starting with libs with no deps).

if err := ExpandManifestConds(manifest, commonManifest, interp); err != nil {
if err := ExpandManifestConds(manifest, commonManifest, interp, true); err != nil {
return errors.Annotatef(err, "expanding app manifest's conds")
}
if len(manifest.Libs) > 0 {
Expand All @@ -1168,7 +1169,7 @@ func expandManifestLibsAndConds(

for _, l := range manifest.LibsHandled {
if l.Manifest != nil && len(l.Manifest.Conds) > 0 {
if err := ExpandManifestConds(l.Manifest, commonManifest, interp); err != nil {
if err := ExpandManifestConds(l.Manifest, commonManifest, interp, false); err != nil {
return errors.Annotatef(err, "expanding %q conds", l.Lib.Name)
}
if len(l.Manifest.Libs) > 0 {
Expand Down Expand Up @@ -1240,7 +1241,7 @@ func expandAllLibsPaths(
// `${build_vars.FOO} bar`) are expanded against dstManifest. See README.md,
// Step 3 for details.
func ExpandManifestConds(
dstManifest, refManifest *build.FWAppManifest, interp *interpreter.MosInterpreter,
dstManifest, refManifest *build.FWAppManifest, interp *interpreter.MosInterpreter, isAppManifest bool,
) error {
interp = interp.Copy()

Expand Down Expand Up @@ -1281,6 +1282,18 @@ func ExpandManifestConds(
}); err != nil {
return errors.Trace(err)
}
// Conds in app's manifest can override name, description and version.
if isAppManifest {
if cond.Apply.Name != "" {
dstManifest.Name = cond.Apply.Name
}
if cond.Apply.Description != "" {
dstManifest.Description = cond.Apply.Description
}
if cond.Apply.Version != "" {
dstManifest.Version = cond.Apply.Version
}
}
}
}

Expand Down
Expand Up @@ -11,4 +11,12 @@ filesystem:
config_schema:
- ["mylib1", "o", {title: "mylib1 settings"}]

conds:
- when: '"1" == "1"'
apply:
# Top-level attributes can only be overriden in app's conds
name: Does not
description: work
version: from here

manifest_version: 2017-09-29
Expand Up @@ -16,4 +16,11 @@ libs:
config_schema:
- ["myapp", "o", {title: "Myapp settings"}]

conds:
- when: '"1" == "1"'
apply:
name: Test app
description: Test app is best app
version: 1.2.3

manifest_version: 2017-09-29
@@ -1,10 +1,11 @@
name: Test app
type: app
version: "1.0"
version: 1.2.3
platform: esp32
platforms:
__ALL_PLATFORMS__
author: mongoose-os
description: My test app
description: Test app is best app
sources:
- __APP_ROOT__/app/build/gen/mgos_deps_init.c
- __APP_ROOT__/libs/mylib1/src/mylib1_src1.c
Expand Down
@@ -1,10 +1,11 @@
name: Test app
type: app
version: "1.0"
version: 1.2.3
platform: esp8266
platforms:
__ALL_PLATFORMS__
author: mongoose-os
description: My test app
description: Test app is best app
sources:
- __APP_ROOT__/app/build/gen/mgos_deps_init.c
- __APP_ROOT__/libs/mylib1/src/mylib1_src1.c
Expand Down

0 comments on commit bb2f974

Please sign in to comment.