启动icfb加载指定目录所有skill

编程
cdsinit, skill, autoLoad, virtuoso, icfb
0 字 / 约 0 分钟

背景

随着写过的skill程序越来越多,每次启动 virtuoso 都需要手动load,而且分布在不同的目录, 有不同的版本,明显不符合脚本控的习惯 所以写一个能在 virtuoso 启动时自动递归加载 指定目录 的所有skill脚本,实现所谓 自动巡航

目录结构

bash
/root/chiplayout.net/skill/autoLoadAllUsefullSkill.il
/root/chiplayout.net/skill/v1.251215/chiplayout.il
/home/personal/test.il

说明

  • autoLoadAllUsefullSkill.il 主程序
  • chiplayout.il 简易测试程序
  • test.il 其它目录加载测试

核心

  • TraverseDir 实现递归目录
  • 筛选所有 *.il 文件
  • 实现 load 并打印log
  • 结尾输出 all load 的提示

代码如下

cadence
/***********************************************
    > File Name: autoLoadAllUsefullSkill.il
    > Author:    chiplayout.net
    > Mail:      admin@chiplayout.net
    > Create Time: Thu Sep 17 22:51:12 2025
    > Description: 
***********************************************/
procedure( autoLoadAllUsefullSkill(@optional (dir "/root/chiplayout.net/skill/v1.251215"))
  prog((fullPath ilList)
    fullPath = simplifyFilename(dir)
    unless(isDir(fullPath)
      error("autoLoadAllUsefullSkill: <%s> is not a directory\n" fullPath))
    procedure(TraverseDir(d)
      prog((entries f)
        entries = remove(".." remove("." getDirFiles(d)))
        ;; start load current directory *.il
        foreach( x setof(file entries rexMatchp("\\.il$" file))
          f= buildString(list(d x) "/")
          printf("LOAD  %s\n" f)
          (load f)
        )
        ;; End load current directory *.il
        foreach(x setof(file entries isDir(buildString(list(d file) "/")))
          TraverseDir(buildString(list(d x) "/")))
      )
    ) ;; end TraverseDir
    TraverseDir(fullPath)
    printf("=== All Skill scripts under <%s> loaded. ===\n" fullPath)
    t
  )
)

使用方法

打开 .cdsinit 文件,末尾添加下面的代码

说明

  • loader 的值是 autoLoadAllUsefullSkill.il 存放的地方
  • autoLoadAllUsefullSkill 使用了两次,
    • 第一次Load 了 chiplayout.net/skill/v1.251215目录下的所有 skill 文件,建议创建一个chiplayout.net/skill/v1.251215的目录,如果后续有 usefull 的 skill都会放在这个包里
    • 第二次Load 了 /home/personal/ 目录下的所有 skill 文件, 暂时只有一个测试,可以换成自己的
    • 同理如果有其它目录的可以继续添加
cadence
;; .cdsinit
let((loader )
  loader = "/root/chiplayout.net/skill/autoLoadAllUsefullSkill.il"
  chiplayoutNetSkillDir = "/root/chiplayout.net/skill/v1.251215/"
  when(isFile(loader)
    (load loader)
    (autoLoadAllUsefullSkill chiplayoutNetSkillDir)
    (autoLoadAllUsefullSkill "/home/personal/")
  )
)

加载结果

  • 如果成功加载,会列出 LOAD list ,如下所示
cadence
LOAD  /root/chiplayout.net/skill/v1.251215//chiplayout.il
=== All Skill scripts under </root/chiplayout.net/skill/v1.251215/> loaded. ===
function TraverseDir redefined
LOAD  /home/personal//test.il
"Hello World!"
=== All Skill scripts under </home/personal/> loaded. ===
  • 如果输出了 Hello World! 说明 /home/personal/ 目录的 test.il 被加载了
  • 通过在 CIW 输入 autoLoadCheck, 收到 A very useful website:[ chipplayout.net](https://chiplayout.net) 说明 chiplayout.net/skill/v1.251215 里的 chiplayout.il 被加载了
cadence
autoLoadCheck
"Hello world!"

示例脚本

  • chiplayout.il
cadence
procedure(autoLoadCheck() 
    let(nil 
	println("A very useful website: chipplayout.net")
    )
)
  • test.il
cadence
println("Hello World!")