Skip to content

Commit

Permalink
Fix Windows use
Browse files Browse the repository at this point in the history
Generate `kconfig.in` file using cfgtool, fix paths as required
(e.g. "/s/path/to" -> "s:/path/to")
  • Loading branch information
mikee47 committed Sep 28, 2021
1 parent 1b2a2f8 commit 1f1180f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
14 changes: 5 additions & 9 deletions Sming/project.mk
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,10 @@ endif
##@Configuration

export UNAME
export KCONFIG_COMPONENTS=$(OUT_BASE)/kconfig.in
# List of all Kconfig files
export KCONFIG_FILES = $(wildcard $(foreach c,$(filter-out Sming,$(COMPONENTS)),$(CMP_$c_PATH)/Kconfig))
# File containing list of component Kconfig file paths (created by cfgtool)
export KCONFIG_COMPONENTS = $(OUT_BASE)/kconfig.in

KCONFIG := $(SMING_HOME)/Kconfig
KCONFIG_CONFIG := $(OUT_BASE)/kconfig.config
Expand All @@ -686,17 +689,10 @@ KCONFIG_ENV := \
KCONFIG=$(KCONFIG) \
KCONFIG_CONFIG=$(KCONFIG_CONFIG)

KCONFIG_FILES = $(wildcard $(foreach c,$(filter-out Sming,$(COMPONENTS)),$(CMP_$c_PATH)/Kconfig))

CFGTOOL_CMDLINE = $(KCONFIG_ENV) $(PYTHON) $(SMING_TOOLS)/cfgtool.py $(CONFIG_CACHE_FILE)

.PHONY: build_kconfig_components
build_kconfig_components:
@echo > $(KCONFIG_COMPONENTS)
@$(foreach f,$(KCONFIG_FILES),echo 'source "$f"' >> $(KCONFIG_COMPONENTS);)

.PHONY: menuconfig
menuconfig: build_kconfig_components ##Run option editor
menuconfig: ##Run option editor
$(Q) $(CFGTOOL_CMDLINE) --to-kconfig
$(Q) $(KCONFIG_ENV) $(PYTHON) -m menuconfig $(SMING_HOME)/Kconfig
$(Q) $(CFGTOOL_CMDLINE) --from-kconfig
23 changes: 21 additions & 2 deletions Tools/cfgtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
#

import argparse, configparser, os, sys, kconfiglib
import argparse, configparser, os, sys, platform, kconfiglib


def load_config_vars(filename):
Expand Down Expand Up @@ -41,6 +41,22 @@ def set_kconfig_value(symbol, v):
cond.set_value('y')
break


def fixpath(path):
"""Paths in Windows can get a little weird"""
if len(path) > 2 and path[1] != ':' and platform.system() == 'Windows' and path[2] == '/':
return path[1] + ':' + path[2:]
return path


def createComponentsFile():
fileList = os.environ['KCONFIG_FILES'].split()
compFile = os.environ['KCONFIG_COMPONENTS']
with open(compFile, "w") as f:
for s in fileList:
f.write('source "%s"\n' % fixpath(s))


def main():
parser = argparse.ArgumentParser(description='Sming configuration management tool')
parser.add_argument('--to-kconfig', help="Convert Sming configuration to Kconfig format", action='store_true')
Expand All @@ -49,15 +65,18 @@ def main():

args = parser.parse_args()

conf = kconfiglib.Kconfig(os.environ['KCONFIG'])
if args.to_kconfig:
createComponentsFile()

conf = kconfiglib.Kconfig(os.environ['KCONFIG'])
src = load_config_vars(args.config_file)
for k, v in src.items():
c = conf.syms.get(k)
if c:
set_kconfig_value(c, v)
conf.write_config(os.environ['KCONFIG_CONFIG'])
elif args.from_kconfig:
conf = kconfiglib.Kconfig(os.environ['KCONFIG'])
conf.load_config(os.environ['KCONFIG_CONFIG'])
dst = load_config_vars(args.config_file)
varnames = set(dst.pop('CACHED_VAR_NAMES').split())
Expand Down

0 comments on commit 1f1180f

Please sign in to comment.