Skip to content

Commit

Permalink
Make lf-build a bit more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
erlingrj committed Jan 26, 2023
1 parent 288b478 commit cbec8a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ application/bin
application/build

scripts/__pycache__
build/

deps/
24 changes: 14 additions & 10 deletions scripts/lf_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ def do_add_parser(self, parser_adder):
return parser # gets stored as self.parser

def do_run(self, args, unknown_args):
# FIXME: The problem is that we dont control where the output of lfc is
# routed. This is a hack and it doesnt work if the LF program is e.g. at app/src/more_dirs/HelloWorld.lf.

if "src" not in args.main_lf.split("/"):
print("ERROR: West lf-build must be invoked outside `src` folder")

srcGenPath = args.main_lf.split(".")[0].replace("src", "src-gen")
appPath = args.main_lf.split("src")[0]

# 1. Invoke lfc with clean flag `-c` and without invoking target
# compiler `n`.
Expand All @@ -49,27 +52,28 @@ def do_run(self, args, unknown_args):
if ret != 0:
exit(1)

# FIXME: This is a not-intuitive limitation from the users prespective.
# But we use `-DOVERLAY_CONFIG` to mix in the prj.conf from the app
# directory with the prj_lf.conf in the `src-gen`
if not args.west_commands:
args.west_commands = ""

# FIXME: This is a not-intuitive limitation from the users prespective.
# But we use `-DOVERLAY_CONFIG` to mix in the prj.conf from the app
# directory with the prj_lf.conf in the `src-gen`
if "-DOVERLAY_CONFIG" in args.west_commands:
print("Error: Use `--conf-overlays` option to pass config overlays to west")

# Add config overlays
userConfigPaths="../../prj.conf"
# Copy project configurations into src-gen
userConfigPaths="prj.conf"
res = subprocess.Popen(f"cp {appPath}/prj.conf {srcGenPath}/", shell=True)
if args.conf_overlays:
userConfigPaths += f";../../{args.conf_overlays}"
res = subprocess.Popen(f"cp {appPath}/{args.conf_overlays} {srcGenPath}/", shell=True)
userConfigPaths += f";{args.conf_overlays}"

# Copy the Kconfig file into the src-gen directory
res = subprocess.Popen(f"cp Kconfig {srcGenPath}/", shell=True)
res = subprocess.Popen(f"cp {appPath}/Kconfig {srcGenPath}/", shell=True)
ret = res.wait()
if ret != 0:
exit(1)


# Invoke west in the `src-gen` directory. Pass in
westCmd = f"west build {srcGenPath} {args.west_commands} -- -DOVERLAY_CONFIG=\"{userConfigPaths}\""
print(f"Executing west command: `{westCmd}`")
Expand Down

0 comments on commit cbec8a4

Please sign in to comment.