gromero commented on code in PR #12338:
URL: https://github.com/apache/tvm/pull/12338#discussion_r940861161


##########
apps/microtvm/zephyr/template_project/microtvm_api_server.py:
##########
@@ -152,6 +152,20 @@ def _get_flash_runner():
     return doc["flash-runner"]
 
 
+def _find_board_from_cmake_file(cmake_file: Union[str, pathlib.Path]) -> str:
+    """Find Zephyr board from generated CMakeLists.txt"""
+    zephyr_board = None
+    with open(cmake_file) as cmake_f:
+        for line in cmake_f:
+            if line.startswith("set(BOARD"):
+                zephyr_board = line.strip("\n").strip("\r").strip(")").split(" 
")[1]

Review Comment:
   I think it's call for a capture group here. For instance:
   ```
        zephyr_board = None
        with open(cmake_file) as cmake_f:
            for line in cmake_f:
   -            if line.startswith("set(BOARD"):
   -                zephyr_board = 
line.strip("\n").strip("\r").strip(")").split(" ")[1]
   +            set_board = re.match("set\(BOARD (.*)\)", line)
   +            if set_board:
   +                zephyr_board = set_board.group(1)
                    break
    
        if not zephyr_board:
            raise RuntimeError(f"No Zephyr board set in the {cmake_file}.")
   +
        return zephyr_board
   
   ```



##########
apps/microtvm/zephyr/template_project/microtvm_api_server.py:
##########
@@ -152,6 +152,20 @@ def _get_flash_runner():
     return doc["flash-runner"]
 
 
+def _find_board_from_cmake_file(cmake_file: Union[str, pathlib.Path]) -> str:
+    """Find Zephyr board from generated CMakeLists.txt"""
+    zephyr_board = None
+    with open(cmake_file) as cmake_f:
+        for line in cmake_f:
+            if line.startswith("set(BOARD"):
+                zephyr_board = line.strip("\n").strip("\r").strip(")").split(" 
")[1]

Review Comment:
   But since it's minor enhancement I won't block on this.



##########
apps/microtvm/zephyr/template_project/microtvm_api_server.py:
##########
@@ -162,7 +176,7 @@ def _get_device_args(options):
         return _get_openocd_device_args(options)
 
     raise BoardError(
-        f"Don't know how to find serial terminal for board 
{CMAKE_CACHE['BOARD']} with flash "
+        f"Don't know how to find serial terminal for board 
{_find_board_from_cmake_file(API_SERVER_DIR / CMAKELIST_FILENAME)} with flash "

Review Comment:
   nit, and since it's out of scope for this PR I won't block on this (send a 
follow-on PR if you like): I think this error message should read something 
like:
   `f"Don't know how to get device arguments for runner {flash_runner}"`  so I 
don't think mentioning the board here is really necessary, like it happens in 
   
   
https://github.com/apache/tvm/blob/main/apps/microtvm/zephyr/template_project/microtvm_api_server.py#L743
   
   The runner is the important info here.
   
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to