diff options
| author | ruki <[email protected]> | 2026-03-04 07:54:30 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-03-04 07:54:30 +0800 |
| commit | bf24224a1f27d9b957caef9fdffa64f139ca093f (patch) | |
| tree | bc67ba183ffff74b7882fd02d53c04b274280187 /xmake/actions | |
| parent | e0e20ef6ddbd0fc62fbaa00d195ce95f22a86fdf (diff) | |
| parent | 074e35d2647a9271d37ecc30f41b4ca7332033ac (diff) | |
Merge pull request #7368 from xmake-io/templates
move templates to repository
Diffstat (limited to 'xmake/actions')
| -rw-r--r-- | xmake/actions/create/main.lua | 4 | ||||
| -rw-r--r-- | xmake/actions/create/template.lua | 26 |
2 files changed, 10 insertions, 20 deletions
diff --git a/xmake/actions/create/main.lua b/xmake/actions/create/main.lua index 72b69f3b2..89a4791a6 100644 --- a/xmake/actions/create/main.lua +++ b/xmake/actions/create/main.lua @@ -194,7 +194,9 @@ function _create_project(lang, templateid, targetname) -- create project local sourcedir = template.templatedir(lang, templateid) - assert(sourcedir, "template(%s/%s): not found!", lang, templateid) + if not sourcedir then + raise("template(%s/%s): not found!\nyou can try:\n - xrepo update-repo (update repositories)\n - xmake create --list (show available templates)", lang, templateid) + end -- get the builtin variables local builtinvars = template.builtinvars(targetname) diff --git a/xmake/actions/create/template.lua b/xmake/actions/create/template.lua index eb9e10b16..d638034cf 100644 --- a/xmake/actions/create/template.lua +++ b/xmake/actions/create/template.lua @@ -33,9 +33,8 @@ end -- get all template roots with extra meta information -- -- priority: --- 1. repo: <global-repo>/templates +-- 1. repo: <global-repo>/templates (including builtin repo templates) -- 2. global: <globaldir>/templates --- 3. builtin: <programdir>/templates function rootinfos() local results = {} @@ -55,10 +54,6 @@ function rootinfos() if os.isdir(dir) then table.insert(results, {kind = "global", dir = dir}) end - dir = path.join(os.programdir(), "templates") - if os.isdir(dir) then - table.insert(results, {kind = "builtin", dir = dir}) - end return results end @@ -144,20 +139,13 @@ function replace_variables_in_files(files, vars) end -- get all languages from templates +-- +-- scanning template roots to detect languages is too slow, and the language module list does not fully match template language names, +-- so we hardcode it here for better performance. function languages() - local found = hashset.new() - for _, rootdir in ipairs(rootdirs()) do - local languages_dirs = os.dirs(path.join(rootdir, "*")) - if languages_dirs then - for _, d in ipairs(languages_dirs) do - local name = path.filename(d) - found:insert(name) - end - end - end - local results = found:to_array() - table.sort(results) - return results + return {"c", "c++", "cuda", "dlang", "fortran", "go", + "kotlin", "nim", "objc", "objc++", "pascal", + "rust", "swift", "vala", "zig"} end -- get all templates for the given language |
