diff options
| author | ruki <[email protected]> | 2021-06-15 22:47:49 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-06-15 22:47:49 +0800 |
| commit | debc652cd0448967a9a2c5425a1d1ae7c6235af0 (patch) | |
| tree | 2f8d8283242ff5af3129cc6b256f19d6aa655325 | |
| parent | b820270442536da435f5fb5582bf56b8bde53011 (diff) | |
add import/export configs
| -rw-r--r-- | xmake/actions/config/main.lua | 33 | ||||
| -rw-r--r-- | xmake/actions/config/menuconf.lua | 14 | ||||
| -rw-r--r-- | xmake/actions/config/xmake.lua | 6 | ||||
| -rw-r--r-- | xmake/core/project/config.lua | 23 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/config.lua | 8 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/package.lua | 1 |
6 files changed, 67 insertions, 18 deletions
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index 61f497c77..68f8ab531 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -48,6 +48,8 @@ function _option_filter(name) , verbose = true , diagnosis = true , require = true + , export = true + , import = true } return not options[name] end @@ -189,6 +191,14 @@ function _config_targets(targetname) end end +-- export configs +function _export_configs() + local exportfile = option.get("export") + if exportfile then + config.save(exportfile, {public = true}) + end +end + -- main entry function main(opt) @@ -229,7 +239,7 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) -- the target name local targetname = option.get("target") or "all" - -- load the project configure + -- load the project configuration -- -- priority: option > option_cache > global > option_default > config_check > project_check > config_cache -- @@ -243,7 +253,7 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) end end - -- override configure from the options or cache + -- override configuration from the options or cache local options_history = {} if not option.get("clean") and not autogen then options_history = localcache.get("config", "options") or {} @@ -258,7 +268,15 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) config.set(name, value, {readonly = true}) end - -- merge the cached configure + -- merge configuration from the given import file + local importfile = option.get("import") + if importfile and os.isfile(importfile) then + if config.load(importfile) then + options_changed = true + end + end + + -- merge the cached configuration -- -- @note we cannot load cache config when switching platform, arch .. -- so we need known whether options have been changed @@ -268,7 +286,7 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) configcache_loaded = config.load() end - -- merge the global configure + -- merge the global configuration for name, value in pairs(global.options()) do if config.get(name) == nil then config.set(name, value) @@ -299,7 +317,7 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) -- load platform instance local instance_plat = platform.load(plat, arch) - -- merge the checked configure + -- merge the checked configuration local recheck = _need_check(options_changed or not configcache_loaded or autogen) if recheck then @@ -364,6 +382,11 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) config.dump() end + -- export configs + if option.get("export") then + _export_configs() + end + -- save options and config cache localcache.set("config", "recheck", false) localcache.set("config", "mtimes", project.mtimes()) diff --git a/xmake/actions/config/menuconf.lua b/xmake/actions/config/menuconf.lua index 5d4c53027..5657b30db 100644 --- a/xmake/actions/config/menuconf.lua +++ b/xmake/actions/config/menuconf.lua @@ -93,6 +93,8 @@ function app:_filter_option(name) , help = true , clean = true , menu = true + , import = true + , export = true } return not options[name] and not project.option(name) end @@ -358,9 +360,13 @@ end -- load configs from options function app:load(cache) - -- load config from cache - if cache then - cache = config.load() + -- merge configuration from the given import file or cache + local loaded = false + local importfile = option.get("import") + if importfile and os.isfile(importfile) then + loaded = config.load(importfile) + elseif cache then + loaded = config.load() end -- clear configs first @@ -374,7 +380,7 @@ function app:load(cache) self:mconfdialog():load(configs) -- the previous config is only for loading menuconf, so clear config now - if cache then + if loaded then config.clear() end end diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 1be74b3f2..6b58698d6 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -42,6 +42,12 @@ task("config") , options = { {'c', "clean", "k", nil , "Clean the cached configure and configure all again." } + , {nil, "export", "kv", nil , "Export the current configuration to the given file." + , " e.g." + , " - xmake f -m debug -xxx=y --export=build/config.txt" } + , {nil, "import", "kv", nil , "Import configuration from the given file." + , " e.g." + , " - xmake f -import=build/config.txt" } , {nil, "menu", "k", nil , "Configure project with a menu-driven user interface." } , {category = "."} , {'p', "plat", "kv", "auto" , "Compile for the given platform." diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua index a5107e456..31e7d0cb5 100644 --- a/xmake/core/project/config.lua +++ b/xmake/core/project/config.lua @@ -137,10 +137,11 @@ function config.directory() end -- load the project configuration -function config.load() +function config.load(filepath) local configs, errors - if os.isfile(config.filepath()) then - configs, errors = io.load(config.filepath()) + filepath = filepath or config.filepath() + if os.isfile(filepath) then + configs, errors = io.load(filepath) if not configs then utils.error(errors) return false @@ -160,8 +161,20 @@ function config.load() end -- save the project configuration -function config.save() - return io.save(config.filepath(), config.options()) +function config.save(filepath, opt) + opt = opt or {} + filepath = filepath or config.filepath() + if opt.public then + local configs = {} + for name, value in pairs(config.options()) do + if not name:startswith("__") then + configs[name] = value + end + end + return io.save(filepath, configs) + else + return io.save(filepath, config.options()) + end end -- read value from the configuration file directly diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua index 76647e313..f8177871a 100644 --- a/xmake/core/sandbox/modules/import/core/project/config.lua +++ b/xmake/core/sandbox/modules/import/core/project/config.lua @@ -87,13 +87,13 @@ function sandbox_core_project_config.readonly(name) end -- load the configuration -function sandbox_core_project_config.load() - return config.load() +function sandbox_core_project_config.load(filepath) + return config.load(filepath) end -- save the configuration -function sandbox_core_project_config.save() - local ok, errors = config.save() +function sandbox_core_project_config.save(filepath, opt) + local ok, errors = config.save(filepath, opt) if not ok then raise(errors) end diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 2c9fc0aae..e3fa7e3af 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -383,6 +383,7 @@ function _finish_requireinfo(requireinfo, package) -- we need ensure readonly configs for _, name in ipairs(table.keys(requireinfo.configs)) do if package:extraconf("configs", name, "readonly") then + print(name, requireinfo.configs[name], package:extraconf("configs", name, "default")) -- package:config() will use default value after loading package requireinfo.configs[name] = nil end |
