From bb2f97428f0d9c56ed6c9d0b35c9f145aa85e30c Mon Sep 17 00:00:00 2001 From: "Deomid \"rojer\" Ryabkov" Date: Wed, 29 Jan 2020 01:33:15 +0000 Subject: [PATCH] Override app name, description and version from app's conds --- cli/build_remote.go | 6 ++--- cli/manifest_parser/manifest_parser.go | 23 +++++++++++++++---- .../libs_common/mylib1/mos.yml | 8 +++++++ .../test_01_app_doesnt_override/app/mos.yml | 7 ++++++ .../expected/esp32/mos_final.yml | 5 ++-- .../expected/esp8266/mos_final.yml | 5 ++-- 6 files changed, 42 insertions(+), 12 deletions(-) diff --git a/cli/build_remote.go b/cli/build_remote.go index 6f408002..7b98ae71 100644 --- a/cli/build_remote.go +++ b/cli/build_remote.go @@ -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" @@ -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" ) @@ -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) } diff --git a/cli/manifest_parser/manifest_parser.go b/cli/manifest_parser/manifest_parser.go index 2eaffa18..e702521a 100644 --- a/cli/manifest_parser/manifest_parser.go +++ b/cli/manifest_parser/manifest_parser.go @@ -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" @@ -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) } @@ -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 { @@ -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 { @@ -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() @@ -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 + } + } } } diff --git a/cli/manifest_parser/test_manifests/testset_02_conds_switch_without_arch_manifests/libs_common/mylib1/mos.yml b/cli/manifest_parser/test_manifests/testset_02_conds_switch_without_arch_manifests/libs_common/mylib1/mos.yml index 78e7a358..30b34ea7 100644 --- a/cli/manifest_parser/test_manifests/testset_02_conds_switch_without_arch_manifests/libs_common/mylib1/mos.yml +++ b/cli/manifest_parser/test_manifests/testset_02_conds_switch_without_arch_manifests/libs_common/mylib1/mos.yml @@ -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 diff --git a/cli/manifest_parser/test_manifests/testset_02_conds_switch_without_arch_manifests/test_01_app_doesnt_override/app/mos.yml b/cli/manifest_parser/test_manifests/testset_02_conds_switch_without_arch_manifests/test_01_app_doesnt_override/app/mos.yml index a99b0d0e..30a84c85 100644 --- a/cli/manifest_parser/test_manifests/testset_02_conds_switch_without_arch_manifests/test_01_app_doesnt_override/app/mos.yml +++ b/cli/manifest_parser/test_manifests/testset_02_conds_switch_without_arch_manifests/test_01_app_doesnt_override/app/mos.yml @@ -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 diff --git a/cli/manifest_parser/test_manifests/testset_02_conds_switch_without_arch_manifests/test_01_app_doesnt_override/expected/esp32/mos_final.yml b/cli/manifest_parser/test_manifests/testset_02_conds_switch_without_arch_manifests/test_01_app_doesnt_override/expected/esp32/mos_final.yml index 3ac089ac..7df6ffd6 100644 --- a/cli/manifest_parser/test_manifests/testset_02_conds_switch_without_arch_manifests/test_01_app_doesnt_override/expected/esp32/mos_final.yml +++ b/cli/manifest_parser/test_manifests/testset_02_conds_switch_without_arch_manifests/test_01_app_doesnt_override/expected/esp32/mos_final.yml @@ -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 diff --git a/cli/manifest_parser/test_manifests/testset_02_conds_switch_without_arch_manifests/test_01_app_doesnt_override/expected/esp8266/mos_final.yml b/cli/manifest_parser/test_manifests/testset_02_conds_switch_without_arch_manifests/test_01_app_doesnt_override/expected/esp8266/mos_final.yml index 1bbb8513..76621bcc 100644 --- a/cli/manifest_parser/test_manifests/testset_02_conds_switch_without_arch_manifests/test_01_app_doesnt_override/expected/esp8266/mos_final.yml +++ b/cli/manifest_parser/test_manifests/testset_02_conds_switch_without_arch_manifests/test_01_app_doesnt_override/expected/esp8266/mos_final.yml @@ -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