You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "raiden00pl (via GitHub)" <gi...@apache.org> on 2023/07/11 11:42:17 UTC
[GitHub] [nuttx] raiden00pl opened a new pull request, #9782: tools: add a convert tool to help migrate from make to cmake
raiden00pl opened a new pull request, #9782:
URL: https://github.com/apache/nuttx/pull/9782
## Summary
A simple tool that convert arch/board makefiles to cmake files. Tested with stm32, don't know if it'll work with other architectures.
It's a really dumb not finished tool that is not ready for upstream so I keep it as a draft.
Maybe someone will find it useful. The results usually require minor manual adjustments, but this makes the job much easier.
Usage:
`python tools/nxmake2cmake.py arch/arm/src/stm32f0l0g0`
`python tools/nxmake2cmake.py boards/arm/stm32/nucleo-f302r8`
## Impact
## Testing
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] tools: add a convert tool to help migrate from make to cmake [nuttx]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on code in PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#discussion_r2047221301
##########
tools/nxmake2cmake.py:
##########
@@ -0,0 +1,239 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/nxmake2cmake.py
+#
+# 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 argparse
+import os
+import sys
+from string import Template
+
+if sys.version_info[0] < 3:
+ raise Exception("Must be using Python 3")
+
+
+def board_cmakelist_get(path):
+ template = """# ##############################################################################
+# $board_path/CMakeLists.txt
+#
+# 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.
+#
+# ##############################################################################
+
+add_subdirectory(src)
+"""
+ temp_obj = Template(template)
+ return temp_obj.substitute(board_path=path)
+
+
+def add_board_cmakelist(path):
+ cmpath = os.path.join(path, "CMakeLists.txt")
+
+ print("Add", cmpath)
+
+ with open(cmpath, "w") as f:
+ content = board_cmakelist_get(path)
+ content = board_cmakelist_get(path)
+ f.write(content)
+
+
+def file_update_path(s, oldpath, newpath):
+ return s.replace(oldpath, newpath)
+
+
+def convert_make_conditional(content):
+ content = content.replace(",y)", "")
+ content = content.replace("ifeq ($", "if")
+ content = content.replace("ifneq ($(", "if(NOT ")
+ content = content.replace("else", "else()")
+ content = content.replace("endif", "endif()")
+ content = content.replace("CHIP_CSRCS = ", "set(SRCS ")
+ content = content.replace("CHIP_CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace("CSRCS = ", "set(SRCS ")
+ content = content.replace("CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace(".c\n", ".c)\n")
+
+ return content
+
+
+# common for board Makefile and Make.defs
+def convert_board_common(path, content):
+ content = convert_make_conditional(content)
+
+ # remove make specific lines
+ content = "\n".join(line for line in content.split("\n") if "include" not in line)
+ content = "\n".join(line for line in content.split("\n") if "ASRCS" not in line)
+ content = "\n".join(line for line in content.split("\n") if "DEPPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "VPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "CFLAGS" not in line)
+
+ content += "target_sources(board PRIVATE ${SRCS})\n\n"
+
+ # linker script
+ if os.path.exists(os.path.join(path, "scripts/ld.script")):
+ content += 'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/ld.script")'
+ elif os.path.exists(os.path.join(path, "scripts/flash.ld")):
+ content += 'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/flash.ld")'
+ else:
+ print("ERROR: not found linker script")
+
+ content += "\n"
+ content = content.replace("\n\n\n", "\n\n")
+ content = content.replace("SRCS ", "SRCS ")
+
+ return content
+
+
+# convert board src/Make.defs to CMakeLists.txt
+def convert_board_makedefs(path):
+ mdpath = os.path.join(path, "src/Make.defs")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mdpath, "r") as fm:
+ content = fm.read()
+ content = content.replace(mdpath, cpath)
+ content = convert_board_common(path, content)
+
+ if content:
+ print("add", cpath)
+ with open(cpath, "w") as fc:
+ fc.write(content)
+
+
+# convert board src/Makefile to CMakeLists.txt
+def convert_board_makefile(path):
+ mpath = os.path.join(path, "src/Makefile")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mpath, "r") as fm:
+ content = fm.read()
+ content = content.replace(mpath, cpath)
+ content = convert_board_common(path, content)
+
+ if content:
+ print("add", cpath)
+ with open(cpath, "w") as fc:
+ fc.write(content)
+
+
+# convert board make build to cmake
+def convert_board(path):
+ add_board_cmakelist(path)
+
+ mpath = os.path.join(path, "src/Makefile")
+ mdpath = os.path.join(path, "src/Make.defs")
Review Comment:
Hi @raiden00pl sorry I was wrong !!!
Very useful tool !
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] raiden00pl commented on a diff in pull request #9782: tools: add a convert tool to help migrate from make to cmake
Posted by "raiden00pl (via GitHub)" <gi...@apache.org>.
raiden00pl commented on code in PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#discussion_r1259763325
##########
tools/nxmake2cmake.py:
##########
@@ -0,0 +1,219 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/nxmake2cmake.py
+#
+# 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 argparse
+import os
+from string import Template
+
+def board_cmakelist_get(path):
+ template ="""# ##############################################################################
+# $board_path/CMakeLists.txt
+#
+# 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.
+#
+# ##############################################################################
+
+add_subdirectory(src)
+"""
+ temp_obj = Template(template)
+ return temp_obj.substitute(board_path=path)
+
+def add_board_cmakelist(path):
+ cmpath = os.path.join(path, "CMakeLists.txt")
+
+ print("Add", cmpath)
+
+ with open(cmpath, 'w') as f:
+ content = board_cmakelist_get(path)
+ content = board_cmakelist_get(path)
+ f.write(content)
+
+def file_update_path(s, oldpath, newpath):
+ return s.replace(oldpath, newpath)
+
+def convert_make_conditional(content):
+ content = content.replace(",y)", "")
+ content = content.replace("ifeq ($", "if")
+ content = content.replace("ifneq ($(", "if(NOT ")
+ content = content.replace("else", "else()")
+ content = content.replace("endif", "endif()")
+ content = content.replace("CHIP_CSRCS = ", "set(SRCS ")
+ content = content.replace("CHIP_CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace("CSRCS = ", "set(SRCS ")
+ content = content.replace("CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace(".c\n", ".c)\n")
+
+ return content
+
+# common for board Makefile and Make.defs
+def convert_board_common(path, content):
+ content = convert_make_conditional(content)
+
+ # remove make specific lines
+ content = '\n'.join(line for line in content.split('\n') if 'include' not in line)
+ content = '\n'.join(line for line in content.split('\n') if 'ASRCS' not in line)
+ content = '\n'.join(line for line in content.split('\n') if 'DEPPATH' not in line)
+ content = '\n'.join(line for line in content.split('\n') if 'VPATH' not in line)
+ content = '\n'.join(line for line in content.split('\n') if 'CFLAGS' not in line)
+
+ content += "target_sources(board PRIVATE ${SRCS})\n\n"
+
+ # linker script
+ if os.path.exists(os.path.join(path, "scripts/ld.script")):
+ content += "set_property(GLOBAL PROPERTY LD_SCRIPT \"${NUTTX_BOARD_DIR}/scripts/ld.script\")"
+ elif os.path.exists(os.path.join(path, "scripts/flash.ld")):
+ content += "set_property(GLOBAL PROPERTY LD_SCRIPT \"${NUTTX_BOARD_DIR}/scripts/flash.ld\")"
+ else:
+ print("ERROR: not found linker script")
+
+ content += "\n"
+ content = content.replace("\n\n\n", "\n\n")
+ content = content.replace("SRCS ", "SRCS ")
+
+ return content
+
+# convert board src/Make.defs to CMakeLists.txt
+def convert_board_makedefs(path):
+ mdpath = os.path.join(path, "src/Make.defs")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mdpath, 'r') as fm:
+ content = fm.read()
+ content = content.replace(mdpath, cpath)
+ content = convert_board_common(path, content)
+
+ if content:
+ print ("add", cpath)
+ with open(cpath, 'w') as fc:
+ fc.write(content)
+
+# convert board src/Makefile to CMakeLists.txt
+def convert_board_makefile(path):
+ mpath = os.path.join(path, "src/Makefile")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mpath, 'r') as fm:
+ content = fm.read()
+ content = content.replace(mpath, cpath)
+ content = convert_board_common(path, content)
+
+ if content:
+ print ("add", cpath)
+ with open(cpath, 'w') as fc:
+ fc.write(content)
+
+# convert board make build to cmake
+def convert_board(path):
+ add_board_cmakelist(path)
+
+ mpath = os.path.join(path, "src/Makefile")
+ mdpath = os.path.join(path, "src/Make.defs")
+
+ if os.path.exists(mpath):
+ convert_board_makefile(path)
+
+ elif os.path.exists(mdpath):
+ convert_board_makedefs(path)
+ else:
+ print("board Makefile or Make.defs not found in ", path)
+ exit(1)
+
+# convert arch Make.defs cmake
+def convert_arch_makedefs(path):
+ mdpath = os.path.join(path, "Make.defs")
+ cpath = os.path.join(path, "CMakeLists.txt")
+
+ content = ""
+ with open(mdpath, 'r') as fm:
+ content = fm.read()
+ content = content.replace(mdpath, cpath)
+ content = convert_make_conditional(content)
+
+ content += "\n"
+
+ content += "target_sources(arch PRIVATE ${SRCS})\n"
+
+ content = '\n'.join(line for line in content.split('\n') if 'include' not in line)
+
+ content = content.replace("\n\n\n", "\n\n")
+ content = content.replace("SRCS ", "SRCS ")
+
+ if content:
+ print ("add", cpath)
+ with open(cpath, 'w') as fc:
+ fc.write(content)
+
+# convert arch make build to cmake
+def convert_arch(path):
+ convert_arch_makedefs(path)
+
+def main():
+ parser = argparse.ArgumentParser(
+ prog='nxmake2cmake',
+ description='convert NuttX makefile to cmake')
+
+ parser.add_argument("path",
+ type=str,
+ help="path to board or arch direcotry. eg. boards/arm/stm32f7/steval-eth001v1")
+
+ args = parser.parse_args()
+
+ if not os.path.exists(args.path):
+ print("invalid path", args.path)
+ exit(1)
+
+ path_split = args.path.split('/')
+
+ if "boards" in args.path:
+ if len(path_split) != 4 or not len(path_split[3]):
+ print("invalid board path")
+ exit(1)
+
+ convert_board(args.path)
+
+ elif "arch" in args.path:
+ if len(path_split) != 4 or not len(path_split[3]):
+ print("invalid arch path")
+ exit(1)
+
+ print("conver arch")
Review Comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] tools: add a convert tool to help migrate from make to cmake [nuttx]
Posted by "raiden00pl (via GitHub)" <gi...@apache.org>.
raiden00pl commented on code in PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#discussion_r2074895701
##########
tools/nxmake2cmake.py:
##########
@@ -0,0 +1,241 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/nxmake2cmake.py
+#
+# 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 argparse
+import os
+import sys
+from string import Template
+
+if sys.version_info[0] < 3:
+ raise Exception("Must be using Python 3")
+
+
+def board_cmakelist_get(path):
+ template = """# ##############################################################################
+# $board_path/CMakeLists.txt
+#
+# 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.
+#
+# ##############################################################################
+
+add_subdirectory(src)
+"""
+ temp_obj = Template(template)
+ return temp_obj.substitute(board_path=path)
+
+
+def add_board_cmakelist(path):
+ cmpath = os.path.join(path, "CMakeLists.txt")
+
+ print("Add", cmpath)
+
+ with open(cmpath, "w") as f:
+ content = board_cmakelist_get(path)
+ content = board_cmakelist_get(path)
+ f.write(content)
+
+
+def file_update_path(s, oldpath, newpath):
+ return s.replace(oldpath, newpath)
+
+
+def convert_make_conditional(content):
+ content = content.replace(",y)", "")
+ content = content.replace("ifeq ($", "if")
+ content = content.replace("ifneq ($(", "if(NOT ")
+ content = content.replace("else", "else()")
+ content = content.replace("endif", "endif()")
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] tools: add a convert tool to help migrate from make to cmake [nuttx]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on code in PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#discussion_r2307538965
##########
tools/nxmake2cmake.py:
##########
@@ -0,0 +1,281 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/nxmake2cmake.py
+#
+# 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.
+#
+############################################################################
+
+__version__ = "0.0.1"
+
+import argparse
+import os
+import sys
+from string import Template
+
+if sys.version_info[0] < 3:
+ raise Exception("Must be using Python 3")
+
+
+def board_cmakelist_get(path):
+ template = """# ##############################################################################
+# $board_path/CMakeLists.txt
+#
+# 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.
+#
+# ##############################################################################
+
+add_subdirectory(src)
+"""
+ temp_obj = Template(template)
+ return temp_obj.substitute(board_path=path)
+
+
+def add_board_cmakelist(path):
+ cmpath = os.path.join(path, "CMakeLists.txt")
+
+ print("Add", cmpath)
+
+ with open(cmpath, "w") as f:
+ content = board_cmakelist_get(path)
+ f.write(content)
+
+
+def file_update_path(s, oldpath, newpath):
+ return s.replace(oldpath, newpath)
+
+
+def convert_make_conditional(content):
+ content = content.replace(",y)", "")
+ content = content.replace("else ifeq ($", "elseif")
+ content = content.replace("ifeq ($", "if")
+ content = content.replace("ifneq ($(", "if(NOT ")
+ content = content.replace("else\n", "else()\n")
+ content = content.replace("endif\n", "endif()\n")
+ content = content.replace("CHIP_CSRCS = ", "set(SRCS ")
+ content = content.replace("CHIP_CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace("CSRCS = ", "set(SRCS ")
+ content = content.replace("CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace(".c\n", ".c)\n")
+
+ return content
+
+
+# common for board Makefile and Make.defs
+def convert_board_common(path, content):
+ content = convert_make_conditional(content)
+
+ # remove make specific lines
+ content = "\n".join(line for line in content.split("\n") if "include" not in line)
+ content = "\n".join(line for line in content.split("\n") if "ASRCS" not in line)
+ content = "\n".join(line for line in content.split("\n") if "DEPPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "VPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "CFLAGS" not in line)
+
+ content += "target_sources(board PRIVATE ${SRCS})\n\n"
+
+ count = 0
+ scriptpath = os.path.join(path, "scripts")
+ # linker script
+ for filename in os.listdir(scriptpath):
+ if filename.endswith(".ld") or filename.endswith(".script"):
+ print("found linker script ->", filename)
+ content += (
+ 'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/'
+ + filename
+ + '")\n'
+ )
+ count += 1
+ continue
+ else:
+ continue
+
+ if count == 0:
+ print("ERROR: not found linker script")
+
+ content += "\n"
+ content = content.replace("\n\n\n", "\n\n")
+ content = content.replace("SRCS ", "SRCS ")
+
+ return content
+
+
+# convert board src/Make.defs to CMakeLists.txt
+def convert_board_makedefs(path):
+ mdpath = os.path.join(path, "src/Make.defs")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mdpath, "r") as fm:
+ content = fm.read()
+ content = content.replace("src/Make.defs", "src/CMakeLists.txt")
+ content = convert_board_common(path, content)
+
+ if content:
+ print("add", cpath)
+ with open(cpath, "w") as fc:
+ fc.write(content)
+
+
+# convert board src/Makefile to CMakeLists.txt
+def convert_board_makefile(path):
+ mpath = os.path.join(path, "src/Makefile")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mpath, "r") as fm:
+ content = fm.read()
+ content = content.replace("src/Make.defs", "src/CMakeLists.txt")
Review Comment:
Make.defs -> Makefile
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] tools: add a convert tool to help migrate from make to cmake [nuttx]
Posted by "raiden00pl (via GitHub)" <gi...@apache.org>.
raiden00pl commented on code in PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#discussion_r2055436828
##########
tools/nxmake2cmake.py:
##########
@@ -0,0 +1,239 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/nxmake2cmake.py
+#
+# 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 argparse
+import os
+import sys
+from string import Template
+
+if sys.version_info[0] < 3:
+ raise Exception("Must be using Python 3")
+
+
+def board_cmakelist_get(path):
+ template = """# ##############################################################################
+# $board_path/CMakeLists.txt
+#
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] tools: add a convert tool to help migrate from make to cmake [nuttx]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on code in PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#discussion_r2068158264
##########
tools/nxmake2cmake.py:
##########
@@ -0,0 +1,241 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/nxmake2cmake.py
+#
+# 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 argparse
+import os
+import sys
+from string import Template
+
+if sys.version_info[0] < 3:
+ raise Exception("Must be using Python 3")
+
+
+def board_cmakelist_get(path):
+ template = """# ##############################################################################
+# $board_path/CMakeLists.txt
+#
+# 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.
+#
+# ##############################################################################
+
+add_subdirectory(src)
+"""
+ temp_obj = Template(template)
+ return temp_obj.substitute(board_path=path)
+
+
+def add_board_cmakelist(path):
+ cmpath = os.path.join(path, "CMakeLists.txt")
+
+ print("Add", cmpath)
+
+ with open(cmpath, "w") as f:
+ content = board_cmakelist_get(path)
+ content = board_cmakelist_get(path)
+ f.write(content)
+
+
+def file_update_path(s, oldpath, newpath):
+ return s.replace(oldpath, newpath)
+
+
+def convert_make_conditional(content):
+ content = content.replace(",y)", "")
+ content = content.replace("ifeq ($", "if")
+ content = content.replace("ifneq ($(", "if(NOT ")
+ content = content.replace("else", "else()")
+ content = content.replace("endif", "endif()")
Review Comment:
```
content = content.replace("else ifeq ($", "elseif")
content = content.replace("ifeq ($", "if")
content = content.replace("ifneq ($(", "if(NOT ")
```
added “else ifeq”
```
content = content.replace("else\n", "else()\n")
content = content.replace("endif\n", "endif()\n")
```
Need to add \n to not replace “else ifeq”
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] lucasssvaz commented on a diff in pull request #9782: tools: add a convert tool to help migrate from make to cmake
Posted by "lucasssvaz (via GitHub)" <gi...@apache.org>.
lucasssvaz commented on code in PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#discussion_r1259733983
##########
tools/nxmake2cmake.py:
##########
@@ -0,0 +1,219 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/nxmake2cmake.py
+#
+# 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 argparse
+import os
+from string import Template
+
+def board_cmakelist_get(path):
+ template ="""# ##############################################################################
+# $board_path/CMakeLists.txt
+#
+# 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.
+#
+# ##############################################################################
+
+add_subdirectory(src)
+"""
+ temp_obj = Template(template)
+ return temp_obj.substitute(board_path=path)
+
+def add_board_cmakelist(path):
+ cmpath = os.path.join(path, "CMakeLists.txt")
+
+ print("Add", cmpath)
+
+ with open(cmpath, 'w') as f:
+ content = board_cmakelist_get(path)
+ content = board_cmakelist_get(path)
+ f.write(content)
+
+def file_update_path(s, oldpath, newpath):
+ return s.replace(oldpath, newpath)
+
+def convert_make_conditional(content):
+ content = content.replace(",y)", "")
+ content = content.replace("ifeq ($", "if")
+ content = content.replace("ifneq ($(", "if(NOT ")
+ content = content.replace("else", "else()")
+ content = content.replace("endif", "endif()")
+ content = content.replace("CHIP_CSRCS = ", "set(SRCS ")
+ content = content.replace("CHIP_CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace("CSRCS = ", "set(SRCS ")
+ content = content.replace("CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace(".c\n", ".c)\n")
+
+ return content
+
+# common for board Makefile and Make.defs
+def convert_board_common(path, content):
+ content = convert_make_conditional(content)
+
+ # remove make specific lines
+ content = '\n'.join(line for line in content.split('\n') if 'include' not in line)
+ content = '\n'.join(line for line in content.split('\n') if 'ASRCS' not in line)
+ content = '\n'.join(line for line in content.split('\n') if 'DEPPATH' not in line)
+ content = '\n'.join(line for line in content.split('\n') if 'VPATH' not in line)
+ content = '\n'.join(line for line in content.split('\n') if 'CFLAGS' not in line)
+
+ content += "target_sources(board PRIVATE ${SRCS})\n\n"
+
+ # linker script
+ if os.path.exists(os.path.join(path, "scripts/ld.script")):
+ content += "set_property(GLOBAL PROPERTY LD_SCRIPT \"${NUTTX_BOARD_DIR}/scripts/ld.script\")"
+ elif os.path.exists(os.path.join(path, "scripts/flash.ld")):
+ content += "set_property(GLOBAL PROPERTY LD_SCRIPT \"${NUTTX_BOARD_DIR}/scripts/flash.ld\")"
+ else:
+ print("ERROR: not found linker script")
+
+ content += "\n"
+ content = content.replace("\n\n\n", "\n\n")
+ content = content.replace("SRCS ", "SRCS ")
+
+ return content
+
+# convert board src/Make.defs to CMakeLists.txt
+def convert_board_makedefs(path):
+ mdpath = os.path.join(path, "src/Make.defs")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mdpath, 'r') as fm:
+ content = fm.read()
+ content = content.replace(mdpath, cpath)
+ content = convert_board_common(path, content)
+
+ if content:
+ print ("add", cpath)
+ with open(cpath, 'w') as fc:
+ fc.write(content)
+
+# convert board src/Makefile to CMakeLists.txt
+def convert_board_makefile(path):
+ mpath = os.path.join(path, "src/Makefile")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mpath, 'r') as fm:
+ content = fm.read()
+ content = content.replace(mpath, cpath)
+ content = convert_board_common(path, content)
+
+ if content:
+ print ("add", cpath)
+ with open(cpath, 'w') as fc:
+ fc.write(content)
+
+# convert board make build to cmake
+def convert_board(path):
+ add_board_cmakelist(path)
+
+ mpath = os.path.join(path, "src/Makefile")
+ mdpath = os.path.join(path, "src/Make.defs")
+
+ if os.path.exists(mpath):
+ convert_board_makefile(path)
+
+ elif os.path.exists(mdpath):
+ convert_board_makedefs(path)
+ else:
+ print("board Makefile or Make.defs not found in ", path)
+ exit(1)
+
+# convert arch Make.defs cmake
+def convert_arch_makedefs(path):
+ mdpath = os.path.join(path, "Make.defs")
+ cpath = os.path.join(path, "CMakeLists.txt")
+
+ content = ""
+ with open(mdpath, 'r') as fm:
+ content = fm.read()
+ content = content.replace(mdpath, cpath)
+ content = convert_make_conditional(content)
+
+ content += "\n"
+
+ content += "target_sources(arch PRIVATE ${SRCS})\n"
+
+ content = '\n'.join(line for line in content.split('\n') if 'include' not in line)
+
+ content = content.replace("\n\n\n", "\n\n")
+ content = content.replace("SRCS ", "SRCS ")
+
+ if content:
+ print ("add", cpath)
+ with open(cpath, 'w') as fc:
+ fc.write(content)
+
+# convert arch make build to cmake
+def convert_arch(path):
+ convert_arch_makedefs(path)
+
+def main():
+ parser = argparse.ArgumentParser(
+ prog='nxmake2cmake',
+ description='convert NuttX makefile to cmake')
+
+ parser.add_argument("path",
+ type=str,
+ help="path to board or arch direcotry. eg. boards/arm/stm32f7/steval-eth001v1")
+
+ args = parser.parse_args()
+
+ if not os.path.exists(args.path):
+ print("invalid path", args.path)
+ exit(1)
+
+ path_split = args.path.split('/')
+
+ if "boards" in args.path:
+ if len(path_split) != 4 or not len(path_split[3]):
+ print("invalid board path")
+ exit(1)
+
+ convert_board(args.path)
+
+ elif "arch" in args.path:
+ if len(path_split) != 4 or not len(path_split[3]):
+ print("invalid arch path")
+ exit(1)
+
+ print("conver arch")
Review Comment:
```suggestion
print("convert arch")
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] tools: add a convert tool to help migrate from make to cmake [nuttx]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on code in PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#discussion_r2047231522
##########
tools/nxmake2cmake.py:
##########
@@ -0,0 +1,239 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/nxmake2cmake.py
+#
+# 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 argparse
+import os
+import sys
+from string import Template
+
+if sys.version_info[0] < 3:
+ raise Exception("Must be using Python 3")
+
+
+def board_cmakelist_get(path):
+ template = """# ##############################################################################
+# $board_path/CMakeLists.txt
+#
Review Comment:
```
# SPDX-License-Identifier: Apache-2.0
#
```
this must also be added
@raiden00pl very useful tool !
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] midokura-xavi92 commented on pull request #9782: tools: add a convert tool to help migrate from make to cmake
Posted by "midokura-xavi92 (via GitHub)" <gi...@apache.org>.
midokura-xavi92 commented on PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#issuecomment-1632814943
> Usage:
> `python tools/nxmake2cmake.py arch/arm/src/stm32f0l0g0`
Coincidentally, the example provided above `include`s another `Makefile`:
https://github.com/apache/nuttx/blob/f43c7e99bedd8ea0cc2e3e6c2c796c38dbb8f354/arch/arm/src/stm32f0l0g0/Make.defs#L21
[The file referred to above](https://github.com/apache/nuttx/blob/f43c7e99bedd8ea0cc2e3e6c2c796c38dbb8f354/arch/arm/src/armv6-m/Make.defs) seems to define another bunch of source files. However, `nxmake2cmake.py` seems to explicitly ignore lines with `include`, so none of these source files are being appended to the generated `CMakeLists.txt`. Is this intended?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] tools: add a convert tool to help migrate from make to cmake [nuttx]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on code in PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#discussion_r2068190344
##########
tools/nxmake2cmake.py:
##########
@@ -0,0 +1,241 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/nxmake2cmake.py
+#
+# 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 argparse
+import os
+import sys
+from string import Template
+
+if sys.version_info[0] < 3:
+ raise Exception("Must be using Python 3")
+
+
+def board_cmakelist_get(path):
+ template = """# ##############################################################################
+# $board_path/CMakeLists.txt
+#
+# 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.
+#
+# ##############################################################################
+
+add_subdirectory(src)
+"""
+ temp_obj = Template(template)
+ return temp_obj.substitute(board_path=path)
+
+
+def add_board_cmakelist(path):
+ cmpath = os.path.join(path, "CMakeLists.txt")
+
+ print("Add", cmpath)
+
+ with open(cmpath, "w") as f:
+ content = board_cmakelist_get(path)
+ content = board_cmakelist_get(path)
+ f.write(content)
+
+
+def file_update_path(s, oldpath, newpath):
+ return s.replace(oldpath, newpath)
+
+
+def convert_make_conditional(content):
+ content = content.replace(",y)", "")
+ content = content.replace("ifeq ($", "if")
+ content = content.replace("ifneq ($(", "if(NOT ")
+ content = content.replace("else", "else()")
+ content = content.replace("endif", "endif()")
+ content = content.replace("CHIP_CSRCS = ", "set(SRCS ")
+ content = content.replace("CHIP_CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace("CSRCS = ", "set(SRCS ")
+ content = content.replace("CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace(".c\n", ".c)\n")
+
+ return content
+
+
+# common for board Makefile and Make.defs
+def convert_board_common(path, content):
+ content = convert_make_conditional(content)
+
+ # remove make specific lines
+ content = "\n".join(line for line in content.split("\n") if "include" not in line)
+ content = "\n".join(line for line in content.split("\n") if "ASRCS" not in line)
+ content = "\n".join(line for line in content.split("\n") if "DEPPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "VPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "CFLAGS" not in line)
+
+ content += "target_sources(board PRIVATE ${SRCS})\n\n"
+
+ # linker script
+ if os.path.exists(os.path.join(path, "scripts/ld.script")):
+ content += 'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/ld.script")'
+ elif os.path.exists(os.path.join(path, "scripts/flash.ld")):
+ content += 'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/flash.ld")'
+ else:
+ print("ERROR: not found linker script")
+
+ content += "\n"
+ content = content.replace("\n\n\n", "\n\n")
+ content = content.replace("SRCS ", "SRCS ")
+
+ return content
+
+
+# convert board src/Make.defs to CMakeLists.txt
+def convert_board_makedefs(path):
+ mdpath = os.path.join(path, "src/Make.defs")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mdpath, "r") as fm:
+ content = fm.read()
+ content = content.replace(mdpath, cpath)
Review Comment:
On Windows, it does not replace the filename (Windows paths are different from Unix)
simple change
`
content = content.replace(mpath, cpath)
`
with
`
content = content.replace("src/Make.defs", "src/CMakeLists.txt")
`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] tools: add a convert tool to help migrate from make to cmake [nuttx]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on code in PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#discussion_r2047221301
##########
tools/nxmake2cmake.py:
##########
@@ -0,0 +1,239 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/nxmake2cmake.py
+#
+# 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 argparse
+import os
+import sys
+from string import Template
+
+if sys.version_info[0] < 3:
+ raise Exception("Must be using Python 3")
+
+
+def board_cmakelist_get(path):
+ template = """# ##############################################################################
+# $board_path/CMakeLists.txt
+#
+# 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.
+#
+# ##############################################################################
+
+add_subdirectory(src)
+"""
+ temp_obj = Template(template)
+ return temp_obj.substitute(board_path=path)
+
+
+def add_board_cmakelist(path):
+ cmpath = os.path.join(path, "CMakeLists.txt")
+
+ print("Add", cmpath)
+
+ with open(cmpath, "w") as f:
+ content = board_cmakelist_get(path)
+ content = board_cmakelist_get(path)
+ f.write(content)
+
+
+def file_update_path(s, oldpath, newpath):
+ return s.replace(oldpath, newpath)
+
+
+def convert_make_conditional(content):
+ content = content.replace(",y)", "")
+ content = content.replace("ifeq ($", "if")
+ content = content.replace("ifneq ($(", "if(NOT ")
+ content = content.replace("else", "else()")
+ content = content.replace("endif", "endif()")
+ content = content.replace("CHIP_CSRCS = ", "set(SRCS ")
+ content = content.replace("CHIP_CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace("CSRCS = ", "set(SRCS ")
+ content = content.replace("CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace(".c\n", ".c)\n")
+
+ return content
+
+
+# common for board Makefile and Make.defs
+def convert_board_common(path, content):
+ content = convert_make_conditional(content)
+
+ # remove make specific lines
+ content = "\n".join(line for line in content.split("\n") if "include" not in line)
+ content = "\n".join(line for line in content.split("\n") if "ASRCS" not in line)
+ content = "\n".join(line for line in content.split("\n") if "DEPPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "VPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "CFLAGS" not in line)
+
+ content += "target_sources(board PRIVATE ${SRCS})\n\n"
+
+ # linker script
+ if os.path.exists(os.path.join(path, "scripts/ld.script")):
+ content += 'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/ld.script")'
+ elif os.path.exists(os.path.join(path, "scripts/flash.ld")):
+ content += 'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/flash.ld")'
+ else:
+ print("ERROR: not found linker script")
+
+ content += "\n"
+ content = content.replace("\n\n\n", "\n\n")
+ content = content.replace("SRCS ", "SRCS ")
+
+ return content
+
+
+# convert board src/Make.defs to CMakeLists.txt
+def convert_board_makedefs(path):
+ mdpath = os.path.join(path, "src/Make.defs")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mdpath, "r") as fm:
+ content = fm.read()
+ content = content.replace(mdpath, cpath)
+ content = convert_board_common(path, content)
+
+ if content:
+ print("add", cpath)
+ with open(cpath, "w") as fc:
+ fc.write(content)
+
+
+# convert board src/Makefile to CMakeLists.txt
+def convert_board_makefile(path):
+ mpath = os.path.join(path, "src/Makefile")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mpath, "r") as fm:
+ content = fm.read()
+ content = content.replace(mpath, cpath)
+ content = convert_board_common(path, content)
+
+ if content:
+ print("add", cpath)
+ with open(cpath, "w") as fc:
+ fc.write(content)
+
+
+# convert board make build to cmake
+def convert_board(path):
+ add_board_cmakelist(path)
+
+ mpath = os.path.join(path, "src/Makefile")
+ mdpath = os.path.join(path, "src/Make.defs")
Review Comment:
Hi @raiden00pl sorry I was wrong !!!
Very useful tool !
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] tools: add a convert tool to help migrate from make to cmake [nuttx]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on code in PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#discussion_r2095740641
##########
tools/nxmake2cmake.py:
##########
@@ -0,0 +1,270 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/nxmake2cmake.py
+#
+# 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.
+#
+############################################################################
+
+__version__ = "0.0.1"
+
+import argparse
+import os
+import sys
+from string import Template
+
+if sys.version_info[0] < 3:
+ raise Exception("Must be using Python 3")
+
+
+def board_cmakelist_get(path):
+ template = """# ##############################################################################
+# $board_path/CMakeLists.txt
+#
+# 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.
+#
+# ##############################################################################
+
+add_subdirectory(src)
+"""
+ temp_obj = Template(template)
+ return temp_obj.substitute(board_path=path)
+
+
+def add_board_cmakelist(path):
+ cmpath = os.path.join(path, "CMakeLists.txt")
+
+ print("Add", cmpath)
+
+ with open(cmpath, "w") as f:
+ content = board_cmakelist_get(path)
+ f.write(content)
+
+
+def file_update_path(s, oldpath, newpath):
+ return s.replace(oldpath, newpath)
+
+
+def convert_make_conditional(content):
+ content = content.replace(",y)", "")
+ content = content.replace("else ifeq ($", "elseif")
+ content = content.replace("ifeq ($", "if")
+ content = content.replace("ifneq ($(", "if(NOT ")
+ content = content.replace("else\n", "else()\n")
+ content = content.replace("endif\n", "endif()\n")
+ content = content.replace("CHIP_CSRCS = ", "set(SRCS ")
+ content = content.replace("CHIP_CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace("CSRCS = ", "set(SRCS ")
+ content = content.replace("CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace(".c\n", ".c)\n")
+
+ return content
+
+
+# common for board Makefile and Make.defs
+def convert_board_common(path, content):
+ content = convert_make_conditional(content)
+
+ # remove make specific lines
+ content = "\n".join(line for line in content.split("\n") if "include" not in line)
+ content = "\n".join(line for line in content.split("\n") if "ASRCS" not in line)
+ content = "\n".join(line for line in content.split("\n") if "DEPPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "VPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "CFLAGS" not in line)
+
+ content += "target_sources(board PRIVATE ${SRCS})\n\n"
+
+ # linker script
+ if os.path.exists(os.path.join(path, "scripts/ld.script")):
Review Comment:
count = 0
scriptpath = os.path.join(path, "scripts")
# linker script
for filename in os.listdir(scriptpath):
if filename.endswith(".ld") or filename.endswith(".script"):
print("found linker script ->", filename)
content += (
'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/'
+ filename
+ '")\n'
)
count += 1
continue
else:
continue
if count == 0:
print("ERROR: not found linker script")
Search the directory scripts for files with the extension .ld and .script
and not name.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] raiden00pl commented on pull request #9782: tools: add a convert tool to help migrate from make to cmake
Posted by "raiden00pl (via GitHub)" <gi...@apache.org>.
raiden00pl commented on PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#issuecomment-1635524778
> > Usage:
> > `python tools/nxmake2cmake.py arch/arm/src/stm32f0l0g0`
>
> Coincidentally, the example provided above `include`s another `Makefile`:
>
> https://github.com/apache/nuttx/blob/f43c7e99bedd8ea0cc2e3e6c2c796c38dbb8f354/arch/arm/src/stm32f0l0g0/Make.defs#L21
>
> [The file referred to above](https://github.com/apache/nuttx/blob/f43c7e99bedd8ea0cc2e3e6c2c796c38dbb8f354/arch/arm/src/armv6-m/Make.defs) seems to define another bunch of source files. However, `nxmake2cmake.py` seems to explicitly ignore lines with `include`, so none of these source files are being appended to the generated `CMakeLists.txt`. Is this intended?
The included Makefile is handled elsewhere (https://github.com/apache/nuttx/blob/f43c7e99bedd8ea0cc2e3e6c2c796c38dbb8f354/arch/arm/src/cmake/armv7-m.cmake), so we can just ignore it.
> Nit: similar tools, such as parsememdump.py, have their +x bit set. Considering nxmake2cmake.py also defines a shebang (i.e., #!/usr/bin/env python3), maybe this was a leftover?
I see that all .py files in `tools/` have `+x` set, so I changed it here as well
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] tools: add a convert tool to help migrate from make to cmake [nuttx]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on code in PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#discussion_r2068184260
##########
tools/nxmake2cmake.py:
##########
@@ -0,0 +1,241 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/nxmake2cmake.py
+#
+# 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 argparse
+import os
+import sys
+from string import Template
+
+if sys.version_info[0] < 3:
+ raise Exception("Must be using Python 3")
+
+
+def board_cmakelist_get(path):
+ template = """# ##############################################################################
+# $board_path/CMakeLists.txt
+#
+# 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.
+#
+# ##############################################################################
+
+add_subdirectory(src)
+"""
+ temp_obj = Template(template)
+ return temp_obj.substitute(board_path=path)
+
+
+def add_board_cmakelist(path):
+ cmpath = os.path.join(path, "CMakeLists.txt")
+
+ print("Add", cmpath)
+
+ with open(cmpath, "w") as f:
+ content = board_cmakelist_get(path)
+ content = board_cmakelist_get(path)
+ f.write(content)
+
+
+def file_update_path(s, oldpath, newpath):
+ return s.replace(oldpath, newpath)
+
+
+def convert_make_conditional(content):
+ content = content.replace(",y)", "")
+ content = content.replace("ifeq ($", "if")
+ content = content.replace("ifneq ($(", "if(NOT ")
+ content = content.replace("else", "else()")
+ content = content.replace("endif", "endif()")
+ content = content.replace("CHIP_CSRCS = ", "set(SRCS ")
+ content = content.replace("CHIP_CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace("CSRCS = ", "set(SRCS ")
+ content = content.replace("CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace(".c\n", ".c)\n")
+
+ return content
+
+
+# common for board Makefile and Make.defs
+def convert_board_common(path, content):
+ content = convert_make_conditional(content)
+
+ # remove make specific lines
+ content = "\n".join(line for line in content.split("\n") if "include" not in line)
+ content = "\n".join(line for line in content.split("\n") if "ASRCS" not in line)
+ content = "\n".join(line for line in content.split("\n") if "DEPPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "VPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "CFLAGS" not in line)
+
+ content += "target_sources(board PRIVATE ${SRCS})\n\n"
+
+ # linker script
+ if os.path.exists(os.path.join(path, "scripts/ld.script")):
+ content += 'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/ld.script")'
+ elif os.path.exists(os.path.join(path, "scripts/flash.ld")):
+ content += 'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/flash.ld")'
+ else:
+ print("ERROR: not found linker script")
+
+ content += "\n"
+ content = content.replace("\n\n\n", "\n\n")
+ content = content.replace("SRCS ", "SRCS ")
+
+ return content
+
+
+# convert board src/Make.defs to CMakeLists.txt
+def convert_board_makedefs(path):
+ mdpath = os.path.join(path, "src/Make.defs")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mdpath, "r") as fm:
+ content = fm.read()
+ content = content.replace(mdpath, cpath)
+ content = convert_board_common(path, content)
+
+ if content:
+ print("add", cpath)
+ with open(cpath, "w") as fc:
+ fc.write(content)
+
+
+# convert board src/Makefile to CMakeLists.txt
+def convert_board_makefile(path):
+ mpath = os.path.join(path, "src/Makefile")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mpath, "r") as fm:
+ content = fm.read()
+ content = content.replace(mpath, cpath)
Review Comment:
On Windows, it does not replace the filename (Windows paths are different from Unix)
simple change
content = content.replace(mpath, cpath)
with
content = content.replace("src/Make.defs", "src/CMakeLists.txt")
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] tools: add a convert tool to help migrate from make to cmake [nuttx]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on code in PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#discussion_r2047221301
##########
tools/nxmake2cmake.py:
##########
@@ -0,0 +1,239 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/nxmake2cmake.py
+#
+# 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 argparse
+import os
+import sys
+from string import Template
+
+if sys.version_info[0] < 3:
+ raise Exception("Must be using Python 3")
+
+
+def board_cmakelist_get(path):
+ template = """# ##############################################################################
+# $board_path/CMakeLists.txt
+#
+# 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.
+#
+# ##############################################################################
+
+add_subdirectory(src)
+"""
+ temp_obj = Template(template)
+ return temp_obj.substitute(board_path=path)
+
+
+def add_board_cmakelist(path):
+ cmpath = os.path.join(path, "CMakeLists.txt")
+
+ print("Add", cmpath)
+
+ with open(cmpath, "w") as f:
+ content = board_cmakelist_get(path)
+ content = board_cmakelist_get(path)
+ f.write(content)
+
+
+def file_update_path(s, oldpath, newpath):
+ return s.replace(oldpath, newpath)
+
+
+def convert_make_conditional(content):
+ content = content.replace(",y)", "")
+ content = content.replace("ifeq ($", "if")
+ content = content.replace("ifneq ($(", "if(NOT ")
+ content = content.replace("else", "else()")
+ content = content.replace("endif", "endif()")
+ content = content.replace("CHIP_CSRCS = ", "set(SRCS ")
+ content = content.replace("CHIP_CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace("CSRCS = ", "set(SRCS ")
+ content = content.replace("CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace(".c\n", ".c)\n")
+
+ return content
+
+
+# common for board Makefile and Make.defs
+def convert_board_common(path, content):
+ content = convert_make_conditional(content)
+
+ # remove make specific lines
+ content = "\n".join(line for line in content.split("\n") if "include" not in line)
+ content = "\n".join(line for line in content.split("\n") if "ASRCS" not in line)
+ content = "\n".join(line for line in content.split("\n") if "DEPPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "VPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "CFLAGS" not in line)
+
+ content += "target_sources(board PRIVATE ${SRCS})\n\n"
+
+ # linker script
+ if os.path.exists(os.path.join(path, "scripts/ld.script")):
+ content += 'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/ld.script")'
+ elif os.path.exists(os.path.join(path, "scripts/flash.ld")):
+ content += 'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/flash.ld")'
+ else:
+ print("ERROR: not found linker script")
+
+ content += "\n"
+ content = content.replace("\n\n\n", "\n\n")
+ content = content.replace("SRCS ", "SRCS ")
+
+ return content
+
+
+# convert board src/Make.defs to CMakeLists.txt
+def convert_board_makedefs(path):
+ mdpath = os.path.join(path, "src/Make.defs")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mdpath, "r") as fm:
+ content = fm.read()
+ content = content.replace(mdpath, cpath)
+ content = convert_board_common(path, content)
+
+ if content:
+ print("add", cpath)
+ with open(cpath, "w") as fc:
+ fc.write(content)
+
+
+# convert board src/Makefile to CMakeLists.txt
+def convert_board_makefile(path):
+ mpath = os.path.join(path, "src/Makefile")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mpath, "r") as fm:
+ content = fm.read()
+ content = content.replace(mpath, cpath)
+ content = convert_board_common(path, content)
+
+ if content:
+ print("add", cpath)
+ with open(cpath, "w") as fc:
+ fc.write(content)
+
+
+# convert board make build to cmake
+def convert_board(path):
+ add_board_cmakelist(path)
+
+ mpath = os.path.join(path, "src/Makefile")
+ mdpath = os.path.join(path, "src/Make.defs")
Review Comment:
mdpath = os.path.join(path, "src/CMakeLists.txt")
Hi @raiden00pl Maybe this should be like this
Very useful tool !
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] acassis commented on pull request #9782: tools: add a convert tool to help migrate from make to cmake
Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis commented on PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#issuecomment-1630828643
@raiden00pl that is a great idea! In fact working on two build systems at same time it not easy, at least this script will help to simplify the process!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] tools: add a convert tool to help migrate from make to cmake [nuttx]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#issuecomment-2862704424
Hi @raiden00pl I have made the following changes:
- removed repeated code line 66
( content = board_cmakelist_get(path) )
- fix paths for windows (arch directory)
- added more user-friendly help
- added version
I attach new version
[nxmake2cmake.txt](https://github.com/user-attachments/files/20101821/nxmake2cmake.txt)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] tools: add a convert tool to help migrate from make to cmake [nuttx]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on code in PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#discussion_r2068184260
##########
tools/nxmake2cmake.py:
##########
@@ -0,0 +1,241 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/nxmake2cmake.py
+#
+# 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 argparse
+import os
+import sys
+from string import Template
+
+if sys.version_info[0] < 3:
+ raise Exception("Must be using Python 3")
+
+
+def board_cmakelist_get(path):
+ template = """# ##############################################################################
+# $board_path/CMakeLists.txt
+#
+# 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.
+#
+# ##############################################################################
+
+add_subdirectory(src)
+"""
+ temp_obj = Template(template)
+ return temp_obj.substitute(board_path=path)
+
+
+def add_board_cmakelist(path):
+ cmpath = os.path.join(path, "CMakeLists.txt")
+
+ print("Add", cmpath)
+
+ with open(cmpath, "w") as f:
+ content = board_cmakelist_get(path)
+ content = board_cmakelist_get(path)
+ f.write(content)
+
+
+def file_update_path(s, oldpath, newpath):
+ return s.replace(oldpath, newpath)
+
+
+def convert_make_conditional(content):
+ content = content.replace(",y)", "")
+ content = content.replace("ifeq ($", "if")
+ content = content.replace("ifneq ($(", "if(NOT ")
+ content = content.replace("else", "else()")
+ content = content.replace("endif", "endif()")
+ content = content.replace("CHIP_CSRCS = ", "set(SRCS ")
+ content = content.replace("CHIP_CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace("CSRCS = ", "set(SRCS ")
+ content = content.replace("CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace(".c\n", ".c)\n")
+
+ return content
+
+
+# common for board Makefile and Make.defs
+def convert_board_common(path, content):
+ content = convert_make_conditional(content)
+
+ # remove make specific lines
+ content = "\n".join(line for line in content.split("\n") if "include" not in line)
+ content = "\n".join(line for line in content.split("\n") if "ASRCS" not in line)
+ content = "\n".join(line for line in content.split("\n") if "DEPPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "VPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "CFLAGS" not in line)
+
+ content += "target_sources(board PRIVATE ${SRCS})\n\n"
+
+ # linker script
+ if os.path.exists(os.path.join(path, "scripts/ld.script")):
+ content += 'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/ld.script")'
+ elif os.path.exists(os.path.join(path, "scripts/flash.ld")):
+ content += 'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/flash.ld")'
+ else:
+ print("ERROR: not found linker script")
+
+ content += "\n"
+ content = content.replace("\n\n\n", "\n\n")
+ content = content.replace("SRCS ", "SRCS ")
+
+ return content
+
+
+# convert board src/Make.defs to CMakeLists.txt
+def convert_board_makedefs(path):
+ mdpath = os.path.join(path, "src/Make.defs")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mdpath, "r") as fm:
+ content = fm.read()
+ content = content.replace(mdpath, cpath)
+ content = convert_board_common(path, content)
+
+ if content:
+ print("add", cpath)
+ with open(cpath, "w") as fc:
+ fc.write(content)
+
+
+# convert board src/Makefile to CMakeLists.txt
+def convert_board_makefile(path):
+ mpath = os.path.join(path, "src/Makefile")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mpath, "r") as fm:
+ content = fm.read()
+ content = content.replace(mpath, cpath)
Review Comment:
On Windows, it does not replace the filename (Windows paths are different from Unix)
simple change
`
content = content.replace(mpath, cpath)
`
with
`
content = content.replace("src/Make.defs", "src/CMakeLists.txt")`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] tools: add a convert tool to help migrate from make to cmake [nuttx]
Posted by "raiden00pl (via GitHub)" <gi...@apache.org>.
raiden00pl commented on code in PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#discussion_r2074889448
##########
tools/nxmake2cmake.py:
##########
@@ -0,0 +1,241 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/nxmake2cmake.py
+#
+# 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 argparse
+import os
+import sys
+from string import Template
+
+if sys.version_info[0] < 3:
+ raise Exception("Must be using Python 3")
+
+
+def board_cmakelist_get(path):
+ template = """# ##############################################################################
+# $board_path/CMakeLists.txt
+#
+# 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.
+#
+# ##############################################################################
+
+add_subdirectory(src)
+"""
+ temp_obj = Template(template)
+ return temp_obj.substitute(board_path=path)
+
+
+def add_board_cmakelist(path):
+ cmpath = os.path.join(path, "CMakeLists.txt")
+
+ print("Add", cmpath)
+
+ with open(cmpath, "w") as f:
+ content = board_cmakelist_get(path)
+ content = board_cmakelist_get(path)
+ f.write(content)
+
+
+def file_update_path(s, oldpath, newpath):
+ return s.replace(oldpath, newpath)
+
+
+def convert_make_conditional(content):
+ content = content.replace(",y)", "")
+ content = content.replace("ifeq ($", "if")
+ content = content.replace("ifneq ($(", "if(NOT ")
+ content = content.replace("else", "else()")
+ content = content.replace("endif", "endif()")
+ content = content.replace("CHIP_CSRCS = ", "set(SRCS ")
+ content = content.replace("CHIP_CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace("CSRCS = ", "set(SRCS ")
+ content = content.replace("CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace(".c\n", ".c)\n")
+
+ return content
+
+
+# common for board Makefile and Make.defs
+def convert_board_common(path, content):
+ content = convert_make_conditional(content)
+
+ # remove make specific lines
+ content = "\n".join(line for line in content.split("\n") if "include" not in line)
+ content = "\n".join(line for line in content.split("\n") if "ASRCS" not in line)
+ content = "\n".join(line for line in content.split("\n") if "DEPPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "VPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "CFLAGS" not in line)
+
+ content += "target_sources(board PRIVATE ${SRCS})\n\n"
+
+ # linker script
+ if os.path.exists(os.path.join(path, "scripts/ld.script")):
+ content += 'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/ld.script")'
+ elif os.path.exists(os.path.join(path, "scripts/flash.ld")):
+ content += 'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/flash.ld")'
+ else:
+ print("ERROR: not found linker script")
+
+ content += "\n"
+ content = content.replace("\n\n\n", "\n\n")
+ content = content.replace("SRCS ", "SRCS ")
+
+ return content
+
+
+# convert board src/Make.defs to CMakeLists.txt
+def convert_board_makedefs(path):
+ mdpath = os.path.join(path, "src/Make.defs")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mdpath, "r") as fm:
+ content = fm.read()
+ content = content.replace(mdpath, cpath)
+ content = convert_board_common(path, content)
+
+ if content:
+ print("add", cpath)
+ with open(cpath, "w") as fc:
+ fc.write(content)
+
+
+# convert board src/Makefile to CMakeLists.txt
+def convert_board_makefile(path):
+ mpath = os.path.join(path, "src/Makefile")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mpath, "r") as fm:
+ content = fm.read()
+ content = content.replace(mpath, cpath)
Review Comment:
done
##########
tools/nxmake2cmake.py:
##########
@@ -0,0 +1,241 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/nxmake2cmake.py
+#
+# 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 argparse
+import os
+import sys
+from string import Template
+
+if sys.version_info[0] < 3:
+ raise Exception("Must be using Python 3")
+
+
+def board_cmakelist_get(path):
+ template = """# ##############################################################################
+# $board_path/CMakeLists.txt
+#
+# 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.
+#
+# ##############################################################################
+
+add_subdirectory(src)
+"""
+ temp_obj = Template(template)
+ return temp_obj.substitute(board_path=path)
+
+
+def add_board_cmakelist(path):
+ cmpath = os.path.join(path, "CMakeLists.txt")
+
+ print("Add", cmpath)
+
+ with open(cmpath, "w") as f:
+ content = board_cmakelist_get(path)
+ content = board_cmakelist_get(path)
+ f.write(content)
+
+
+def file_update_path(s, oldpath, newpath):
+ return s.replace(oldpath, newpath)
+
+
+def convert_make_conditional(content):
+ content = content.replace(",y)", "")
+ content = content.replace("ifeq ($", "if")
+ content = content.replace("ifneq ($(", "if(NOT ")
+ content = content.replace("else", "else()")
+ content = content.replace("endif", "endif()")
+ content = content.replace("CHIP_CSRCS = ", "set(SRCS ")
+ content = content.replace("CHIP_CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace("CSRCS = ", "set(SRCS ")
+ content = content.replace("CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace(".c\n", ".c)\n")
+
+ return content
+
+
+# common for board Makefile and Make.defs
+def convert_board_common(path, content):
+ content = convert_make_conditional(content)
+
+ # remove make specific lines
+ content = "\n".join(line for line in content.split("\n") if "include" not in line)
+ content = "\n".join(line for line in content.split("\n") if "ASRCS" not in line)
+ content = "\n".join(line for line in content.split("\n") if "DEPPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "VPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "CFLAGS" not in line)
+
+ content += "target_sources(board PRIVATE ${SRCS})\n\n"
+
+ # linker script
+ if os.path.exists(os.path.join(path, "scripts/ld.script")):
+ content += 'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/ld.script")'
+ elif os.path.exists(os.path.join(path, "scripts/flash.ld")):
+ content += 'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/flash.ld")'
+ else:
+ print("ERROR: not found linker script")
+
+ content += "\n"
+ content = content.replace("\n\n\n", "\n\n")
+ content = content.replace("SRCS ", "SRCS ")
+
+ return content
+
+
+# convert board src/Make.defs to CMakeLists.txt
+def convert_board_makedefs(path):
+ mdpath = os.path.join(path, "src/Make.defs")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mdpath, "r") as fm:
+ content = fm.read()
+ content = content.replace(mdpath, cpath)
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] tools: add a convert tool to help migrate from make to cmake [nuttx]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on code in PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#discussion_r2047221301
##########
tools/nxmake2cmake.py:
##########
@@ -0,0 +1,239 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/nxmake2cmake.py
+#
+# 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 argparse
+import os
+import sys
+from string import Template
+
+if sys.version_info[0] < 3:
+ raise Exception("Must be using Python 3")
+
+
+def board_cmakelist_get(path):
+ template = """# ##############################################################################
+# $board_path/CMakeLists.txt
+#
+# 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.
+#
+# ##############################################################################
+
+add_subdirectory(src)
+"""
+ temp_obj = Template(template)
+ return temp_obj.substitute(board_path=path)
+
+
+def add_board_cmakelist(path):
+ cmpath = os.path.join(path, "CMakeLists.txt")
+
+ print("Add", cmpath)
+
+ with open(cmpath, "w") as f:
+ content = board_cmakelist_get(path)
+ content = board_cmakelist_get(path)
+ f.write(content)
+
+
+def file_update_path(s, oldpath, newpath):
+ return s.replace(oldpath, newpath)
+
+
+def convert_make_conditional(content):
+ content = content.replace(",y)", "")
+ content = content.replace("ifeq ($", "if")
+ content = content.replace("ifneq ($(", "if(NOT ")
+ content = content.replace("else", "else()")
+ content = content.replace("endif", "endif()")
+ content = content.replace("CHIP_CSRCS = ", "set(SRCS ")
+ content = content.replace("CHIP_CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace("CSRCS = ", "set(SRCS ")
+ content = content.replace("CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace(".c\n", ".c)\n")
+
+ return content
+
+
+# common for board Makefile and Make.defs
+def convert_board_common(path, content):
+ content = convert_make_conditional(content)
+
+ # remove make specific lines
+ content = "\n".join(line for line in content.split("\n") if "include" not in line)
+ content = "\n".join(line for line in content.split("\n") if "ASRCS" not in line)
+ content = "\n".join(line for line in content.split("\n") if "DEPPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "VPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "CFLAGS" not in line)
+
+ content += "target_sources(board PRIVATE ${SRCS})\n\n"
+
+ # linker script
+ if os.path.exists(os.path.join(path, "scripts/ld.script")):
+ content += 'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/ld.script")'
+ elif os.path.exists(os.path.join(path, "scripts/flash.ld")):
+ content += 'set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/flash.ld")'
+ else:
+ print("ERROR: not found linker script")
+
+ content += "\n"
+ content = content.replace("\n\n\n", "\n\n")
+ content = content.replace("SRCS ", "SRCS ")
+
+ return content
+
+
+# convert board src/Make.defs to CMakeLists.txt
+def convert_board_makedefs(path):
+ mdpath = os.path.join(path, "src/Make.defs")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mdpath, "r") as fm:
+ content = fm.read()
+ content = content.replace(mdpath, cpath)
+ content = convert_board_common(path, content)
+
+ if content:
+ print("add", cpath)
+ with open(cpath, "w") as fc:
+ fc.write(content)
+
+
+# convert board src/Makefile to CMakeLists.txt
+def convert_board_makefile(path):
+ mpath = os.path.join(path, "src/Makefile")
+ cpath = os.path.join(path, "src/CMakeLists.txt")
+
+ content = ""
+ with open(mpath, "r") as fm:
+ content = fm.read()
+ content = content.replace(mpath, cpath)
+ content = convert_board_common(path, content)
+
+ if content:
+ print("add", cpath)
+ with open(cpath, "w") as fc:
+ fc.write(content)
+
+
+# convert board make build to cmake
+def convert_board(path):
+ add_board_cmakelist(path)
+
+ mpath = os.path.join(path, "src/Makefile")
+ mdpath = os.path.join(path, "src/Make.defs")
Review Comment:
mdpath = os.path.join(path, "src/CMakeLists.txt")
hi @raiden00pl Maybe this should be like this
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] raiden00pl commented on pull request #9782: tools: add a convert tool to help migrate from make to cmake
Posted by "raiden00pl (via GitHub)" <gi...@apache.org>.
raiden00pl commented on PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#issuecomment-1630856161
@acassis That's right, using two build systems is a pain. I personally migrate all my NuttX based code to CMake now.
I was a bit skeptical about CMake as I don't know it at all, but once it's upstream it's a good motivation to learn. After a few days of using it, I can confidently say that it is a positive change. Faster build and out-of-source builds convince me. The CMake syntax isn't even that disgusting once you get used to it for a while ;)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] acassis commented on pull request #9782: tools: add a convert tool to help migrate from make to cmake
Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis commented on PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#issuecomment-1631377195
I agree @raiden00pl !!! It will make NuttX integration easier!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] midokura-xavi92 commented on pull request #9782: tools: add a convert tool to help migrate from make to cmake
Posted by "midokura-xavi92 (via GitHub)" <gi...@apache.org>.
midokura-xavi92 commented on PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#issuecomment-1632804455
Thank you a lot for your contribution! Please let me share a few comments and minor concerns:
> Usage:
> `python tools/nxmake2cmake.py arch/arm/src/stm32f0l0g0`
> `python tools/nxmake2cmake.py boards/arm/stm32/nucleo-f302r8`
I am not sure if there any systems out there still mapping `python` to `python2`, so IMHO it might be sensible to enforce the use of `python3` for this script.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] midokura-xavi92 commented on pull request #9782: tools: add a convert tool to help migrate from make to cmake
Posted by "midokura-xavi92 (via GitHub)" <gi...@apache.org>.
midokura-xavi92 commented on PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#issuecomment-1632824506
Nit: similar tools, such as [`parsememdump.py`](https://github.com/apache/nuttx/blob/f43c7e99bedd8ea0cc2e3e6c2c796c38dbb8f354/tools/parsememdump.py), have their `+x` bit set. Considering `nxmake2cmake.py` also defines a shebang (i.e., `#!/usr/bin/env python3`), maybe this was a leftover?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] tools: add a convert tool to help migrate from make to cmake [nuttx]
Posted by "raiden00pl (via GitHub)" <gi...@apache.org>.
raiden00pl commented on code in PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#discussion_r2109251368
##########
tools/nxmake2cmake.py:
##########
@@ -0,0 +1,270 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/nxmake2cmake.py
+#
+# 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.
+#
+############################################################################
+
+__version__ = "0.0.1"
+
+import argparse
+import os
+import sys
+from string import Template
+
+if sys.version_info[0] < 3:
+ raise Exception("Must be using Python 3")
+
+
+def board_cmakelist_get(path):
+ template = """# ##############################################################################
+# $board_path/CMakeLists.txt
+#
+# 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.
+#
+# ##############################################################################
+
+add_subdirectory(src)
+"""
+ temp_obj = Template(template)
+ return temp_obj.substitute(board_path=path)
+
+
+def add_board_cmakelist(path):
+ cmpath = os.path.join(path, "CMakeLists.txt")
+
+ print("Add", cmpath)
+
+ with open(cmpath, "w") as f:
+ content = board_cmakelist_get(path)
+ f.write(content)
+
+
+def file_update_path(s, oldpath, newpath):
+ return s.replace(oldpath, newpath)
+
+
+def convert_make_conditional(content):
+ content = content.replace(",y)", "")
+ content = content.replace("else ifeq ($", "elseif")
+ content = content.replace("ifeq ($", "if")
+ content = content.replace("ifneq ($(", "if(NOT ")
+ content = content.replace("else\n", "else()\n")
+ content = content.replace("endif\n", "endif()\n")
+ content = content.replace("CHIP_CSRCS = ", "set(SRCS ")
+ content = content.replace("CHIP_CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace("CSRCS = ", "set(SRCS ")
+ content = content.replace("CSRCS += ", " list(APPEND SRCS ")
+ content = content.replace(".c\n", ".c)\n")
+
+ return content
+
+
+# common for board Makefile and Make.defs
+def convert_board_common(path, content):
+ content = convert_make_conditional(content)
+
+ # remove make specific lines
+ content = "\n".join(line for line in content.split("\n") if "include" not in line)
+ content = "\n".join(line for line in content.split("\n") if "ASRCS" not in line)
+ content = "\n".join(line for line in content.split("\n") if "DEPPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "VPATH" not in line)
+ content = "\n".join(line for line in content.split("\n") if "CFLAGS" not in line)
+
+ content += "target_sources(board PRIVATE ${SRCS})\n\n"
+
+ # linker script
+ if os.path.exists(os.path.join(path, "scripts/ld.script")):
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] tools: add a convert tool to help migrate from make to cmake [nuttx]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on code in PR #9782:
URL: https://github.com/apache/nuttx/pull/9782#discussion_r2047231522
##########
tools/nxmake2cmake.py:
##########
@@ -0,0 +1,239 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/nxmake2cmake.py
+#
+# 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 argparse
+import os
+import sys
+from string import Template
+
+if sys.version_info[0] < 3:
+ raise Exception("Must be using Python 3")
+
+
+def board_cmakelist_get(path):
+ template = """# ##############################################################################
+# $board_path/CMakeLists.txt
+#
Review Comment:
```
# SPDX-License-Identifier: Apache-2.0
#
```
this must also be added
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org