@@ -342,14 +342,35 @@ def buildDepGraph(cfgs):
342342 return loader
343343
344344
345- def buildWorkload (cfgName , cfgs , buildBin = True , buildImg = True ):
345+ def buildWorkload (cfgName , cfgs , buildBin = True , buildImg = True , lspOnly = False ):
346346 # This should only be built once (multiple builds will mess up doit)
347347 global taskLoader
348348 if taskLoader is None :
349349 taskLoader = buildDepGraph (cfgs )
350350
351351 config = cfgs [cfgName ]
352352
353+ if lspOnly :
354+ # For LSP mode, we only need to generate compile_commands.json
355+ if 'linux' not in config :
356+ print ("Warning: No Linux configuration found for LSP generation" )
357+ return 0
358+
359+ # Create a simple task for LSP generation using the existing build system
360+ lspTask = {
361+ 'name' : f"lsp-{ cfgName } " ,
362+ 'actions' : [(makeBin , [config ], {'lspOnly' : True })],
363+ 'targets' : [str (config ['out-dir' ] / 'compile_commands.json' )],
364+ 'file_dep' : config ['linux' ]['config' ] if isinstance (config ['linux' ]['config' ], list ) else [config ['linux' ]['config' ]],
365+ 'task_dep' : []
366+ }
367+
368+ # Add the LSP task to the loader
369+ taskLoader .addTask (lspTask )
370+
371+ doitHandle = doit .doit_cmd .DoitMain (taskLoader )
372+ return doitHandle .run ([str (config ['out-dir' ] / 'compile_commands.json' )])
373+
353374 imgList = []
354375 binList = []
355376
@@ -520,7 +541,7 @@ def makeOpenSBI(config, nodisk=False):
520541 return config ['firmware' ]['source' ] / 'build' / 'platform' / 'generic' / 'firmware' / 'fw_payload.elf'
521542
522543
523- def makeBin (config , nodisk = False ):
544+ def makeBin (config , nodisk = False , lspOnly = False ):
524545 """Build the binary specified in 'config'.
525546
526547 This is called as a doit task (see buildDepGraph() and addDep())
@@ -561,23 +582,36 @@ def makeBin(config, nodisk=False):
561582 initramfsIncludes += [wlutil .getOpt ('initramfs-dir' ) / "disk" ]
562583 initramfsPath = makeInitramfs (initramfsIncludes , cpioDir , includeDevNodes = True )
563584
564- makeInitramfsKfrag (initramfsPath , cpioDir / "initramfs.kfrag" )
565- generateKConfig (config ['linux' ]['config' ] + [cpioDir / "initramfs.kfrag" ], config ['linux' ]['source' ])
566- wlutil .run (['make' ] + wlutil .getOpt ('linux-make-args' ) + ['vmlinux' , 'Image' , '-j' + str (wlutil .getOpt ('jlevel' ))], cwd = config ['linux' ]['source' ])
567- # copy files needed to build linux (busybox copying is put here so that it is shown per linux build)
568- shutil .copy (config ['linux' ]['source' ] / '.config' , config ['out-dir' ] / 'linux_config' )
569- shutil .copy (wlutil .getOpt ('busybox-dir' ) / '.config' , config ['out-dir' ] / 'busybox_config' )
585+ if lspOnly :
586+ # For LSP mode, just generate compile_commands.json
587+ generateKConfig (config ['linux' ]['config' ], config ['linux' ]['source' ])
588+ wlutil .run (['make' ] + wlutil .getOpt ('linux-make-args' ) + ['compile_commands.json' ],
589+ cwd = config ['linux' ]['source' ])
590+
591+ # Copy the generated compile_commands.json to the output directory
592+ shutil .copy (config ['linux' ]['source' ] / 'compile_commands.json' ,
593+ config ['out-dir' ] / 'compile_commands.json' )
594+ shutil .copy (config ['linux' ]['source' ] / '.config' ,
595+ config ['out-dir' ] / 'linux_config' )
596+ else :
597+ # Normal build process
598+ makeInitramfsKfrag (initramfsPath , cpioDir / "initramfs.kfrag" )
599+ generateKConfig (config ['linux' ]['config' ] + [cpioDir / "initramfs.kfrag" ], config ['linux' ]['source' ])
600+ wlutil .run (['make' ] + wlutil .getOpt ('linux-make-args' ) + ['vmlinux' , 'Image' , '-j' + str (wlutil .getOpt ('jlevel' ))], cwd = config ['linux' ]['source' ])
601+ # copy files needed to build linux (busybox copying is put here so that it is shown per linux build)
602+ shutil .copy (config ['linux' ]['source' ] / '.config' , config ['out-dir' ] / 'linux_config' )
603+ shutil .copy (wlutil .getOpt ('busybox-dir' ) / '.config' , config ['out-dir' ] / 'busybox_config' )
570604
571- fw = makeOpenSBI (config , nodisk )
605+ fw = makeOpenSBI (config , nodisk )
572606
573- config ['bin' ].parent .mkdir (parents = True , exist_ok = True )
574- config ['dwarf' ].parent .mkdir (parents = True , exist_ok = True )
575- if nodisk :
576- shutil .copy (fw , wlutil .noDiskPath (config ['bin' ]))
577- shutil .copy (config ['linux' ]['source' ] / 'vmlinux' , wlutil .noDiskPath (config ['dwarf' ]))
578- else :
579- shutil .copy (fw , config ['bin' ])
580- shutil .copy (config ['linux' ]['source' ] / 'vmlinux' , config ['dwarf' ])
607+ config ['bin' ].parent .mkdir (parents = True , exist_ok = True )
608+ config ['dwarf' ].parent .mkdir (parents = True , exist_ok = True )
609+ if nodisk :
610+ shutil .copy (fw , wlutil .noDiskPath (config ['bin' ]))
611+ shutil .copy (config ['linux' ]['source' ] / 'vmlinux' , wlutil .noDiskPath (config ['dwarf' ]))
612+ else :
613+ shutil .copy (fw , config ['bin' ])
614+ shutil .copy (config ['linux' ]['source' ] / 'vmlinux' , config ['dwarf' ])
581615
582616 return True
583617
0 commit comments