Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/newt_sysinit/override_fail/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Error: Invalid sysinit definitions detected:
Missing pkg.init functions in target.yml:
ble_store_config_init
ble_transport_hs_init

18 changes: 18 additions & 0 deletions .github/newt_sysinit/override_success/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Brief sysinit config for targets/sysinit_override_success:
STAGE | PACKAGE | FUNCTION | SETTING
---------+---------------------------------------------------+-------------------------+------------------------
10 | @apache-mynewt-nimble/nimble/transport | ble_transport_ll_init |
11 | @apache-mynewt-nimble/nimble/host/services/gatt | ble_svc_gatt_init |
12 | @apache-mynewt-core/sys/stats/full | stats_module_init |
100 | @apache-mynewt-core/sys/log/modlog | modlog_init | MODLOG_SYSINIT_STAGE
101 | @apache-mynewt-nimble/nimble/host/store/config | ble_store_config_init |
102 | @apache-mynewt-nimble/nimble/transport | ble_transport_hs_init |
200 | @apache-mynewt-core/sys/shell | shell_init |
201 | @apache-mynewt-nimble/nimble/controller | ble_ll_init |
202 | @apache-mynewt-nimble/nimble/transport | ble_transport_init |
300 | @apache-mynewt-nimble/nimble/host/services/ans | ble_svc_ans_init |
400 | @apache-mynewt-nimble/nimble/host/services/gap | ble_svc_gap_init |
401 | @apache-mynewt-core/sys/flash_map | flash_map_init |
402 | @apache-mynewt-core/sys/log/full | log_init |
403 | @apache-mynewt-core/sys/console/full | console_pkg_init |
404 | @apache-mynewt-core/kernel/os | os_pkg_init |
5 changes: 5 additions & 0 deletions .github/targets/sysinit_override_fail/pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pkg.name: "targets/sysinit_override_fail"
pkg.type: target
pkg.description:
pkg.author:
pkg.homepage:
24 changes: 24 additions & 0 deletions .github/targets/sysinit_override_fail/target.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
target.app: "@apache-mynewt-nimble/apps/btshell"
target.bsp: "@apache-mynewt-core/hw/bsp/nordic_pca10056"
target.build_profile: optimized

pkg.init:
ble_transport_ll_init: 10
ble_svc_gatt_init: 11
stats_module_init: 12
modlog_init: MYNEWT_VAL(MODLOG_SYSINIT_STAGE)
shell_init: 200
ble_ll_init: 201
ble_transport_init: 202

ble_svc_ans_init: 300
ble_svc_gap_init: 400
flash_map_init: 401
log_init: 402
console_pkg_init: 403
os_pkg_init: 404

# Redundant init functions shall be ignored
dummy_1: 1
dummy_2: 205
dummy_3: 500
5 changes: 5 additions & 0 deletions .github/targets/sysinit_override_success/pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pkg.name: "targets/sysinit_override_success"
pkg.type: target
pkg.description:
pkg.author:
pkg.homepage:
26 changes: 26 additions & 0 deletions .github/targets/sysinit_override_success/target.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
target.app: "@apache-mynewt-nimble/apps/btshell"
target.bsp: "@apache-mynewt-core/hw/bsp/nordic_pca10056"
target.build_profile: optimized

pkg.init:
ble_transport_ll_init: 10
ble_svc_gatt_init: 11
stats_module_init: 12
modlog_init: MYNEWT_VAL(MODLOG_SYSINIT_STAGE)
ble_store_config_init: 101
ble_transport_hs_init: 102
shell_init: 200
ble_ll_init: 201
ble_transport_init: 202

ble_svc_ans_init: 300
ble_svc_gap_init: 400
flash_map_init: 401
log_init: 402
console_pkg_init: 403
os_pkg_init: 404

# Redundant init functions shall be ignored
dummy_1: 1
dummy_2: 205
dummy_3: 500
21 changes: 20 additions & 1 deletion .github/workflows/test_sysinit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,23 @@ jobs:
newt upgrade -v --escape=false apache-mynewt-core apache-mynewt-nimble
newt info
newt target sysinit brief nordic_pca10056_btshell > tmp.txt
diff -w tmp.txt ../.github/newt_sysinit/expected.txt
diff -w tmp.txt ../.github/newt_sysinit/brief/expected.txt
- name: Test_sysinit_override (success)
shell: bash
run: |
cp -r .github/targets/sysinit_override_success project/targets
cd project/
newt upgrade -v --escape=false apache-mynewt-core apache-mynewt-nimble
newt info
newt build sysinit_override_success
newt target sysinit brief sysinit_override_success > tmp.txt
diff -w tmp.txt ../.github/newt_sysinit/override_success/expected.txt
- name: Test_sysinit_override (fail)
shell: bash
run: |
cp -r .github/targets/sysinit_override_fail project/targets
cd project/
newt upgrade -v --escape=false apache-mynewt-core apache-mynewt-nimble
newt info
newt build sysinit_override_fail 2> tmp.txt || true
diff -w tmp.txt ../.github/newt_sysinit/override_fail/expected.txt
5 changes: 3 additions & 2 deletions newt/builder/targetbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import (
"bufio"
"fmt"
"io/ioutil"
"mynewt.apache.org/newt/newt/cfgv"
"os"
"path/filepath"
"sort"
"strings"

"mynewt.apache.org/newt/newt/cfgv"

log "github.com/sirupsen/logrus"

"github.com/apache/mynewt-artifact/flash"
Expand Down Expand Up @@ -240,7 +241,7 @@ func (t *TargetBuilder) ensureResolved(detectErr bool) error {

var err error
t.res, err = resolve.ResolveFull(
loaderSeeds, appSeeds, t.injectedSettings, t.bspPkg.FlashMap, detectErr)
loaderSeeds, appSeeds, t.injectedSettings, t.bspPkg.FlashMap, t.target.TargetY, detectErr)
if err != nil {
return err
}
Expand Down
11 changes: 7 additions & 4 deletions newt/resolve/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ package resolve

import (
"fmt"
"mynewt.apache.org/newt/newt/cfgv"
"sort"
"strings"

"mynewt.apache.org/newt/newt/cfgv"
"mynewt.apache.org/newt/newt/ycfg"

log "github.com/sirupsen/logrus"

"mynewt.apache.org/newt/newt/extcmd"
Expand Down Expand Up @@ -1026,7 +1028,7 @@ func (r *Resolver) resolveDeps() ([]*ResolvePackage, error) {
// 1. Calculates the system configuration (syscfg).
// 2. Determines which packages satisfy which API requirements.
// 3. Resolves package dependencies by populating the resolver's package map.
func (r *Resolver) resolveDepsAndCfg() error {
func (r *Resolver) resolveDepsAndCfg(targetCfg ycfg.YCfg) error {
if err := r.resolveHardDeps(); err != nil {
return err
}
Expand Down Expand Up @@ -1071,7 +1073,7 @@ func (r *Resolver) resolveDepsAndCfg() error {

lpkgs := RpkgSliceToLpkgSlice(r.rpkgSlice())
r.lcfg = logcfg.Read(lpkgs, &r.cfg)
r.sysinitCfg = sysinit.Read(lpkgs, &r.cfg)
r.sysinitCfg = sysinit.Read(lpkgs, &r.cfg, targetCfg)
r.sysdownCfg = sysdown.Read(lpkgs, &r.cfg)

r.preBuildCmdCfg = extcmd.Read("pre_build_cmds", lpkgs, &r.cfg,
Expand Down Expand Up @@ -1169,6 +1171,7 @@ func ResolveFull(
appSeeds []*pkg.LocalPackage,
injectedSettings *cfgv.Settings,
flashMap flashmap.FlashMap,
targetCfg ycfg.YCfg,
detectErr bool) (*Resolution, error) {

// First, calculate syscfg and determine which package provides each
Expand All @@ -1180,7 +1183,7 @@ func ResolveFull(
allSeeds := append(loaderSeeds, appSeeds...)
r := newResolver(allSeeds, injectedSettings, flashMap)

if err := r.resolveDepsAndCfg(); err != nil {
if err := r.resolveDepsAndCfg(targetCfg); err != nil {
return nil, err
}

Expand Down
69 changes: 64 additions & 5 deletions newt/sysinit/sysinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ package sysinit
import (
"bytes"
"fmt"
"github.com/spf13/cast"
"io"
"mynewt.apache.org/newt/util"
"sort"
"strings"

"github.com/spf13/cast"
"mynewt.apache.org/newt/newt/ycfg"
"mynewt.apache.org/newt/util"

"mynewt.apache.org/newt/newt/newtutil"
"mynewt.apache.org/newt/newt/pkg"
"mynewt.apache.org/newt/newt/stage"
Expand Down Expand Up @@ -169,7 +171,7 @@ func ResolveStageFuncsOrder(sfs []stage.StageFunc) ([]stage.StageFunc, error) {
}
return true
})

// Put nodes without stages first, so they are resolved and put to
// stack first - we do not want them to precede all nodes with stages.
// While technically correct, it's better not to start sysinit with
Expand Down Expand Up @@ -233,7 +235,51 @@ func ResolveStageFuncsOrder(sfs []stage.StageFunc) ([]stage.StageFunc, error) {
return sfs, nil
}

func Read(lpkgs []*pkg.LocalPackage, cfg *syscfg.Cfg) SysinitCfg {
func getTargetStageFuncs(tCfg ycfg.YCfg, cfg *syscfg.Cfg) ([]stage.StageFunc, error) {
initMap, _ := tCfg.GetValStringMap("pkg.init", nil)
var sfs []stage.StageFunc

for name, stageDef := range initMap {
stageStr := cast.ToString(stageDef)
sf, err := stage.NewStageFunc(name, stageStr, nil, cfg)
if err != nil {
return nil, err
}

sfs = append(sfs, sf)
}

return sfs, nil
}

func targetStageFuncsOverride(tStageFuncs []stage.StageFunc, pStageFuncs []stage.StageFunc) error {
indexByName := make(map[string]int, len(pStageFuncs))

for i := range pStageFuncs {
indexByName[pStageFuncs[i].Name] = i
}

for _, tSF := range tStageFuncs {
if idx, ok := indexByName[tSF.Name]; ok {
pStageFuncs[idx].Stage = tSF.Stage
delete(indexByName, tSF.Name)
}
}

missing := make([]string, 0, len(indexByName))
for name := range indexByName {
missing = append(missing, name)
}

if len(missing) != 0 {
sort.Strings(missing)
return util.NewNewtError("Missing pkg.init functions in target.yml:\n\t" + strings.Join(missing, "\n\t"))
}

return nil
}

func Read(lpkgs []*pkg.LocalPackage, cfg *syscfg.Cfg, tCfg ycfg.YCfg) SysinitCfg {
scfg := SysinitCfg{
Conflicts: map[string][]stage.StageFunc{},
}
Expand All @@ -242,6 +288,20 @@ func Read(lpkgs []*pkg.LocalPackage, cfg *syscfg.Cfg) SysinitCfg {
scfg.readOnePkg(lpkg, cfg)
}

tStageFuncs, err := getTargetStageFuncs(tCfg, cfg)
if err != nil {
scfg.InvalidSettings = append(scfg.InvalidSettings, err.Error())
return scfg
}

if tStageFuncs != nil {
err := targetStageFuncsOverride(tStageFuncs, scfg.StageFuncs)
if err != nil {
scfg.InvalidSettings = append(scfg.InvalidSettings, err.Error())
return scfg
}
}

scfg.detectConflicts()

// Don't try to resolve order if there are name conflicts since that
Expand All @@ -251,7 +311,6 @@ func Read(lpkgs []*pkg.LocalPackage, cfg *syscfg.Cfg) SysinitCfg {
return scfg
}

var err error
scfg.StageFuncs, err = ResolveStageFuncsOrder(scfg.StageFuncs)
if err != nil {
scfg.InvalidSettings = append(scfg.InvalidSettings, err.Error())
Expand Down
Loading