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
14 changes: 8 additions & 6 deletions interpreters/berry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
# ##############################################################################

if(CONFIG_INTERPRETERS_BERRY)
find_package(
Python3
COMPONENTS Interpreter
REQUIRED)

set(BERRY_COMMIT_ID 4db341475df9e9ad18e6741ef978b4c467690e09)
set(BERRY_DIR ${CMAKE_CURRENT_LIST_DIR}/berry)

Expand All @@ -33,7 +38,9 @@ if(CONFIG_INTERPRETERS_BERRY)
${CMAKE_CURRENT_LIST_DIR}/berry BINARY_DIR
${CMAKE_BINARY_DIR}/apps/interpreters/berry/berry
PATCH_COMMAND
patch -l -p1 -d ${CMAKE_CURRENT_LIST_DIR}/berry -i
${Python3_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/tools/fix-crlf.py
${CMAKE_CURRENT_LIST_DIR}/berry/default/berry.c COMMAND patch -l -p1 -d
${CMAKE_CURRENT_LIST_DIR}/berry -i
${CMAKE_CURRENT_LIST_DIR}/0001-Fix-Berry-default-port-for-NuttX.patch
DOWNLOAD_NO_PROGRESS true
TIMEOUT 30)
Expand All @@ -45,11 +52,6 @@ if(CONFIG_INTERPRETERS_BERRY)
endif()
endif()

find_package(
Python3
COMPONENTS Interpreter
REQUIRED)

set(BERRY_CONFIG_DIR ${CMAKE_CURRENT_LIST_DIR}/include)
set(BERRY_CONFIG ${BERRY_CONFIG_DIR}/berry_conf.h)
set(BERRY_GENERATE ${BERRY_DIR}/generate)
Expand Down
3 changes: 3 additions & 0 deletions interpreters/berry/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ BERRY_URL_BASE = https://github.com/berry-lang/berry/archive/
BERRY_URL = $(BERRY_URL_BASE)/$(BERRY_COMMIT_ID).zip
BERRY_CONFIG = include$(DELIM)berry_conf.h
BERRY_COC = $(BERRY_UNPACK)$(DELIM)tools$(DELIM)coc$(DELIM)coc
BERRY_FIX_CRLF = tools$(DELIM)fix-crlf.py
BERRY_GENERATE = $(BERRY_UNPACK)$(DELIM)generate
BERRY_GEN_STAMP = $(BERRY_GENERATE)$(DELIM).generated
BERRY_MAIN = $(BERRY_UNPACK)$(DELIM)default$(DELIM)berry.c

BERRY_SRCS = be_api.c be_baselib.c be_bytecode.c be_byteslib.c
BERRY_SRCS += be_class.c be_code.c be_debug.c be_debuglib.c be_exec.c
Expand Down Expand Up @@ -71,6 +73,7 @@ $(BERRY_UNPACK): $(BERRY_ARCHIVE)
$(Q) unzip -q -o $(BERRY_ARCHIVE)
$(call DELDIR, $(BERRY_UNPACK))
$(Q) mv berry-$(BERRY_COMMIT_ID) $(BERRY_UNPACK)
$(Q) python3 $(BERRY_FIX_CRLF) $(BERRY_MAIN)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but why not patch to \r\n version, or upstream the patch (convert '\r\n' to '\n' in berry.c) to the community.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already upstreamed the Berry-side change here: berry-lang/berry#539. That PR is approved, but it has not been merged yet.

For this NuttX apps PR, I normalized the downloaded default/berry.c before applying the existing patch because the current pinned Berry archive still contains CRLF line endings, while the NuttX patch is LF. This keeps the patch file in the normal NuttX text format and makes both Make and CMake fetch paths apply it reliably.

If you prefer, I can switch this PR to a CRLF-formatted patch instead. Once berry-lang/berry#539 is merged, I can also update the pinned Berry commit and remove the local NuttX patch entirely.

@cederom cederom Jun 29, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be best to point to a release otherwise not much difference, i would stick to fixed upstream, let @xiaoxiang781216 decide :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's patch the origin code on '\r\n' version and merge it first. Once berry-lang/berry#539 is merged, we can create a new pr to drop the local patch.

$(Q) patch -l -d $(BERRY_UNPACK) -p1 < 0001-Fix-Berry-default-port-for-NuttX.patch

$(BERRY_GEN_STAMP): $(BERRY_UNPACK) $(BERRY_CONFIG)
Expand Down
35 changes: 35 additions & 0 deletions interpreters/berry/tools/fix-crlf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
############################################################################
# apps/interpreters/berry/tools/fix-crlf.py
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

import sys
from pathlib import Path


def main():
for filename in sys.argv[1:]:
path = Path(filename)
path.write_bytes(path.read_bytes().replace(b"\r\n", b"\n"))


if __name__ == "__main__":
main()
Loading