Sunrisepeak / d2ds

Dive into Data Structures - 强调动手实践的数据结构学习项目,其中包含在线书籍、公开课、练习代码等子项目
https://sunrisepeak.github.io/d2ds-courses/
Other
19 stars 12 forks source link

dslings: build-cache: use xmake's watch plugin replace mtime detect #15

Open Sunrisepeak opened 1 month ago

Sunrisepeak commented 1 month ago

https://xmake.io/#/zh-cn/plugin/builtin_plugins?id=%e9%a1%b9%e7%9b%ae%e6%9b%b4%e6%96%b0%e5%90%8e%e8%87%aa%e5%8a%a8%e6%9e%84%e5%bb%ba

        import("core.base.fwatcher")

        -- listen file change
        -- use xmake watch plugin and fwatcher to replace file mtime
        fwatcher.add(os.projectdir(), {recursive = true})
        local function target_files_changed()
            local ok, event = fwatcher.wait(50)
            local status = nil
            if ok > 0 then
                local status
                if event.type == fwatcher.ET_CREATE then
                    status = "created"
                elseif event.type == fwatcher.ET_MODIFY then
                    status = "modified"
                elseif event.type == fwatcher.ET_DELETE then
                    status = "deleted"
                end
                -- print(event.path, status)
            end
            return status ~= nil
        end