@@ -134,6 +134,27 @@ def run_cmd(cmd):
134134def to_blue (str ):
135135 return TBLUE + str + TWHITE
136136
137+ def cmake_cache_source_mismatch (build_dir , noos ):
138+ """True if build_dir's CMakeCache.txt was generated from a different source path.
139+
140+ CMake refuses to reuse a cache whose CMAKE_HOME_DIRECTORY differs, which
141+ happens when CI agents check the repo out under different absolute paths.
142+ """
143+ cache = os .path .join (build_dir , 'CMakeCache.txt' )
144+ if not os .path .isfile (cache ):
145+ return False
146+ want = os .path .realpath (noos )
147+ try :
148+ with open (cache ) as f :
149+ for line in f :
150+ if line .startswith ('CMAKE_HOME_DIRECTORY:' ):
151+ have = line .split ('=' , 1 )[1 ].strip ()
152+ return os .path .realpath (have ) != want
153+ except OSError :
154+ # Unreadable cache: treat as mismatch so --fresh regenerates it cleanly.
155+ return True
156+ return False
157+
137158SKIP_DOWNLOAD = None
138159key = 'SKIP_DOWNLOAD'
139160if key in os .environ :
@@ -362,30 +383,16 @@ def build_cmake_project(noos, project, _platform, export_dir, log_dir, cmake_bui
362383 jobs = int (multiprocessing .cpu_count () / 2 ) or 1
363384 # Pass an absolute --build-dir: no_os_build anchors a relative one to the
364385 # repo root, which would not match the build_dir we clean/probe here.
365- # Xilinx: reuse cached BSP unless the .xsa changed (new_hdf). Shared build
366- # dirs mean CMakeCache paths won't match the current checkout, but the BSP
367- # artifacts don't depend on source paths - only the .xsa matters.
368- fresh_flag = " --fresh" if (platform == 'xilinx' and new_hdf ) else ""
369-
370- # Update cmake cache with current working directory
371- if _platform == 'xilinx' :
372- cmake_cache_file = build_dir / 'CMakeCache.txt'
373- cmake_cache_file_new = build_dir / 'CMakeCache_new.txt'
374- cmake_toolchain_new = f"CMAKE_TOOLCHAIN_FILE:FILEPATH={ noos } /drivers/platform/xilinx/toolchain.cmake"
375- if os .path .exists (cmake_cache_file ):
376- with open (cmake_cache_file , "r" ) as old :
377- lines = old .readlines ()
378- with open (cmake_cache_file_new , "w" ) as new :
379- for line in lines :
380- if "CMAKE_TOOLCHAIN_FILE:FILEPATH=" in line :
381- line = cmake_toolchain_new
382- elif "no-os_SOURCE_DIR:STATIC" in line :
383- line = f"no-os_SOURCE_DIR:STATIC={ noos } "
384- elif "CMAKE_HOME_DIRECTORY:INTERNAL" in line :
385- line = f"CMAKE_HOME_DIRECTORY:INTERNAL={ noos } "
386- new .write (line )
387- os .remove (cmake_cache_file )
388- os .rename (cmake_cache_file_new , cmake_cache_file )
386+ # Xilinx: keep the cached BSP, clean only objects unless the .xsa changed
387+ # or the cache came from a different source path (another CI agent).
388+ stale_cache = platform == 'xilinx' and cmake_cache_source_mismatch (str (build_dir ), noos )
389+ if platform == 'xilinx' and build_dir .exists () and not new_hdf and not stale_cache :
390+ # CMAKE, not bare 'cmake': the sourced xilinx env leads PATH with Vitis's broken one.
391+ clean_cmd = "%s --build %s --target clean > /dev/null 2>&1" % (CMAKE , build_dir )
392+ os .system (clean_cmd )
393+ fresh_flag = ""
394+ else :
395+ fresh_flag = " --fresh"
389396
390397 build_cmd = ("python3 %s/tools/scripts/no_os_build.py build"
391398 " --project %s --variant %s --board %s"
@@ -436,8 +443,6 @@ def build_cmake_project(noos, project, _platform, export_dir, log_dir, cmake_bui
436443
437444 return ok
438445
439- < << << << HEAD
440- == == == =
441446def check_built_projects (projects = dict ):
442447 new_projects = {}
443448 for project , status in projects .items ():
@@ -506,7 +511,6 @@ def _finalize_bsp_hash(builds_dir, noos_dir):
506511 if os .path .isfile (regen_marker ):
507512 os .remove (regen_marker )
508513
509- > >> >> >> 4 afb59e42 (ci : create shared build workspace and filters )
510514def main ():
511515 (noos , export_dir , log_dir , _builds_dir , _platform , hdl_branch , _projects ) = parse_input ()
512516 projects_dir = os .path .join (noos ,'projects' )
0 commit comments