99 - commit messages have a well-formed subsystem prefix before ':'
1010 - commit subject lines are <= 160 characters
1111 - changed markdown files pass markdownlint-cli2
12- - new hwdef board directories include a README.md, except ODID variants
13- - new hwdef board READMEs contain at least one local image added in the PR,
14- except AP_Periph and ODID variants
12+
13+ (new hwdef board README/image requirements are validated by test_new_boards.py)
1514
1615AP_FLAKE8_CLEAN
1716'''
2827import urllib .error
2928import urllib .request
3029
31- import board_list
3230import build_script_base
3331
3432DOCS_URL = "https://ardupilot.org/dev/docs/submitting-patches-back-to-master.html"
5856class CheckBranchConventions (build_script_base .BuildScriptBase ):
5957
6058 DEFAULT_UPSTREAM = "origin/master"
61- HWDEF_PREFIX = "libraries/AP_HAL_ChibiOS/hwdef/"
6259
6360 def __init__ (self , base_branch : str | None = None ) -> None :
6461 super ().__init__ ()
6562 self .base_branch = base_branch
6663 repo_root = self .run_git (['rev-parse' , '--show-toplevel' ], show_output = False ).strip ()
6764 self .board_types_path = pathlib .Path (repo_root , 'Tools' , 'AP_Bootloader' , 'board_types.txt' )
68- self ._board_list : board_list .BoardList | None = None
6965
7066 def progress_prefix (self ) -> str :
7167 return "CBC"
@@ -77,34 +73,6 @@ def run_git(self, args, show_output=True, source_dir=None):
7773 show_output = show_output , show_command = False , cwd = source_dir ,
7874 )
7975
80- def board_list (self ) -> board_list .BoardList :
81- if self ._board_list is None :
82- self ._board_list = board_list .BoardList ()
83- return self ._board_list
84-
85- def is_odid_board (self , board_name : str ) -> bool :
86- try :
87- hwdef = self .board_list ().hwdef_for_board (board_name )
88- except KeyError :
89- return False
90- return hwdef .intdefines .get ('AP_OPENDRONEID_ENABLED' , 0 ) == 1
91-
92- def is_ap_periph_board (self , board_name : str ) -> bool :
93- try :
94- return bool (self .board_list ().board_by_name (board_name ).is_ap_periph )
95- except KeyError :
96- return False
97-
98- def check_board_readme_required (self , board_name : str ) -> bool :
99- return not self .is_odid_board (board_name )
100-
101- def check_board_image_required (self , board_name : str ) -> bool :
102- if self .is_odid_board (board_name ):
103- return False
104- if self .is_ap_periph_board (board_name ):
105- return False
106- return True
107-
10876 def check_merge_commits (self ) -> bool :
10977 merge_commits = self .run_git (
11078 ["log" , f"{ self .base_branch } ..HEAD" , "--merges" , "--oneline" ],
@@ -591,132 +559,10 @@ def check_board_ids(self) -> bool:
591559
592560 return all_board_ids_are_valid
593561
594- def check_new_board_has_readme (self ) -> bool :
595- '''Every new hwdef board directory must include a README.md.'''
596-
597- added_raw = self .run_git (
598- ["diff" , "--name-only" , "--diff-filter=A" ,
599- f"{ self .base_branch } ...HEAD" ],
600- show_output = False ,
601- ).strip ()
602- added_files = set (added_raw .splitlines ()) if added_raw else set ()
603-
604- # Board dirs that have at least one newly added file at depth 1 under hwdef/
605- candidate_boards = {
606- f .split ("/" )[3 ]
607- for f in added_files
608- if f .startswith (self .HWDEF_PREFIX ) and f .count ("/" ) == 4
609- }
610-
611- if not candidate_boards :
612- print (f"{ PASS } No new hwdef board directories added." )
613- return True
614-
615- # Determine which of those dirs are genuinely new (absent in base branch)
616- existing_raw = self .run_git (
617- ["ls-tree" , "--name-only" , self .base_branch ,
618- self .HWDEF_PREFIX ],
619- show_output = False ,
620- ).strip ()
621- existing_boards = {
622- os .path .basename (p )
623- for p in existing_raw .splitlines ()
624- if p .strip ()
625- }
626-
627- new_boards = sorted (candidate_boards - existing_boards )
628- if not new_boards :
629- print (f"{ PASS } No new hwdef board directories added." )
630- return True
631-
632- ok = True
633- for board_name in new_boards :
634- if not self .check_board_readme_required (board_name ):
635- print (f"{ PASS } { board_name } : README.md not required for ODID variant." )
636- continue
637-
638- board_prefix = f"{ self .HWDEF_PREFIX } { board_name } /"
639- has_readme = any (
640- os .path .basename (f ) == "README.md"
641- for f in added_files
642- if f .startswith (board_prefix )
643- )
644- if has_readme :
645- print (f"{ PASS } { board_name } : README.md present." )
646- else :
647- print (f"{ FAIL } { board_name } : new board directory has no README.md." )
648- ok = False
649-
650- return ok
651-
652- def check_new_board_images (self ) -> bool :
653- '''For each newly added hwdef board README, verify it contains at least one
654- local image reference that is also a newly added file in the PR.'''
655-
656- # All files added (not modified) in this PR
657- added_raw = self .run_git (
658- ["diff" , "--name-only" , "--diff-filter=A" ,
659- f"{ self .base_branch } ...HEAD" ],
660- show_output = False ,
661- ).strip ()
662- added_files = set (added_raw .splitlines ()) if added_raw else set ()
663-
664- # New READMEs exactly one directory level under hwdef/
665- # e.g. libraries/AP_HAL_ChibiOS/hwdef/NewBoard/README.md → 4 slashes
666- new_readmes = sorted (
667- f for f in added_files
668- if f .startswith (self .HWDEF_PREFIX )
669- and os .path .basename (f ) == "README.md"
670- and f .count ("/" ) == 4
671- )
672-
673- if not new_readmes :
674- print (f"{ PASS } No new hwdef board READMEs added." )
675- return True
676-
677- img_md_re = re .compile (r'!\[[^\]]*\]\(([^)#?\s]+)' )
678-
679- ok = True
680- for readme_path in new_readmes :
681- board_name = readme_path .split ("/" )[3 ]
682-
683- if not self .check_board_image_required (board_name ):
684- print (f"{ PASS } { board_name } : README.md image not required." )
685- continue
686-
687- if not os .path .exists (readme_path ):
688- print (f"{ SKIP } { board_name } : README not present locally, skipping image check." )
689- continue
690-
691- with open (readme_path , encoding = "utf-8" , errors = "replace" ) as fh :
692- content = fh .read ()
693-
694- readme_dir = os .path .dirname (readme_path )
695- local_refs = []
696- for m in img_md_re .finditer (content ):
697- src = m .group (1 ).strip ()
698- if not src .startswith (("http://" , "https://" , "//" )):
699- local_refs .append (src )
700-
701- if not local_refs :
702- print (f"{ FAIL } { board_name } : README.md contains no local image references." )
703- ok = False
704- continue
705-
706- found = any (
707- os .path .normpath (os .path .join (readme_dir , src )) in added_files
708- for src in local_refs
709- )
710- if found :
711- print (f"{ PASS } { board_name } : README.md includes at least one image added in this PR." )
712- else :
713- print (f"{ FAIL } { board_name } : README.md has no local images added in this PR." )
714- for src in local_refs :
715- resolved = os .path .normpath (os .path .join (readme_dir , src ))
716- print (f" { src !r} → { resolved } " )
717- ok = False
718-
719- return ok
562+ # NOTE: checks concerning new hwdef boards (README.md presence, README
563+ # images, defaults.parm contents, and the board build itself) live in
564+ # test_new_boards.py, not here. Add new-board-related checks there to keep
565+ # them in one place and avoid the duplication this file once had.
720566
721567 def check_markdown (self ) -> bool :
722568 changed_md = self .run_git (
@@ -762,8 +608,6 @@ def run(self) -> None:
762608 self .check_author_emails (),
763609 self .check_submodule_isolation (),
764610 self .check_submodule_references_exist (),
765- self .check_new_board_has_readme (),
766- self .check_new_board_images (),
767611 self .check_board_ids (),
768612 self .check_markdown (),
769613 self .check_markdown_rst_hyperlinks (),
0 commit comments