Unnamed: 0
int64
0
0
repo_id
stringlengths
5
186
file_path
stringlengths
15
223
content
stringlengths
1
32.8M
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/base/cli.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author OpportunityLiu -- @file cli.lua -- -- load modules local cli = require("base/cli") -- define module local sandbox_cli = sandbox_cli or {} -- inherit some builtin interfaces for key, value in pairs(cli) do if not key:startswith("_") then sandbox_cli[key] = value end end -- return module return sandbox_cli
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/base/heap.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file heap.lua -- -- return module return require("base/heap")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/base/list.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file list.lua -- -- return module return require("base/list")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/base/graph.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file graph.lua -- -- return module return require("base/graph")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/base/semver.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file semver.lua -- -- define module local sandbox_core_base_semver = sandbox_core_base_semver or {} -- load modules local table = require("base/table") local semver = require("base/semver") local raise = require("sandbox/modules/raise") -- new a version instance function sandbox_core_base_semver.new(version) local result, errors = semver.new(version) if errors then raise(errors) end return result end -- try parsing the given version string to semver instance function sandbox_core_base_semver.try_parse(version) return semver.new(version) end -- match a valid version from the string -- -- semver.match('xxx 1.2.3 xxx') => { major = 1, minor = 2, patch = 3, ... } -- semver.match('a.b.c') => nil -- function sandbox_core_base_semver.match(str, pos, pattern) return semver.match(str, pos, pattern) end -- is valid version? function sandbox_core_base_semver.is_valid(version) return semver.parse(version) ~= nil end -- is valid version range? function sandbox_core_base_semver.is_valid_range(range) local ok = semver.satisfies("1.0", range) return ok ~= nil end -- compare two version strings -- -- semver.compare('1.2.3', '1.3.0') > 0? -- function sandbox_core_base_semver.compare(version1, version2) local result, errors = semver.compare(version1, version2) if errors then raise(errors) end return result end -- this version satisfies in the given version range -- -- semver.satisfies('1.2.3', '1.x || >=2.5.0 || 5.0.0 - 7.2.3') => true -- function sandbox_core_base_semver.satisfies(version, range) local result, errors = semver.satisfies(version, range) if errors then raise(errors) end return result end -- select required version from versions, tags and branches -- -- e.g. -- -- local version, source = semver.select(">=1.5.0 <1.6", {"1.5.0", "1.5.1"}, {"v1.5.0", ..}, {"master", "dev"}) -- -- @version the selected version number -- @source the version source, e.g. version, tag, branch -- function sandbox_core_base_semver.select(range, versions, tags, branches) local verinfo, errors = semver.select(range, table.wrap(versions), table.wrap(tags), table.wrap(branches)) if not verinfo then raise(errors) end return verinfo.version, verinfo.source end -- return module return sandbox_core_base_semver
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/base/tty.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file tty.lua -- -- load modules return require("base/tty")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/base/privilege.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author TitanSnow -- @file privilege.lua -- -- return module return require("base/privilege")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/base/hashset.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author OpportunityLiu -- @file hashset.lua -- -- load modules local hashset = require("base/hashset") -- define module local sandbox_hashset = sandbox_hashset or {} -- inherit some builtin interfaces for key, value in pairs(hashset) do if not key:startswith("_") then sandbox_hashset[key] = value end end -- return module return sandbox_hashset
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/base/option.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file option.lua -- -- define module local sandbox_core_base_option = sandbox_core_base_option or {} -- load modules local table = require("base/table") local option = require("base/option") local raise = require("sandbox/modules/raise") -- get the option value function sandbox_core_base_option.get(name) return option.get(name) end -- set the option value function sandbox_core_base_option.set(name, value) option.set(name, value) end -- get the default option value function sandbox_core_base_option.default(name) return option.default(name) end -- get the given task menu function sandbox_core_base_option.taskmenu(taskname) return option.taskmenu(taskname) end -- get the options function sandbox_core_base_option.options() return assert(option.options()) end -- get the defaults function sandbox_core_base_option.defaults() return option.defaults() or {} end -- show logo function sandbox_core_base_option.show_logo(logo, opt) option.show_logo(logo, opt) end -- show options function sandbox_core_base_option.show_options(options, taskname) option.show_options(options, taskname) end -- parse arguments with the given options function sandbox_core_base_option.raw_parse(argv, options, opt) -- check assert(argv and options) -- parse it local results, errors = option.parse(argv, options, opt) if not results then raise(errors) end return results end -- parse arguments with the given options function sandbox_core_base_option.parse(argv, options, ...) -- check assert(argv and options) -- add common options table.insert(options, 1, {}) table.insert(options, 2, {'h', "help", "k", nil, "Print this help message and exit." }) table.insert(options, 3, {}) -- show help local descriptions = {...} local function show_help() for _, description in ipairs(descriptions) do print(description) end option.show_options(options) end -- parse it local results, errors = option.parse(argv, options) if not results then show_help() raise(errors) end -- help? if results.help then show_help() os.exit() else results.help = show_help end return results end -- save context function sandbox_core_base_option.save(taskname) return option.save(taskname) end -- restore context function sandbox_core_base_option.restore() option.restore() end -- get the boolean value function sandbox_core_base_option.boolean(value) return option.boolean(value) end -- return module return sandbox_core_base_option
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/base/text.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author OpportunityLiu -- @file text.lua -- -- load modules local text = require("base/text") -- define module local sandbox_text = sandbox_text or {} -- inherit some builtin interfaces for key, value in pairs(text) do if not key:startswith("_") then sandbox_text[key] = value end end -- return module return sandbox_text
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/base/dlist.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file dlist.lua -- -- return module return require("base/list")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/base/interpreter.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file interpreter.lua -- -- load modules local interpreter = require("base/interpreter") -- define module local sandbox_core_base_interpreter = sandbox_core_base_interpreter or {} -- inherit some builtin interfaces sandbox_core_base_interpreter.instance = interpreter.instance sandbox_core_base_interpreter.builtin_modules = interpreter.builtin_modules -- return module return sandbox_core_base_interpreter
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/base/global.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file global.lua -- -- define module local sandbox_core_base_global = sandbox_core_base_global or {} -- load modules local os = require("base/os") local table = require("base/table") local global = require("base/global") local platform = require("platform/platform") local raise = require("sandbox/modules/raise") -- export some readonly interfaces sandbox_core_base_global.get = global.get sandbox_core_base_global.set = global.set sandbox_core_base_global.readonly = global.readonly sandbox_core_base_global.dump = global.dump sandbox_core_base_global.clear = global.clear sandbox_core_base_global.options = global.options sandbox_core_base_global.filepath = global.filepath sandbox_core_base_global.directory = global.directory sandbox_core_base_global.cachedir = global.cachedir -- save the configure function sandbox_core_base_global.save() local ok, errors = global.save() if not ok then raise(errors) end end -- return module return sandbox_core_base_global
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/base/fwatcher.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file fwatcher.lua -- -- define module local sandbox_core_base_fwatcher = sandbox_core_base_fwatcher or {} -- load modules local fwatcher = require("base/fwatcher") local raise = require("sandbox/modules/raise") -- the fwatcher event type sandbox_core_base_fwatcher.ET_MODIFY = fwatcher.ET_MODIFY sandbox_core_base_fwatcher.ET_CREATE = fwatcher.ET_CREATE sandbox_core_base_fwatcher.ET_DELETE = fwatcher.ET_DELETE -- add watch directory function sandbox_core_base_fwatcher.add(watchdir, opt) local ok, errors = fwatcher.add(watchdir, opt) if not ok then raise(errors) end end -- remove watch directory function sandbox_core_base_fwatcher.remove(watchdir) local ok, errors = fwatcher.remove(watchdir) if not ok then raise(errors) end end -- wait event function sandbox_core_base_fwatcher.wait(timeout) local ok, event_or_errors = fwatcher.wait(timeout) if ok < 0 and event_or_errors then raise(event_or_errors) end return ok, event_or_errors end -- watch watchdirs function sandbox_core_base_fwatcher.watchdirs(watchdirs, callback, opt) local ok, errors = fwatcher.watchdirs(watchdirs, callback, opt) if not ok then raise(errors) end end -- watch created file path function sandbox_core_base_fwatcher.on_created(watchdirs, callback, opt) local ok, errors = fwatcher.on_created(watchdirs, callback, opt) if not ok then raise(errors) end end -- watch modified file path function sandbox_core_base_fwatcher.on_modified(watchdirs, callback, opt) local ok, errors = fwatcher.on_modified(watchdirs, callback, opt) if not ok then raise(errors) end end -- watch deleted file path function sandbox_core_base_fwatcher.on_deleted(watchdirs, callback, opt) local ok, errors = fwatcher.on_deleted(watchdirs, callback, opt) if not ok then raise(errors) end end -- return module return sandbox_core_base_fwatcher
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/base/profiler.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file profiler.lua -- -- define module local sandbox_core_base_profiler = sandbox_core_base_profiler or {} -- load modules local profiler = require("base/profiler") local raise = require("sandbox/modules/raise") -- enter tag function sandbox_core_base_profiler.enter(name, ...) profiler:enter(name, ...) end -- leave tag function sandbox_core_base_profiler.leave(name, ...) profiler:leave(name, ...) end -- return module return sandbox_core_base_profiler
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/base/json.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file json.lua -- -- define module local sandbox_core_base_json = sandbox_core_base_json or {} -- load modules local json = require("base/json") local raise = require("sandbox/modules/raise") -- inherit some builtin interfaces sandbox_core_base_json.null = json.null sandbox_core_base_json.purenull = json.purenull sandbox_core_base_json.mark_as_array = json.mark_as_array sandbox_core_base_json.is_marked_as_array = json.is_marked_as_array -- decode the json string to the lua table function sandbox_core_base_json.decode(jsonstr, opt) local luatable, errors = json.decode(jsonstr, opt) if not luatable then raise(errors) end return luatable end -- encode the lua table to the json string function sandbox_core_base_json.encode(luatable, opt) local jsonstr, errors = json.encode(luatable, opt) if not jsonstr then raise(errors) end return jsonstr end -- load json file to the lua table function sandbox_core_base_json.loadfile(filepath, opt) local luatable, errors = json.loadfile(filepath, opt) if not luatable then raise(errors) end return luatable end -- save lua table to the json file function sandbox_core_base_json.savefile(filepath, luatable, opt) local ok, errors = json.savefile(filepath, luatable, opt) if not ok then raise(errors) end return ok end -- return module return sandbox_core_base_json
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/base/task.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file task.lua -- -- define module local sandbox_core_base_task = sandbox_core_base_task or {} -- load modules local os = require("base/os") local io = require("base/io") local table = require("base/table") local option = require("base/option") local string = require("base/string") local task = require("base/task") local project = require("project/project") local raise = require("sandbox/modules/raise") -- run the given task function sandbox_core_base_task.run(taskname, options, ...) -- init options options = table.wrap(options) -- inherit some parent options for _, name in ipairs({"file", "project", "diagnosis", "verbose", "quiet", "yes", "confirm", "root"}) do if options[name] == nil and option.get(name) ~= nil then options[name] = option.get(name) end end -- save the current option and push a new option context option.save(taskname) -- init the new options for name, value in pairs(options) do option.set(name, value) end -- get task instance local taskname = option.taskname() or "build" local taskinst = task.task(taskname) or project.task(taskname) if not taskinst then raise("do unknown task(%s)!", taskname) end -- run the task local ok, errors = taskinst:run(...) if not ok then raise(errors) end -- restore the previous option context option.restore() end function sandbox_core_base_task.names() local default_tasks = table.keys(task.tasks()) local project_tasks = table.keys(project.tasks()) return table.join(default_tasks, project_tasks) end -- return module return sandbox_core_base_task
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/language/menu.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file menu.lua -- -- define module local sandbox_core_language_menu = sandbox_core_language_menu or {} -- load modules local menu = require("language/menu") local raise = require("sandbox/modules/raise") -- get the language menu options for the given action: config or global function sandbox_core_language_menu.options(action) -- get it local options, errors = menu.options(action) if not options then raise(errors) end -- ok? return options end -- return module return sandbox_core_language_menu
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/language/language.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file language.lua -- -- define module local sandbox_core_language = sandbox_core_language or {} -- load modules local language = require("language/language") local raise = require("sandbox/modules/raise") -- get the apis function sandbox_core_language.apis() return language.apis() end -- get the source extensions of all languages function sandbox_core_language.extensions() return language.extensions() end -- get the target kinds of all languages function sandbox_core_language.targetkinds() return language.targetkinds() end -- get the source kinds of all languages function sandbox_core_language.sourcekinds() return language.sourcekinds() end -- get the source flags of all languages function sandbox_core_language.sourceflags() return language.sourceflags() end -- get the linker kinds of all languages function sandbox_core_language.linkerkinds() return language.linkerkinds() end -- get the language kinds of all languages function sandbox_core_language.langkinds() return language.langkinds() end -- load the language from the given name (c++, objc++, swift, golang, asm, ...) function sandbox_core_language.load(name) local instance, errors = language.load(name) if not instance then raise(errors) end return instance end -- load the language from the given source kind: cc, cxx, mm, mxx, sc, go, as .. function sandbox_core_language.load_sk(sourcekind) local instance, errors = language.load_sk(sourcekind) if not instance then raise(errors) end return instance end -- load the language from the given source extension: .c, .cpp, .m, .mm, .swift, .go, .s .. function sandbox_core_language.load_ex(extension) local instance, errors = language.load_ex(extension) if not instance then raise(errors) end return instance end -- get source kind of the source file name function sandbox_core_language.sourcekind_of(sourcefile) local sourcekind, errors = language.sourcekind_of(sourcefile) if not sourcekind then raise(errors) end return sourcekind end -- get extension of the source kind function sandbox_core_language.extension_of(sourcekind) local extension, errors = language.extension_of(sourcekind) if not extension then raise(errors) end return extension end -- get linker info (kind and flag) of the source kinds function sandbox_core_language.linkerinfos_of(targetkind, sourcekinds) local linkerinfo, errors = language.linkerinfos_of(targetkind, sourcekinds) if not linkerinfo then raise(errors) end return linkerinfo end -- return module return sandbox_core_language
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/compress/lz4.lua
--!A cross-platform build utility compressd on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file lz4.lua -- -- define module local sandbox_core_compress_lz4 = sandbox_core_compress_lz4 or {} local sandbox_core_compress_lz4_cstream = sandbox_core_compress_lz4_cstream or {} local sandbox_core_compress_lz4_dstream = sandbox_core_compress_lz4_dstream or {} -- load modules local lz4 = require("compress/lz4") local raise = require("sandbox/modules/raise") -- wrap compress stream function _cstream_wrap(instance) local hooked = {} for name, func in pairs(sandbox_core_compress_lz4_cstream) do if not name:startswith("_") and type(func) == "function" then hooked["_" .. name] = instance["_" .. name] or instance[name] hooked[name] = func end end for name, func in pairs(hooked) do instance[name] = func end return instance end -- wrap decompress stream function _dstream_wrap(instance) local hooked = {} for name, func in pairs(sandbox_core_compress_lz4_dstream) do if not name:startswith("_") and type(func) == "function" then hooked["_" .. name] = instance["_" .. name] or instance[name] hooked[name] = func end end for name, func in pairs(hooked) do instance[name] = func end return instance end -- read data from stream function sandbox_core_compress_lz4_cstream.read(stream, buff, size, opt) local real, data_or_errors = stream:_read(buff, size, opt) if real < 0 and data_or_errors then raise(data_or_errors) end return real, data_or_errors end -- write data to stream function sandbox_core_compress_lz4_cstream.write(stream, data, opt) local real, errors = stream:_write(data, opt) if real < 0 and errors then raise(errors) end return real end -- read data from stream function sandbox_core_compress_lz4_dstream.read(stream, buff, size, opt) local real, data_or_errors = stream:_read(buff, size, opt) if real < 0 and data_or_errors then raise(data_or_errors) end return real, data_or_errors end -- write data to stream function sandbox_core_compress_lz4_dstream.write(stream, data, opt) local real, errors = stream:_write(data, opt) if real < 0 and errors then raise(errors) end return real end -- compress frame data function sandbox_core_compress_lz4.compress(data, opt) local result, errors = lz4.compress(data, opt) if not result and errors then raise(errors) end return result end -- decompress frame data function sandbox_core_compress_lz4.decompress(data, opt) local result, errors = lz4.decompress(data, opt) if not result and errors then raise(errors) end return result end -- compress file data function sandbox_core_compress_lz4.compress_file(srcpath, dstpath, opt) local result, errors = lz4.compress_file(srcpath, dstpath, opt) if not result and errors then raise(errors) end end -- decompress file data function sandbox_core_compress_lz4.decompress_file(srcpath, dstpath, opt) local result, errors = lz4.decompress_file(srcpath, dstpath, opt) if not result and errors then raise(errors) end end -- compress block data function sandbox_core_compress_lz4.block_compress(data, opt) local result, errors = lz4.block_compress(data, opt) if not result and errors then raise(errors) end return result end -- decompress block data function sandbox_core_compress_lz4.block_decompress(data, realsize, opt) local result, errors = lz4.block_decompress(data, realsize, opt) if not result and errors then raise(errors) end return result end -- new compress stream function sandbox_core_compress_lz4.compress_stream(opt) local result, errors = lz4.compress_stream(opt) if not result and errors then raise(errors) end return _cstream_wrap(result) end -- new a decompress stream function sandbox_core_compress_lz4.decompress_stream(opt) local result, errors = lz4.decompress_stream(opt) if not result and errors then raise(errors) end return _dstream_wrap(result) end -- return module return sandbox_core_compress_lz4
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/platform/menu.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file menu.lua -- -- define module local sandbox_core_platform_menu = sandbox_core_platform_menu or {} -- load modules local menu = require("platform/menu") local raise = require("sandbox/modules/raise") -- get the platform menu options for the given action: config or global function sandbox_core_platform_menu.options(action) -- get it local options, errors = menu.options(action) if not options then raise(errors) end -- ok? return options end -- return module return sandbox_core_platform_menu
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/platform/platform.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file platform.lua -- -- define module local sandbox_core_platform = sandbox_core_platform or {} -- load modules local platform = require("platform/platform") local raise = require("sandbox/modules/raise") -- load the current platform function sandbox_core_platform.load(plat, arch) local instance, errors = platform.load(plat, arch) if not instance then raise(errors) end return instance end -- get the platform os function sandbox_core_platform.os(plat, arch) return platform.os(plat, arch) end -- get the all platforms function sandbox_core_platform.plats() return assert(platform.plats()) end -- get the all toolchains function sandbox_core_platform.toolchains() return assert(platform.toolchains()) end -- get the all architectures for the given platform function sandbox_core_platform.archs(plat, arch) return platform.archs(plat, arch) end -- get the current platform configuration function sandbox_core_platform.get(name, plat, arch) return platform.get(name, plat, arch) end -- get the platform tool from the kind -- -- e.g. cc, cxx, mm, mxx, as, ar, ld, sh, .. -- function sandbox_core_platform.tool(toolkind, plat, arch) return platform.tool(toolkind, plat, arch) end -- get the current platform tool configuration function sandbox_core_platform.toolconfig(name, plat, arch) return platform.toolconfig(name, plat, arch) end -- return module return sandbox_core_platform
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/package/repository.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file repository.lua -- -- define module local sandbox_core_package_repository = sandbox_core_package_repository or {} -- load modules local global = require("base/global") local project = require("project/project") local localcache = require("cache/localcache") local repository = require("package/repository") local raise = require("sandbox/modules/raise") local import = require("sandbox/modules/import") -- inherit some builtin interfaces sandbox_core_package_repository.directory = repository.directory sandbox_core_package_repository.get = repository.get sandbox_core_package_repository.load = repository.load -- add repository url to the given name function sandbox_core_package_repository.add(name, url, branch, is_global) local ok, errors = repository.add(name, url, branch, is_global) if not ok then raise(errors) end end -- remove repository from gobal or local directory function sandbox_core_package_repository.remove(name, is_global) local ok, errors = repository.remove(name, is_global) if not ok then raise(errors) end end -- clear all repositories from global or local directory function sandbox_core_package_repository.clear(is_global) local ok, errors = repository.clear(is_global) if not ok then raise(errors) end end -- get all repositories from global or local directory function sandbox_core_package_repository.repositories(is_global) -- load repositories from repository cache local repositories = {} for name, repoinfo in pairs(table.wrap(repository.repositories(is_global))) do local url = repoinfo local branch = nil if type(repoinfo) == "table" then url = repoinfo[1] branch = repoinfo[2] end local repo = repository.load(name, url, branch, is_global) if repo then table.insert(repositories, repo) end end -- load repositories from project file -- -- in project xmake.lua: -- -- add_repositories("other-repo https://github.com/other/other-repo.git dev") -- add_repositories("other-repo dirname", {rootdir = os.scriptdir()}) -- if not is_global then for _, repo in ipairs(table.wrap(project.get("repositories"))) do local repoinfo = repo:split('%s') if #repoinfo <= 3 then local name = repoinfo[1] local url = repoinfo[2] local branch = repoinfo[3] local rootdir = project.extraconf("repositories", repo, "rootdir") if url and rootdir and not path.is_absolute(url) and not url:find(":", 1, true) then url = path.join(rootdir, url) end local repo = repository.load(name, url, branch, is_global) if repo then table.insert(repositories, repo) end else raise("invalid repository: %s", repo) end end end -- add global xmake repositories if is_global then -- get the network mode local network = project.policy("network.mode") if network == nil then network = global.get("network") end -- add artifacts urls local artifacts_urls = localcache.cache("repository"):get("artifacts_urls") if not artifacts_urls then local binary_repo = os.getenv("XMAKE_BINARY_REPO") if binary_repo then artifacts_urls = {binary_repo} else artifacts_urls = {"https://github.com/xmake-mirror/build-artifacts.git", "https://gitlab.com/xmake-mirror/build-artifacts.git", "https://gitee.com/xmake-mirror/build-artifacts.git"} if network ~= "private" then import("net.fasturl") fasturl.add(artifacts_urls) artifacts_urls = fasturl.sort(artifacts_urls) localcache.cache("repository"):set("artifacts_urls", artifacts_urls) localcache.cache("repository"):save() end end end if #artifacts_urls > 0 then local repo = repository.load("build-artifacts", artifacts_urls[1], "main", true) if repo then table.insert(repositories, repo) end end -- add main urls local mainurls = localcache.cache("repository"):get("mainurls") if not mainurls then local mainrepo = os.getenv("XMAKE_MAIN_REPO") if mainrepo then mainurls = {mainrepo} else mainurls = {"https://github.com/xmake-io/xmake-repo.git", "https://gitlab.com/tboox/xmake-repo.git", "https://gitee.com/tboox/xmake-repo.git"} if network ~= "private" then import("net.fasturl") fasturl.add(mainurls) mainurls = fasturl.sort(mainurls) localcache.cache("repository"):set("mainurls", mainurls) localcache.cache("repository"):save() end end end if #mainurls > 0 then local repo = repository.load("xmake-repo", mainurls[1], "master", true) if repo then table.insert(repositories, repo) end end end -- load repository from builtin program directory if is_global then local repo = repository.load("builtin-repo", path.join(os.programdir(), "repository"), nil, true) if repo then table.insert(repositories, repo) end end -- get the repositories return repositories end -- return module return sandbox_core_package_repository
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/package/package.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file package.lua -- -- define module local sandbox_core_package_package = sandbox_core_package_package or {} -- load modules local project = require("project/project") local package = require("package/package") local raise = require("sandbox/modules/raise") -- inherit some builtin interfaces sandbox_core_package_package.cachedir = package.cachedir sandbox_core_package_package.installdir = package.installdir sandbox_core_package_package.searchdirs = package.searchdirs sandbox_core_package_package.targetplat = package.targetplat sandbox_core_package_package.targetarch = package.targetarch sandbox_core_package_package.apis = package.apis sandbox_core_package_package.new = package.new -- load the package from the project file function sandbox_core_package_package.load_from_project(packagename) local instance, errors = package.load_from_project(packagename, project) if errors then raise(errors) end return instance end -- load the package from the system function sandbox_core_package_package.load_from_system(packagename) local instance, errors = package.load_from_system(packagename) if errors then raise(errors) end return instance end -- load the package from repositories function sandbox_core_package_package.load_from_repository(packagename, packagedir, opt) local instance, errors = package.load_from_repository(packagename, packagedir, opt) if not instance then raise(errors) end return instance end -- return module return sandbox_core_package_package
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/dialog.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file dialog.lua -- -- return module: dialog return require("ui/dialog")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/textdialog.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file textdialog.lua -- -- return module: textdialog return require("ui/textdialog")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/point.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file point.lua -- -- return module: point return require("ui/point")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/button.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file button.lua -- -- return module: button return require("ui/button")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/rect.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file rect.lua -- -- return module: rect return require("ui/rect")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/application.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source application. -- -- @author ruki -- @file application.lua -- -- load module: application return require("ui/application")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/canvas.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file canvas.lua -- -- load modules return require("ui/canvas")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/curses.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file curses.lua -- -- return module: curses return require("ui/curses")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/inputdialog.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file inputdialog.lua -- -- return module: inputdialog return require("ui/inputdialog")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/desktop.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file desktop.lua -- -- return module: desktop return require("ui/desktop")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/mconfdialog.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file mconfdialog.lua -- -- return module: mconfdialog return require("ui/mconfdialog")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/object.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file object.lua -- -- return module: object return require("ui/object")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/log.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file log.lua -- -- return module: log return require("ui/log")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/textedit.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file textedit.lua -- -- return module: textedit return require("ui/textedit")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/menuconf.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file menuconf.lua -- -- return module: menuconf return require("ui/menuconf")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/action.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file action.lua -- -- return module: action return require("ui/action")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/statusbar.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file statusbar.lua -- -- return module: statusbar return require("ui/statusbar")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/view.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file view.lua -- -- return module: view return require("ui/view")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/choicebox.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file choicebox.lua -- -- return module: choicebox return require("ui/choicebox")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/label.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file label.lua -- -- return module: label return require("ui/label")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/textarea.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file textarea.lua -- -- return module: textarea return require("ui/textarea")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/window.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file window.lua -- -- return module: window return require("ui/window")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/panel.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file panel.lua -- -- return module: panel return require("ui/panel")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/menubar.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file menubar.lua -- -- return module: menubar return require("ui/menubar")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/boxdialog.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file boxdialog.lua -- -- return module: boxdialog return require("ui/boxdialog")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/border.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file border.lua -- -- return module: border return require("ui/border")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/choicedialog.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file choicedialog.lua -- -- return module: choicedialog return require("ui/choicedialog")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/event.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file event.lua -- -- return module: event return require("ui/event")
0
repos/xmake/xmake/core/sandbox/modules/import/core
repos/xmake/xmake/core/sandbox/modules/import/core/ui/program.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source program. -- -- @author ruki -- @file program.lua -- -- return module: program return require("ui/program")
0
repos/xmake/xmake/core/sandbox/modules/import
repos/xmake/xmake/core/sandbox/modules/import/lib/lni.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file lni.lua -- -- return module return _lni or {}
0
repos/xmake/xmake/core/sandbox/modules/import/lib
repos/xmake/xmake/core/sandbox/modules/import/lib/luajit/bit.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file bit.lua -- if xmake._LUAJIT then return require("bit") end
0
repos/xmake/xmake/core/sandbox/modules/import/lib
repos/xmake/xmake/core/sandbox/modules/import/lib/luajit/bcsave.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file bcsave.lua -- -- load modules local io = require("base/io") local string = require("base/string") local raise = require("sandbox/modules/raise") if not xmake._LUAJIT then return end -- save lua file to bitcode file -- -- @param luafile the lua file -- @param bcfile the bitcode file -- @param opt the arguments option, e.g. {strip = true, displaypath = "/xxx/a.lua", nocache = true} -- function main(luafile, bcfile, opt) opt = opt or {} local result, errors = loadfile(luafile, "bt", {displaypath = opt.displaypath, nocache = opt.nocache}) if not result then raise(errors) end result, errors = string._dump(result, opt.strip) if not result then raise(errors) end result, errors = io.writefile(bcfile, result) if not result then raise(errors) end end return main
0
repos/xmake/xmake/core/sandbox/modules/import/lib
repos/xmake/xmake/core/sandbox/modules/import/lib/luajit/jit.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file jit.lua -- if xmake._LUAJIT then return require("jit") end
0
repos/xmake/xmake/core/sandbox/modules/import/lib
repos/xmake/xmake/core/sandbox/modules/import/lib/luajit/ffi.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file ffi.lua -- if xmake._LUAJIT then return require("ffi") end
0
repos/xmake/xmake/core/sandbox/modules/import/lib
repos/xmake/xmake/core/sandbox/modules/import/lib/lua/package.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file package.lua -- -- load modules local string = require("base/string") local raise = require("sandbox/modules/raise") -- define module local sandbox_lib_lua_package = sandbox_lib_lua_package or {} -- load lua module from the dynamic library -- -- @param libfile the lib file, e.g. foo.dll, libfoo.so -- @param symbol the export symbol name, e.g. luaopen_xxx -- function sandbox_lib_lua_package.loadlib(libfile, symbol) local script, errors = package.loadlib(libfile, symbol) if not script then raise(errors) end return script end return sandbox_lib_lua_package
0
repos/xmake/xmake/core/sandbox/modules/import/lib
repos/xmake/xmake/core/sandbox/modules/import/lib/detect/find_path.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file find_path.lua -- -- define module local sandbox_lib_detect_find_path = sandbox_lib_detect_find_path or {} -- load modules local os = require("base/os") local path = require("base/path") local table = require("base/table") local profiler = require("base/profiler") local raise = require("sandbox/modules/raise") local vformat = require("sandbox/modules/vformat") -- find the given file path or directory function sandbox_lib_detect_find_path._find(filedir, name) -- find the first path local results = os.filedirs(path.join(filedir, name), function (file, isdir) return false end) if results and #results > 0 then local filepath = results[1] if filepath then -- we need to translate name first, https://github.com/xmake-io/xmake-repo/issues/1315 local p = filepath:lastof(path.pattern(path.translate(name))) if p then filepath = path.translate(filepath:sub(1, p - 1)) if os.isdir(filepath) then return filepath else return path.directory(filepath) end end end end end -- find path -- -- @param name the path name -- @param paths the search paths (e.g. dirs, paths, winreg paths) -- @param opt the options, e.g. {suffixes = {"/aa", "/bb"}} -- -- @return the path -- -- @code -- -- local p = find_path("include/test.h", { "/usr", "/usr/local"}) -- -> /usr/local ("/usr/local/include/test.h") -- -- local p = find_path("include/*.h", { "/usr", "/usr/local/**"}) -- local p = find_path("lib/xxx", { "$(env PATH)", "$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\XXXX;Name)"}) -- local p = find_path("lib/xxx", { "$(env PATH)", function () return val("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\XXXX;Name"):match("\"(.-)\"") end}) -- -- @endcode -- function sandbox_lib_detect_find_path.main(name, paths, opt) -- init options opt = opt or {} -- find path local results profiler:enter("find_path", name) local suffixes = table.wrap(opt.suffixes) for _, _path in ipairs(table.wrap(paths)) do -- format path for builtin variables if type(_path) == "function" then local ok, result_or_errors = sandbox.load(_path) if ok then _path = result_or_errors or "" else raise(result_or_errors) end else _path = vformat(_path) end -- find file with suffixes if #suffixes > 0 then for _, suffix in ipairs(suffixes) do local filedir = path.join(_path, suffix) results = sandbox_lib_detect_find_path._find(filedir, name) if results then goto found end end else -- find file in the given path results = sandbox_lib_detect_find_path._find(_path, name) if results then goto found end end end ::found:: profiler:leave("find_path", name) return results end -- return module return sandbox_lib_detect_find_path
0
repos/xmake/xmake/core/sandbox/modules/import/lib
repos/xmake/xmake/core/sandbox/modules/import/lib/detect/find_directory.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file find_directory.lua -- -- define module local sandbox_lib_detect_find_directory = sandbox_lib_detect_find_directory or {} -- load modules local os = require("base/os") local path = require("base/path") local utils = require("base/utils") local table = require("base/table") local raise = require("sandbox/modules/raise") local vformat = require("sandbox/modules/vformat") -- find directory -- -- @param name the directory name -- @param paths the search paths (e.g. dirs, paths, winreg paths) -- @param opt the options, e.g. {suffixes = {"/aa", "/bb"}} -- -- @return the directory path -- -- @code -- -- local dir = find_directory("bin", { "/usr", "/usr/local"}) -- local dir = find_directory("xxx/test", { "/usr/include", "/usr/local/include/**"}) -- local dir = find_directory("xxx/test", { "$(env PATH)", "$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\XXXX;Name)"}) -- local dir = find_directory("xxx/test/dir*", { "$(env PATH)", function () return val("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\XXXX;Name"):match("\"(.-)\"") end}) -- -- @endcode -- function sandbox_lib_detect_find_directory.main(name, paths, opt) -- init options opt = opt or {} -- init paths paths = table.wrap(paths) -- append suffixes to paths local suffixes = table.wrap(opt.suffixes) if #suffixes > 0 then local paths_new = {} for _, parent in ipairs(paths) do for _, suffix in ipairs(suffixes) do table.insert(paths_new, path.join(parent, suffix)) end end paths = paths_new end -- find file for _, _path in ipairs(paths) do -- format path for builtin variables if type(_path) == "function" then local ok, results = sandbox.load(_path) if ok then _path = results or "" else raise(results) end else _path = vformat(_path) end -- find the first directory local results = os.dirs(path.join(_path, name), function (file, isdir) return false end) if results and #results > 0 then return results[1] end end end -- return module return sandbox_lib_detect_find_directory
0
repos/xmake/xmake/core/sandbox/modules/import/lib
repos/xmake/xmake/core/sandbox/modules/import/lib/detect/find_file.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file find_file.lua -- -- define module local sandbox_lib_detect_find_file = sandbox_lib_detect_find_file or {} -- load modules local os = require("base/os") local path = require("base/path") local utils = require("base/utils") local table = require("base/table") local profiler = require("base/profiler") local raise = require("sandbox/modules/raise") local vformat = require("sandbox/modules/vformat") -- find the given file path or directory function sandbox_lib_detect_find_file._find(filedir, name) -- get file path local filepath = nil if os.isfile(filedir) then filepath = filedir else filepath = path.join(filedir, name) end -- find the first file local results = os.files(filepath, function (file, isdir) return false end) if results and #results > 0 then return results[1] end end -- find file -- -- @param name the file name -- @param paths the search paths (e.g. dirs, paths, winreg paths) -- @param opt the options, e.g. {suffixes = {"/aa", "/bb"}} -- -- @return the file path -- -- @code -- -- local file = find_file("ccache", { "/usr/bin", "/usr/local/bin"}) -- local file = find_file("test.h", { "/usr/include", "/usr/local/include/**"}) -- local file = find_file("xxx.h", { "$(env PATH)", "$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\XXXX;Name)"}) -- local file = find_file("xxx.h", { "$(env PATH)", function () return val("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\XXXX;Name"):match("\"(.-)\"") end}) -- -- @endcode -- function sandbox_lib_detect_find_file.main(name, paths, opt) -- init options opt = opt or {} -- find file profiler:enter("find_file", name) local results local suffixes = table.wrap(opt.suffixes) for _, _path in ipairs(table.wrap(paths)) do -- format path for builtin variables if type(_path) == "function" then local ok, result_or_errors = sandbox.load(_path) if ok then _path = result_or_errors or "" else raise(result_or_errors) end elseif type(_path) == "string" then if _path:match("^%$%(env .+%)$") then _path = path.splitenv(vformat(_path)) else _path = vformat(_path) end end for _, _s_path in ipairs(table.wrap(_path)) do if #_s_path > 0 then -- find file with suffixes if #suffixes > 0 then for _, suffix in ipairs(suffixes) do local filedir = path.join(_s_path, suffix) results = sandbox_lib_detect_find_file._find(filedir, name) if results then goto found end end else -- find file in the given path results = sandbox_lib_detect_find_file._find(_s_path, name) if results then goto found end end end end end ::found:: profiler:leave("find_file", name) return results end -- return module return sandbox_lib_detect_find_file
0
repos/xmake/xmake/core/sandbox/modules/import/lib
repos/xmake/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file find_program.lua -- -- define module local sandbox_lib_detect_find_program = sandbox_lib_detect_find_program or {} -- load modules local os = require("base/os") local path = require("base/path") local option = require("base/winos") local table = require("base/table") local utils = require("base/utils") local option = require("base/option") local profiler = require("base/profiler") local project = require("project/project") local detectcache = require("cache/detectcache") local sandbox = require("sandbox/sandbox") local package = require("package/package") local raise = require("sandbox/modules/raise") local vformat = require("sandbox/modules/vformat") local scheduler = require("sandbox/modules/import/core/base/scheduler") -- do check function sandbox_lib_detect_find_program._do_check(program, opt) -- do not attempt to run program? check it fastly if opt.norun then return os.isfile(program) end -- no check script? attempt to run it directly if not opt.check then local ok, errors = os.runv(program, {"--version"}, {envs = opt.envs, shell = opt.shell}) if not ok and option.get("verbose") and option.get("diagnosis") then utils.cprint("${color.warning}checkinfo: ${clear dim}" .. errors) end return ok end -- check it local ok = false local errors = nil if type(opt.check) == "string" then ok, errors = os.runv(program, {opt.check}, {envs = opt.envs, shell = opt.shell}) elseif type(opt.check) == "table" then ok, errors = os.runv(program, opt.check, {envs = opt.envs, shell = opt.shell}) else ok, errors = sandbox.load(opt.check, program) end -- check failed? print verbose error info if not ok and option.get("verbose") and option.get("diagnosis") then utils.cprint("${color.warning}checkinfo: ${clear dim}" .. errors) end return ok end -- check program function sandbox_lib_detect_find_program._check(program, opt) opt = opt or {} local findname = program if os.subhost() == "windows" then if not opt.shell and not program:endswith(".exe") and not program:endswith(".cmd") and not program:endswith(".bat") then findname = program .. ".exe" end elseif os.subhost() == "msys" and os.isfile(program) and os.filesize(program) < 256 then -- only a sh script on msys2? e.g. c:/msys64/usr/bin/7z -- we need to use sh to wrap it, otherwise os.exec cannot run it program = "sh " .. program findname = program end if sandbox_lib_detect_find_program._do_check(findname, opt) then return program -- check "zig c++" without ".exe" -- https://github.com/xmake-io/xmake/issues/2232 elseif findname ~= program and path.filename(program):find(" ", 1, true) and sandbox_lib_detect_find_program._do_check(program, opt) then return program end end -- find program from the given paths function sandbox_lib_detect_find_program._find_from_paths(name, paths, opt) -- attempt to check it from the given directories if not path.is_absolute(name) then for _, _path in ipairs(table.wrap(paths)) do -- format path for builtin variables if type(_path) == "function" then local ok, results = sandbox.load(_path) if ok then _path = results or "" else raise(results) end elseif type(_path) == "string" then if _path:match("^%$%(env .+%)$") then _path = path.splitenv(vformat(_path)) else _path = vformat(_path) end end for _, _s_path in ipairs(table.wrap(_path)) do -- get program path local program_path = nil if os.isfile(_s_path) then program_path = _s_path elseif os.isdir(_s_path) then program_path = path.join(_s_path, name) end -- the program path if program_path and (os.isexec(program_path) or os.isexec(program_path:split("%s")[1])) then local program_path_real = sandbox_lib_detect_find_program._check(program_path, opt) if program_path_real then return program_path_real end end end end end end -- find program from the xmake packages function sandbox_lib_detect_find_program._find_from_packages(name, opt) -- get the manifest file of package, e.g. ~/.xmake/packages/g/git/1.1.12/ed41d5327fad3fc06fe376b4a94f62ef/manifest.txt opt = opt or {} local installdir = opt.installdir or path.join(package.installdir(), name:sub(1, 1), name, opt.require_version, opt.buildhash) local manifest_file = path.join(installdir, "manifest.txt") if not os.isfile(manifest_file) then return end -- get install directory of this package local installdir = path.directory(manifest_file) -- init paths local paths = {} local manifest = io.load(manifest_file) if manifest and manifest.envs then local pathenvs = manifest.envs.PATH if pathenvs then for _, pathenv in ipairs(pathenvs) do table.insert(paths, path.join(installdir, pathenv)) end end end -- find it return sandbox_lib_detect_find_program._find_from_paths(name, paths, opt) end -- find program function sandbox_lib_detect_find_program._find(name, paths, opt) -- attempt to find it from the given directories local program_path = sandbox_lib_detect_find_program._find_from_paths(name, paths, opt) if program_path and opt.system ~= false then return program_path end -- attempt to find it from the xmake packages if opt.require_version and opt.buildhash and opt.system ~= true then return sandbox_lib_detect_find_program._find_from_packages(name, opt) end -- we will not continue to find system program if opt.system == false then return end -- attempt to find it from regists if os.host() == "windows" then local program_name = name:lower() if not program_name:endswith(".exe") then program_name = program_name .. ".exe" end program_path = winos.registry_query("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" .. program_name) if program_path then program_path = program_path:trim() if os.isexec(program_path) then local program_path_real = sandbox_lib_detect_find_program._check(program_path, opt) if program_path_real then return program_path_real end end end else -- attempt to find it use `which program` command local ok, program_path = os.iorunv("which", {name}) if ok and program_path then program_path = program_path:trim() local program_path_real = sandbox_lib_detect_find_program._check(program_path, opt) if program_path_real then return program_path_real end end end -- attempt to find it from the some default $PATH and system directories local syspaths = {} --[[ local envpaths = os.getenv("PATH") if envpaths then table.join2(syspaths, path.splitenv(envpaths)) end]] if os.host() ~= "windows" or os.is_subhost("msys", "cygwin") then table.insert(syspaths, "/usr/local/bin") table.insert(syspaths, "/usr/bin") end if #syspaths > 0 then program_path = sandbox_lib_detect_find_program._find_from_paths(name, syspaths, opt) if program_path then return program_path end end -- attempt to find it directly in current environment -- -- @note must be detected at the end, because full path is more accurate -- local program_path_real = sandbox_lib_detect_find_program._check(name, opt) if program_path_real then return program_path_real end -- attempt to find it use `where.exe program.exe` command -- -- and we need to add `.exe` suffix to avoid find some incorrect programs. e.g. pkg-config.bat if os.host() == "windows" then local program_name = name:lower() if not program_name:endswith(".exe") then program_name = program_name .. ".exe" end local ok, wherepaths = os.iorunv("where.exe", {program_name}) if ok and wherepaths then for _, program_path in ipairs(wherepaths:split("\n")) do program_path = program_path:trim() if #program_path > 0 then local program_path_real = sandbox_lib_detect_find_program._check(program_path, opt) if program_path_real then return program_path_real end end end end end end -- find program -- -- @param name the program name -- @param opt the options, e.g. {paths = {"/usr/bin"}, check = function (program) os.run("%s -h", program) end, verbose = true, force = true, cachekey = "xxx"} -- - opt.paths the program paths (e.g. dirs, paths, winreg paths, script paths) -- - opt.check the check script or command -- - opt.norun do not attempt to run program to check program fastly -- - opt.system true: only find it from system, false: only find it from xmake/packages -- -- @return the program name or path -- -- @code -- -- local program = find_program("ccache") -- local program = find_program("ccache", {paths = {"/usr/bin", "/usr/local/bin"}}) -- local program = find_program("ccache", {paths = {"/usr/bin", "/usr/local/bin"}, check = "--help"}) -- simple check command: ccache --help -- local program = find_program("ccache", {paths = {"/usr/bin", "/usr/local/bin"}, check = function (program) os.run("%s -h", program) end}) -- local program = find_program("ccache", {paths = {"$(env PATH)", "$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger)"}}) -- local program = find_program("ccache", {paths = {"$(env PATH)", function () return "/usr/local/bin" end}}) -- local program = find_program("ccache", {envs = {PATH = "xxx"}}) -- -- @endcode -- function sandbox_lib_detect_find_program.main(name, opt) opt = opt or {} -- init cachekey local cachekey = "find_program" if opt.cachekey then cachekey = cachekey .. "_" .. opt.cachekey end -- @see https://github.com/xmake-io/xmake/issues/4645 -- @note avoid detect the same program in the same time leading to deadlock if running in the coroutine (e.g. ccache) local lockname = cachekey .. name scheduler.co_lock(lockname) -- attempt to get result from cache first local result = detectcache:get2(cachekey, name) if result ~= nil and not opt.force then scheduler.co_unlock(lockname) return result and result or nil end -- get paths from the opt.envs.PATH -- @note the wrong `pathes` word will be discarded, but the interface parameters will still be compatible local envs = opt.envs local paths = opt.paths or opt.pathes if envs and (envs.PATH or envs.path) then local pathenv = envs.PATH or envs.path if type(pathenv) == "string" then pathenv = path.splitenv(pathenv) end paths = table.join(table.wrap(opt.paths or opt.pathes), pathenv) end -- find executable program profiler:enter("find_program", name) result = sandbox_lib_detect_find_program._find(name, paths, opt) profiler:leave("find_program", name) -- cache result detectcache:set2(cachekey, name, result and result or false) detectcache:save() -- trace if option.get("verbose") or opt.verbose then if result then utils.cprint("checking for %s ... ${color.success}%s", name, (name == result and "${text.success}" or result)) else utils.cprint("checking for %s ... ${color.nothing}${text.nothing}", name) end end scheduler.co_unlock(lockname) return result end -- return module return sandbox_lib_detect_find_program
0
repos/xmake/xmake/core/sandbox/modules/import/lib
repos/xmake/xmake/core/sandbox/modules/import/lib/detect/find_library.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file find_library.lua -- -- define module local sandbox_lib_detect_find_library = sandbox_lib_detect_find_library or {} -- load modules local os = require("base/os") local path = require("base/path") local utils = require("base/utils") local table = require("base/table") local config = require("project/config") local target = require("project/target") local raise = require("sandbox/modules/raise") local import = require("sandbox/modules/import") local find_file = import("lib.detect.find_file") -- find library -- -- @param names the library names -- @param paths the search paths -- @param opt the options, e.g. {kind = "static/shared", suffixes = {"/aa", "/bb"}} -- -- @return {kind = "static", link = "crypto", linkdir = "/usr/local/lib", filename = "libcrypto.a", plat = ..} -- -- @code -- -- local library = find_library({"crypto", "cryp*"}, {"/usr/lib", "/usr/local/lib"}) -- local library = find_library("crypto", {"/usr/lib", "/usr/local/lib"}, {kind = "static"}) -- -- @endcode -- function sandbox_lib_detect_find_library.main(names, paths, opt) -- no paths? if not paths or #paths == 0 then return end -- find library file from the given paths opt = opt or {} local kinds = opt.kind or {"static", "shared"} for _, name in ipairs(table.wrap(names)) do for _, kind in ipairs(table.wrap(kinds)) do local filepath = find_file(target.filename(name, kind, {plat = opt.plat}), paths, opt) if opt.plat == "mingw" then if not filepath and kind == "shared" then -- for implib/mingw, e.g. libxxx.dll.a filepath = find_file(target.filename(name, kind, {plat = opt.plat}) .. ".a", paths, opt) end if not filepath then -- in order to be compatible with mingw/windows library with .lib filepath = find_file(target.filename(name, kind, {plat = "windows"}), paths, opt) end end if filepath then local filename = path.filename(filepath) local linkname = target.linkname(filename, {plat = opt.plat}) return {kind = kind, filename = filename, linkdir = path.directory(filepath), link = linkname} end end end end -- return module return sandbox_lib_detect_find_library
0
repos/xmake/xmake/core/sandbox/modules/import/lib
repos/xmake/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file find_programver.lua -- -- define module local sandbox_lib_detect_find_programver = sandbox_lib_detect_find_programver or {} -- load modules local os = require("base/os") local path = require("base/path") local table = require("base/table") local utils = require("base/utils") local option = require("base/option") local semver = require("base/semver") local profiler = require("base/profiler") local project = require("project/project") local detectcache = require("cache/detectcache") local sandbox = require("sandbox/sandbox") local raise = require("sandbox/modules/raise") local scheduler = require("sandbox/modules/import/core/base/scheduler") -- find program version -- -- @param program the program -- @param opt the options, e.g. {command = "--version", parse = "(%d+%.?%d*%.?%d*.-)%s", verbose = true, force = true, cachekey = "xxx"} -- - opt.command the version command string or script, default: --version -- - opt.parse the version parse script or lua match pattern -- -- @return the version string -- -- @code -- local version = find_programver("ccache") -- local version = find_programver("ccache", {command = "-v"}) -- local version = find_programver("ccache", {command = "--version", parse = "(%d+%.?%d*%.?%d*.-)%s"}) -- local version = find_programver("ccache", {command = "--version", parse = function (output) return output:match("(%d+%.?%d*%.?%d*.-)%s") end}) -- local version = find_programver("ccache", {command = function () return os.iorun("ccache --version") end}) -- @endcode -- function sandbox_lib_detect_find_programver.main(program, opt) opt = opt or {} -- init cachekey local cachekey = "find_programver" if opt.cachekey then cachekey = cachekey .. "_" .. opt.cachekey end -- @see https://github.com/xmake-io/xmake/issues/4645 -- @note avoid detect the same program in the same time leading to deadlock if running in the coroutine (e.g. ccache) local lockname = cachekey .. program scheduler.co_lock(lockname) -- attempt to get result from cache first local result = detectcache:get2(cachekey, program) if result ~= nil and not opt.force then scheduler.co_unlock(lockname) return result and result or nil end -- attempt to get version output info profiler:enter("find_programver", program) local ok = false local outdata = nil local command = opt.command if type(command) == "function" then ok, outdata = sandbox.load(command) if not ok and outdata and option.get("diagnosis") then utils.cprint("${color.warning}checkinfo: ${clear dim}" .. outdata) end elseif type(command) == "table" then ok, outdata = os.iorunv(program, command, {envs = opt.envs}) else ok, outdata = os.iorunv(program, {command or "--version"}, {envs = opt.envs}) end profiler:leave("find_programver", program) -- find version info if ok and outdata and #outdata > 0 then local parse = opt.parse if type(parse) == "function" then ok, result = sandbox.load(parse, outdata) if not ok and result and option.get("diagnosis") then utils.cprint("${color.warning}checkinfo: ${clear dim}" .. result) result = nil end elseif parse == nil or type(parse) == "string" then result = semver.match(outdata, 1, parse) if result then result = result:rawstr() end end end -- save result detectcache:set2(cachekey, program, result and result or false) detectcache:save() scheduler.co_unlock(lockname) return result end -- return module return sandbox_lib_detect_find_programver
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/table.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file table.lua -- -- load module return require("sandbox/modules/table")
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/linuxos.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file linuxos.lua -- -- load modules local linuxos = require("base/linuxos") -- define module local sandbox_linuxos = sandbox_linuxos or {} -- export some readonly interfaces sandbox_linuxos.name = linuxos.name sandbox_linuxos.version = linuxos.version sandbox_linuxos.kernelver = linuxos.kernelver -- return module return sandbox_linuxos
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/ipairs.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file ipairs.lua -- -- load modules return require("sandbox/modules/ipairs")
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/unpack.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file table.unpack.lua -- -- load module return require("base/table").unpack
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/string.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file string.lua -- -- load module return require("sandbox/modules/string")
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/tostring.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file tostring.lua -- -- load module return tostring
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/type.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file type.lua -- -- load module return type
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/print.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file print.lua -- -- load modules local table = require("base/table") local try = require("sandbox/modules/try") local catch = require("sandbox/modules/catch") -- print format string function _print(format, ...) -- print format string if type(format) == "string" and format:find("%", 1, true) then local args = {...} try { function () -- attempt to print format string first io.write(string.format(format, table.unpack(args)) .. "\n") end, catch { function () -- print multi-variables with raw lua action print(format, table.unpack(args)) end } } else -- print multi-variables with raw lua action print(format, ...) end end -- load module return _print
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/printf.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file printf.lua -- -- printf format string without newline function _printf(format, ...) -- done io.write(string.format(format, ...)) end -- load module return _printf
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/macos.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file macos.lua -- -- load modules local macos = require("base/macos") -- define module local sandbox_macos = sandbox_macos or {} -- export some readonly interfaces sandbox_macos.version = macos.version -- return module return sandbox_macos
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/pairs.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file pairs.lua -- -- load modules return require("sandbox/modules/pairs")
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/winos.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file winos.lua -- -- load modules local winos = require("base/winos") -- define module local sandbox_winos = sandbox_winos or {} -- export some readonly interfaces sandbox_winos.registry_query = winos.registry_query sandbox_winos.registry_keys = winos.registry_keys sandbox_winos.registry_values = winos.registry_values sandbox_winos.logical_drives = winos.logical_drives sandbox_winos.version = winos.version -- return module return sandbox_winos
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/getenv.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file getenv.lua -- -- return module return require("sandbox/modules/os").getenv
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/os.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file os.lua -- -- load modules local os = require("base/os") local string = require("base/string") local interpreter = require("base/interpreter") -- define module local sandbox_os = sandbox_os or {} -- export some readonly interfaces sandbox_os.term = os.term sandbox_os.host = os.host sandbox_os.arch = os.arch sandbox_os.subhost = os.subhost sandbox_os.subarch = os.subarch sandbox_os.date = os.date sandbox_os.time = os.time sandbox_os.mtime = os.mtime sandbox_os.mclock = os.mclock sandbox_os.getenv = os.getenv sandbox_os.isdir = os.isdir sandbox_os.isfile = os.isfile sandbox_os.exists = os.exists sandbox_os.curdir = os.curdir sandbox_os.tmpdir = os.tmpdir sandbox_os.cpuinfo = os.cpuinfo sandbox_os.default_njob = os.default_njob sandbox_os.filesize = os.filesize sandbox_os.programdir = os.programdir sandbox_os.programfile = os.programfile sandbox_os.projectdir = os.projectdir sandbox_os.projectfile = os.projectfile -- match files function sandbox_os.files(pattern, ...) return os.files(string.format(pattern, ...)) end -- match directories function sandbox_os.dirs(pattern, ...) return os.dirs(string.format(pattern, ...)) end -- match file and directories function sandbox_os.filedirs(pattern, ...) return os.filedirs(string.format(pattern, ...)) end -- get the script directory function sandbox_os.scriptdir() local instance = interpreter.instance() assert(instance) return instance:scriptdir() end -- return module return sandbox_os
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/format.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file format.lua -- -- return module return string.format
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/tonumber.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file tonumber.lua -- -- load module return tonumber
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/path.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file path.lua -- -- load module return require("sandbox/modules/path")
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- load modules local xmake = require("base/xmake") -- define module local sandbox_xmake = sandbox_xmake or {} -- inherit some builtin interfaces sandbox_xmake.version = xmake.version sandbox_xmake.programdir = xmake.programdir sandbox_xmake.programfile = xmake.programfile sandbox_xmake.luajit = xmake.luajit -- return module return sandbox_xmake
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/is_host.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file is_host.lua -- -- return module return require("base/os").is_host
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/is_subhost.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file is_subhost.lua -- -- return module return require("base/os").is_subhost
0
repos/xmake/xmake/core/sandbox/modules
repos/xmake/xmake/core/sandbox/modules/interpreter/math.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file math.lua -- -- load module return require("sandbox/modules/math")
0
repos/xmake/xmake/core
repos/xmake/xmake/core/cache/memcache.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file memcache.lua -- -- define module: memcache local memcache = memcache or {} local _instance = _instance or {} -- load modules local table = require("base/table") -- new an instance function _instance.new(name) local instance = table.inherit(_instance) instance._NAME = name instance._DATA = {} return instance end -- get cache name function _instance:name() return self._NAME end -- get cache data function _instance:data() return self._DATA end -- get cache value in level/1 function _instance:get(key) return self._DATA[key] end -- get cache value in level/2 function _instance:get2(key1, key2) local value1 = self:get(key1) if value1 ~= nil then return value1[key2] end end -- get cache value in level/3 function _instance:get3(key1, key2, key3) local value2 = self:get2(key1, key2) if value2 ~= nil then return value2[key3] end end -- set cache value in level/1 function _instance:set(key, value) self._DATA[key] = value end -- set cache value in level/2 function _instance:set2(key1, key2, value2) local value1 = self:get(key1) if value1 == nil then value1 = {} self:set(key1, value1) end value1[key2] = value2 end -- set cache value in level/3 function _instance:set3(key1, key2, key3, value3) local value2 = self:get2(key1, key2) if value2 == nil then value2 = {} self:set2(key1, key2, value2) end value2[key3] = value3 end -- clear cache scopes function _instance:clear() self._DATA = {} end -- get cache instance function memcache.cache(cachename) local caches = memcache._CACHES if not caches then caches = {} memcache._CACHES = caches end local instance = caches[cachename] if not instance then instance = _instance.new(cachename) caches[cachename] = instance end return instance end -- get all caches function memcache.caches() return memcache._CACHES end -- get cache value in level/1 function memcache.get(cachename, key) return memcache.cache(cachename):get(key) end -- get cache value in level/2 function memcache.get2(cachename, key1, key2) return memcache.cache(cachename):get2(key1, key2) end -- get cache value in level/3 function memcache.get3(cachename, key1, key2, key3) return memcache.cache(cachename):get3(key1, key2, key3) end -- set cache value in level/1 function memcache.set(cachename, key, value) return memcache.cache(cachename):set(key, value) end -- set cache value in level/2 function memcache.set2(cachename, key1, key2, value) return memcache.cache(cachename):set2(key1, key2, value) end -- set cache value in level/3 function memcache.set3(cachename, key1, key2, key3, value) return memcache.cache(cachename):set3(key1, key2, key3, value) end -- clear the given cache, it will clear all caches if cache name is nil function memcache.clear(cachename) local caches = memcache.caches() if caches then for _, cache in pairs(caches) do if cachename then if cache:name() == cachename then cache:clear() end else cache:clear() end end end end -- return module: memcache return memcache
0
repos/xmake/xmake/core
repos/xmake/xmake/core/cache/globalcache.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file globalcache.lua -- -- define module: globalcache local globalcache = globalcache or {} local _instance = _instance or {} -- load modules local table = require("base/table") local io = require("base/io") local os = require("base/os") local path = require("base/path") local global = require("base/global") -- new an instance function _instance.new(name) local instance = table.inherit(_instance) instance._NAME = name instance:load() instance._DATA = instance._DATA or {} return instance end -- get cache name function _instance:name() return self._NAME end -- get cache data function _instance:data() return self._DATA end -- load cache function _instance:load() local result = io.load(path.join(global.cachedir(), self:name())) if result ~= nil then self._DATA = result end end -- save cache function _instance:save() local ok, errors = io.save(path.join(global.cachedir(), self:name()), self._DATA) if not ok then os.raise(errors) end end -- get cache value in level/1 function _instance:get(key) return self._DATA[key] end -- get cache value in level/2 function _instance:get2(key1, key2) local value1 = self:get(key1) if value1 ~= nil then return value1[key2] end end -- get cache value in level/3 function _instance:get3(key1, key2, key3) local value2 = self:get2(key1) if value2 ~= nil then return value2[key3] end end -- set cache value in level/1 function _instance:set(key, value) self._DATA[key] = value end -- set cache value in level/2 function _instance:set2(key1, key2, value2) local value1 = self:get(key1) if value1 == nil then value1 = {} self:set(key1, value1) end value1[key2] = value2 end -- set cache value in level/3 function _instance:set3(key1, key2, key3, value3) local value2 = self:get2(key1, key2) if value2 == nil then value2 = {} self:set2(key1, key2, value2) end value2[key3] = value3 end -- clear cache scopes function _instance:clear() self._DATA = {} end -- get cache instance function globalcache.cache(cachename) local caches = globalcache._CACHES if not caches then caches = {} globalcache._CACHES = caches end local instance = caches[cachename] if not instance then instance = _instance.new(cachename) caches[cachename] = instance end return instance end -- get all caches function globalcache.caches(opt) opt = opt or {} if opt.flush then for _, cachefile in ipairs(os.files(path.join(global.cachedir(), "*"))) do local cachename = path.filename(cachefile) globalcache.cache(cachename) end end return globalcache._CACHES end -- get cache value in level/1 function globalcache.get(cachename, key) return globalcache.cache(cachename):get(key) end -- get cache value in level/2 function globalcache.get2(cachename, key1, key2) return globalcache.cache(cachename):get2(key1, key2) end -- get cache value in level/3 function globalcache.get3(cachename, key1, key2, key3) return globalcache.cache(cachename):get3(key1, key2, key3) end -- set cache value in level/1 function globalcache.set(cachename, key, value) return globalcache.cache(cachename):set(key, value) end -- set cache value in level/2 function globalcache.set2(cachename, key1, key2, value) return globalcache.cache(cachename):set2(key1, key2, value) end -- set cache value in level/3 function globalcache.set3(cachename, key1, key2, key3, value) return globalcache.cache(cachename):set3(key1, key2, key3, value) end -- save the given cache, it will save all caches if cache name is nil function globalcache.save(cachename) if cachename then globalcache.cache(cachename):save() else local caches = globalcache.caches() if caches then for _, cache in pairs(caches) do cache:save() end end end end -- clear the given cache, it will clear all caches if cache name is nil function globalcache.clear(cachename) if cachename then globalcache.cache(cachename):clear() else local caches = globalcache.caches({flush = true}) if caches then for _, cache in pairs(caches) do cache:clear() end end end end -- return module: globalcache return globalcache
0
repos/xmake/xmake/core
repos/xmake/xmake/core/cache/global_detectcache.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file global_detectcache.lua -- return require("cache/globalcache").cache("detect")
0
repos/xmake/xmake/core
repos/xmake/xmake/core/cache/localcache.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file localcache.lua -- -- define module: localcache local localcache = localcache or {} local _instance = _instance or {} -- load modules local table = require("base/table") local io = require("base/io") local os = require("base/os") local path = require("base/path") local config = require("project/config") -- new an instance function _instance.new(name) local instance = table.inherit(_instance) instance._NAME = name instance:load() instance._DATA = instance._DATA or {} return instance end -- get cache name function _instance:name() return self._NAME end -- get cache data function _instance:data() return self._DATA end -- load cache function _instance:load() if os.isfile(os.projectfile()) or os.isdir(config.directory()) then local result = io.load(path.join(config.cachedir(), self:name())) if result ~= nil then self._DATA = result end end end -- save cache function _instance:save() -- for xmake project or trybuild mode if os.isfile(os.projectfile()) or os.isdir(config.directory()) then local ok, errors = io.save(path.join(config.cachedir(), self:name()), self._DATA) if not ok then os.raise(errors) end end end -- get cache value in level/1 function _instance:get(key) return self._DATA[key] end -- get cache value in level/2 function _instance:get2(key1, key2) local value1 = self:get(key1) if value1 ~= nil then return value1[key2] end end -- get cache value in level/3 function _instance:get3(key1, key2, key3) local value2 = self:get2(key1, key2) if value2 ~= nil then return value2[key3] end end -- set cache value in level/1 function _instance:set(key, value) self._DATA[key] = value end -- set cache value in level/2 function _instance:set2(key1, key2, value2) local value1 = self:get(key1) if value1 == nil then value1 = {} self:set(key1, value1) end value1[key2] = value2 end -- set cache value in level/3 function _instance:set3(key1, key2, key3, value3) local value2 = self:get2(key1, key2) if value2 == nil then value2 = {} self:set2(key1, key2, value2) end value2[key3] = value3 end -- clear cache scopes function _instance:clear() self._DATA = {} end -- get cache instance function localcache.cache(cachename) local caches = localcache._CACHES if not caches then caches = {} localcache._CACHES = caches end local instance = caches[cachename] if not instance then instance = _instance.new(cachename) caches[cachename] = instance end return instance end -- get all caches function localcache.caches(opt) opt = opt or {} if opt.flush then for _, cachefile in ipairs(os.files(path.join(config.cachedir(), "*"))) do local cachename = path.filename(cachefile) localcache.cache(cachename) end end return localcache._CACHES end -- get cache value in level/1 function localcache.get(cachename, key) return localcache.cache(cachename):get(key) end -- get cache value in level/2 function localcache.get2(cachename, key1, key2) return localcache.cache(cachename):get2(key1, key2) end -- get cache value in level/3 function localcache.get3(cachename, key1, key2, key3) return localcache.cache(cachename):get3(key1, key2, key3) end -- set cache value in level/1 function localcache.set(cachename, key, value) return localcache.cache(cachename):set(key, value) end -- set cache value in level/2 function localcache.set2(cachename, key1, key2, value) return localcache.cache(cachename):set2(key1, key2, value) end -- set cache value in level/3 function localcache.set3(cachename, key1, key2, key3, value) return localcache.cache(cachename):set3(key1, key2, key3, value) end -- save the given cache, it will save all caches if cache name is nil function localcache.save(cachename) if cachename then localcache.cache(cachename):save() else local caches = localcache.caches() if caches then for _, cache in pairs(caches) do cache:save() end end end end -- clear the given cache, it will clear all caches if cache name is nil function localcache.clear(cachename) if cachename then localcache.cache(cachename):clear() else local caches = localcache.caches({flush = true}) if caches then for _, cache in pairs(caches) do cache:clear() end end end end -- return module: localcache return localcache
0
repos/xmake/xmake/core
repos/xmake/xmake/core/cache/detectcache.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file detectcache.lua -- return require("cache/localcache").cache("detect")
0
repos/xmake/xmake/core
repos/xmake/xmake/core/theme/theme.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file theme.lua -- -- define module local theme = theme or {} local _instance = _instance or {} -- load modules local os = require("base/os") local path = require("base/path") local table = require("base/table") local interpreter = require("base/interpreter") local global = require("base/global") -- new an instance function _instance.new(name, info, rootdir) local instance = table.inherit(_instance) instance._NAME = name instance._INFO = info instance._ROOTDIR = rootdir return instance end -- get theme name function _instance:name() return self._NAME end -- get the theme configuration function _instance:get(name) return self._INFO:get(name) end -- the interpreter function theme._interpreter() -- the interpreter has been initialized? return it directly if theme._INTERPRETER then return theme._INTERPRETER end -- init interpreter local interp = interpreter.new() assert(interp) -- define apis interp:api_define(theme._apis()) -- save interpreter theme._INTERPRETER = interp -- ok? return interp end -- get theme apis function theme._apis() return { keyvalues = { -- theme.set_xxx "theme.set_color" , "theme.set_text" } } end -- get theme directories function theme.directories() -- init directories local dirs = theme._DIRS or { path.join(global.directory(), "themes") , path.join(os.programdir(), "themes") } -- save directories to cache theme._DIRS = dirs return dirs end -- find all themes function theme.names() local paths = {} for _, dir in ipairs(theme.directories()) do table.join2(paths, (os.files(path.join(dir, "*", "xmake.lua")))) end for i, v in ipairs(paths) do local value = path.split(v) paths[i] = value[#value - 1] end return paths end -- load the given theme function theme.load(name) -- find the theme script path local scriptpath = nil if name then for _, dir in ipairs(theme.directories()) do scriptpath = path.join(dir, name, "xmake.lua") if os.isfile(scriptpath) then break end end end -- not exists? uses the default theme if not scriptpath or not os.isfile(scriptpath) then scriptpath = path.join(os.programdir(), "themes", "default", "xmake.lua") end -- get interpreter local interp = theme._interpreter() -- load script local ok, errors = interp:load(scriptpath) if not ok then return nil, errors end -- load theme local results, errors = interp:make("theme", true, false) if not results and os.isfile(scriptpath) then return nil, errors end -- get result local result = results[name] if not result then return nil, string.format("the theme %s not found!", name) end -- new an instance local instance, errors = _instance.new(name, result, interp:rootdir()) if not instance then return nil, errors end -- save the current theme instance theme._THEME = instance return instance end -- get the current theme instance function theme.instance() return theme._THEME end -- get the given theme configuration function theme.get(name) local instance = theme._THEME if instance then return instance:get(name) end end -- return module return theme
0
repos/xmake/xmake/core
repos/xmake/xmake/core/project/cache.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file cache.lua -- -- define module local cache = cache or {} -- load modules local io = require("base/io") local os = require("base/os") local path = require("base/path") local table = require("base/table") local utils = require("base/utils") local config = require("project/config") local global = require("base/global") -- the cache instance -- -- @param scopename local.xxxx -- global.xxxx -- function cache._instance(scopename) -- check assert(scopename) -- init instances cache._INSTANCES = cache._INSTANCES or {} local instances = cache._INSTANCES -- this instance has been initialized? if instances[scopename] then return instances[scopename] end -- init instance local instance = table.inherit(cache) -- memory cache? if scopename:startswith("memory.") then instance._CACHEDATA = instance._CACHEDATA or {__version = xmake._VERSION_SHORT} instances[scopename] = instance return instance end -- check scopename if not scopename:find("local%.") and not scopename:find("global%.") then os.raise("invalid cache scope: %s", scopename) end -- make the cache path local cachepath = (scopename:gsub("%.", "/")) cachepath = (cachepath:gsub("^local%/", path.join(config.directory(), "cache") .. "/")) cachepath = (cachepath:gsub("^global%/", path.join(global.cachedir()) .. "/")) -- save the cache path instance._CACHEPATH = cachepath -- load the cache data local results = io.load(cachepath) if results then instance._CACHEDATA = results end instance._CACHEDATA = instance._CACHEDATA or {__version = xmake._VERSION_SHORT} -- save instance instances[scopename] = instance -- ok return instance end -- get the value function cache:get(name) return self._CACHEDATA[name] end -- set the value function cache:set(name, value) self._CACHEDATA[name] = value end -- clear all function cache:clear() self._CACHEDATA = {__version = xmake._VERSION_SHORT} end -- flush to cache file function cache:flush() -- flush the version self._CACHEDATA.__version = xmake._VERSION_SHORT -- memory cache? ignore it directly if not self._CACHEPATH then return end -- save to file local ok, errors = io.save(self._CACHEPATH, self._CACHEDATA) if not ok then os.raise(errors) end end -- return module return cache._instance
0
repos/xmake/xmake/core
repos/xmake/xmake/core/project/target.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file target.lua -- -- define module local target = target or {} local _instance = _instance or {} -- load modules local bit = require("base/bit") local os = require("base/os") local path = require("base/path") local hash = require("base/hash") local utils = require("base/utils") local table = require("base/table") local baseoption = require("base/option") local hashset = require("base/hashset") local deprecated = require("base/deprecated") local select_script = require("base/private/select_script") local match_copyfiles = require("base/private/match_copyfiles") local instance_deps = require("base/private/instance_deps") local is_cross = require("base/private/is_cross") local memcache = require("cache/memcache") local rule = require("project/rule") local option = require("project/option") local config = require("project/config") local policy = require("project/policy") local project_package = require("project/package") local tool = require("tool/tool") local linker = require("tool/linker") local compiler = require("tool/compiler") local toolchain = require("tool/toolchain") local platform = require("platform/platform") local environment = require("platform/environment") local language = require("language/language") local sandbox = require("sandbox/sandbox") local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- new a target instance function _instance.new(name, info) local instance = table.inherit(_instance) instance._NAME = name instance._INFO = info instance._CACHEID = 1 return instance end -- get memcache function _instance:_memcache() local cache = self._MEMCACHE if not cache then cache = memcache.cache("core.project.target." .. tostring(self)) self._MEMCACHE = cache end return cache end -- load rule, move cache to target function _instance:_load_rule(ruleinst, suffix) -- init cache local key = ruleinst:name() .. (suffix and ("_" .. suffix) or "") local cache = self._RULES_LOADED or {} -- do load if cache[key] == nil then local on_load = ruleinst:script("load" .. (suffix and ("_" .. suffix) or "")) if on_load then local ok, errors = sandbox.load(on_load, self) cache[key] = {ok, errors} else cache[key] = {true} end -- before_load has been deprecated if on_load and suffix == "before" then deprecated.add(ruleinst:name() .. ".on_load", ruleinst:name() .. ".before_load") end end -- save cache self._RULES_LOADED = cache -- return results local results = cache[key] if results then return results[1], results[2] end end -- load rules function _instance:_load_rules(suffix) for _, r in ipairs(self:orderules()) do local ok, errors = self:_load_rule(r, suffix) if not ok then return false, errors end end return true end -- do load target and rules function _instance:_load() -- do load with target rules local ok, errors = self:_load_rules() if not ok then return false, errors end -- do load for target local on_load = self:script("load") if on_load then ok, errors = sandbox.load(on_load, self) if not ok then return false, errors end end -- mark as loaded self._LOADED = true return true end -- do before_load for rules -- @note it's deprecated, please use on_load instead of before_load function _instance:_load_before() local ok, errors = self:_load_rules("before") if not ok then return false, errors end return true end -- do after_load target and rules function _instance:_load_after() -- enter the environments of the target packages local oldenvs = os.addenvs(self:pkgenvs()) -- do load for target local after_load = self:script("load_after") if after_load then local ok, errors = sandbox.load(after_load, self) if not ok then return false, errors end end -- do after_load with target rules local ok, errors = self:_load_rules("after") if not ok then return false, errors end -- leave the environments of the target packages os.setenvs(oldenvs) self._LOADED_AFTER = true return true end -- get the visibility, private: 1, interface: 2, public: 3 = 1 | 2 function _instance:_visibility(opt) local visibility = 1 if opt then if opt.interface then visibility = 2 elseif opt.public then visibility = 3 end end return visibility end -- update file rules -- -- if we add files in on_load() dynamically, we need to update file rules, -- otherwise it will cause: unknown source file: ... -- function _instance:_update_filerules() local rulenames = {} local extensions = {} for _, sourcefile in ipairs(table.wrap(self:get("files"))) do local extension = path.extension((sourcefile:gsub("|.*$", ""))) if not extensions[extension] then local lang = language.load_ex(extension) if lang and lang:rules() then table.join2(rulenames, lang:rules()) end extensions[extension] = true end end rulenames = table.unique(rulenames) for _, rulename in ipairs(rulenames) do local r = target._project() and target._project().rule(rulename) or rule.rule(rulename) if r then -- only add target rules if r:kind() == "target" then if not self:rule(rulename) then self:rule_add(r) for _, deprule in ipairs(r:orderdeps()) do if not self:rule(deprule:name()) then self:rule_add(deprule) end end end end end end end -- invalidate the previous cache function _instance:_invalidate(name) self._CACHEID = self._CACHEID + 1 self._POLICIES = nil self:_memcache():clear() -- we need to flush the source files cache if target/files are modified, e.g. `target:add("files", "xxx.c")` if name == "files" then self._SOURCEFILES = nil self._OBJECTFILES = nil self._SOURCEBATCHES = nil self:_update_filerules() elseif name == "deps" then self._DEPS = nil self._ORDERDEPS = nil self._INHERITDEPS = nil end if self._FILESCONFIG then self._FILESCONFIG[name] = nil end end -- build deps function _instance:_build_deps() if target._project() then local instances = target._project().targets() self._DEPS = self._DEPS or {} self._ORDERDEPS = self._ORDERDEPS or {} self._INHERITDEPS = self._INHERITDEPS or {} instance_deps.load_deps(self, instances, self._DEPS, self._ORDERDEPS, {self:name()}) -- @see https://github.com/xmake-io/xmake/issues/4689 instance_deps.load_deps(self, instances, {}, self._INHERITDEPS, {self:name()}, function (t, dep) local depinherit = t:extraconf("deps", dep:name(), "inherit") return depinherit == nil or depinherit end) end end -- is loaded? function _instance:_is_loaded() return self._LOADED end -- get values from target deps with {interface|public = ...} function _instance:_get_from_deps(name, result_values, result_sources, opt) local orderdeps = self:orderdeps({inherit = true}) local total = #orderdeps for idx, _ in ipairs(orderdeps) do local dep = orderdeps[total + 1 - idx] local values = dep:get(name, opt) if values ~= nil then table.insert(result_values, values) table.insert(result_sources, "dep::" .. dep:name()) end local dep_values = {} local dep_sources = {} dep:_get_from_options(name, dep_values, dep_sources, opt) dep:_get_from_packages(name, dep_values, dep_sources, opt) for idx, values in ipairs(dep_values) do local dep_source = dep_sources[idx] table.insert(result_values, values) table.insert(result_sources, "dep::" .. dep:name() .. "/" .. dep_source) end end end -- get values from target options with {interface|public = ...} function _instance:_get_from_options(name, result_values, result_sources, opt) for _, opt_ in ipairs(self:orderopts(opt)) do local values = opt_:get(name) if values ~= nil then table.insert(result_values, values) table.insert(result_sources, "option::" .. opt_:name()) end end end -- get values from target packages with {interface|public = ...} function _instance:_get_from_packages(name, result_values, result_sources, opt) local function _filter_libfiles(libfiles) local result = {} for _, libfile in ipairs(table.wrap(libfiles)) do if not libfile:endswith(".dll") then table.insert(result, libfile) end end return table.unwrap(result) end for _, pkg in ipairs(self:orderpkgs(opt)) do local configinfo = self:pkgconfig(pkg:name()) -- get values from package components -- e.g. `add_packages("sfml", {components = {"graphics", "window"}})` local selected_components = configinfo and configinfo.components or pkg:components_default() if selected_components and pkg:components() then local components_enabled = hashset.new() for _, comp in ipairs(table.wrap(selected_components)) do components_enabled:insert(comp) for _, dep in ipairs(table.wrap(pkg:component_orderdeps(comp))) do components_enabled:insert(dep) end end components_enabled:insert("__base") -- if we can't find the values from the component, we need to fall back to __base to find them. -- it contains some common values of all components local values = {} local components = table.wrap(pkg:components()) for _, component_name in ipairs(table.join(pkg:components_orderlist(), "__base")) do if components_enabled:has(component_name) then local info = components[component_name] if info then local compvalues = info[name] -- use full link path instead of links -- @see https://github.com/xmake-io/xmake/issues/5066 if configinfo and configinfo.linkpath then local libfiles = info.libfiles if name == "links" then if libfiles then compvalues = _filter_libfiles(libfiles) end elseif name == "linkdirs" then if libfiles then compvalues = nil end end end table.join2(values, compvalues) else local components_str = table.concat(table.wrap(configinfo.components), ", ") utils.warning("unknown component(%s) in add_packages(%s, {components = {%s}})", component_name, pkg:name(), components_str) end end end if #values > 0 then table.insert(result_values, values) table.insert(result_sources, "package::" .. pkg:name()) end -- get values instead of the builtin configs if exists extra package config -- e.g. `add_packages("xxx", {links = "xxx"})` elseif configinfo and configinfo[name] then local values = configinfo[name] if values ~= nil then table.insert(result_values, values) table.insert(result_sources, "package::" .. pkg:name()) end else -- get values from the builtin package configs local values = pkg:get(name) -- use full link path instead of links -- @see https://github.com/xmake-io/xmake/issues/5066 if configinfo and configinfo.linkpath then local libfiles = pkg:libraryfiles() if name == "links" then if libfiles then values = _filter_libfiles(libfiles) end elseif name == "linkdirs" then if libfiles then values = nil end end end if values ~= nil then table.insert(result_values, values) table.insert(result_sources, "package::" .. pkg:name()) end end end end -- get values from the given source function _instance:_get_from_source(name, source, result_values, result_sources, opt) if source == "self" then local values = self:get(name, opt) if values ~= nil then table.insert(result_values, values) table.insert(result_sources, "self") end elseif source:startswith("dep::") then local depname = source:split("::", {plain = true, limit = 2})[2] if depname == "*" then self:_get_from_deps(name, result_values, result_sources, opt) else local depsource local splitinfo = depname:split("/", {plain = true}) if #splitinfo == 2 then depname = splitinfo[1] depsource = splitinfo[2] end local dep = self:dep(depname) if dep then -- e.g. -- dep::foo/option::bar -- dep::foo/package::bar if depsource then local dep_values = {} local dep_sources = {} dep:_get_from_source(name, depsource, dep_values, dep_sources, opt) for idx, values in ipairs(dep_values) do local dep_source = dep_sources[idx] table.insert(result_values, values) table.insert(result_sources, "dep::" .. depname .. "/" .. dep_source) end else -- dep::foo local values = dep:get(name, opt) if values ~= nil then table.insert(result_values, values) table.insert(result_sources, source) end end end end elseif source:startswith("option::") then local optname = source:split("::", {plain = true, limit = 2})[2] if optname == "*" then self:_get_from_options(name, result_values, result_sources, opt) else local opt_ = self:opt(optname, opt) if opt_ then local values = opt_:get(name) if values ~= nil then table.insert(result_values, values) table.insert(result_sources, source) end end end elseif source:startswith("package::") then local pkgname = source:split("::", {plain = true, limit = 2})[2] if pkgname == "*" then self:_get_from_packages(name, result_values, result_sources, opt) else local pkg = self:pkg(pkgname, opt) if pkg then local values = pkg:get(name) if values ~= nil then table.insert(result_values, values) table.insert(result_sources, source) end end end elseif source == "*" then self:_get_from_source(name, "self", result_values, result_sources, opt) self:_get_from_source(name, "option::*", result_values, result_sources, opt) self:_get_from_source(name, "package::*", result_values, result_sources, opt) self:_get_from_source(name, "dep::*", result_values, result_sources, {interface = true}) else os.raise("target:get_from(): unknown source %s", source) end end -- get the checked target, it's only for target:check_xxx api. -- -- we should not inherit links from deps/packages when checking snippets in on_config, -- because the target deps has been not built. -- -- @see https://github.com/xmake-io/xmake/issues/4491 -- function _instance:_checked_target() local checked_target = self._CHECKED_TARGET if checked_target == nil then checked_target = self:clone() -- we need update target:cachekey(), because target flags may be cached in builder checked_target:_invalidate() checked_target.get_from = function (target, name, sources, opt) if (name == "links" or name == "linkdirs") and sources == "*" then sources = "self" end return _instance.get_from(target, name, sources, opt) end self._CHECKED_TARGET = checked_target end return checked_target end -- get format function _instance:_format(kind) local formats = self._FORMATS if not formats then for _, toolchain_inst in ipairs(self:toolchains()) do formats = toolchain_inst:formats() if formats then break end end self._FORMATS = formats end if formats then return formats[kind or self:kind()] end end -- clone target, @note we can just call it in after_load() function _instance:clone() if not self:_is_loaded() then os.raise("please call target:clone() in after_load().", self:name()) end local instance = target.new(self:name(), self._INFO:clone()) if self._DEPS then instance._DEPS = table.clone(self._DEPS) end if self._ORDERDEPS then instance._ORDERDEPS = table.clone(self._ORDERDEPS) end if self._INHERITDEPS then instance._INHERITDEPS = table.clone(self._INHERITDEPS) end if self._RULES then instance._RULES = table.clone(self._RULES) end if self._ORDERULES then instance._ORDERULES = table.clone(self._ORDERULES) end if self._DATA then instance._DATA = table.clone(self._DATA) end if self._SOURCEFILES then instance._SOURCEFILES = table.clone(self._SOURCEFILES) end if self._OBJECTFILES then instance._OBJECTFILES = table.clone(self._OBJECTFILES) end if self._SOURCEBATCHES then instance._SOURCEBATCHES = table.clone(self._SOURCEBATCHES, 3) end instance._LOADED = self._LOADED instance._LOADED_AFTER = true return instance end -- get the target info -- -- e.g. -- -- default: get private -- - target:get("cflags") -- - target:get("cflags", {private = true}) -- -- get private and interface -- - target:get("cflags", {public = true}) -- -- get interface -- - target:get("cflags", {interface = true}) -- -- get raw reference of values -- - target:get("cflags", {rawref = true}) -- function _instance:get(name, opt) -- get values local values = self._INFO:get(name) -- get thr required visibility local vs_private = 1 local vs_interface = 2 local vs_public = 3 -- all local vs_required = self:_visibility(opt) -- get all values? (private and interface) if vs_required == vs_public or (opt and opt.rawref) then return values end -- get the extra configuration local extraconf = self:extraconf(name) if extraconf then -- filter values for public, private or interface if be not dictionary if not table.is_dictionary(values) then local results = {} for _, value in ipairs(table.wrap(values)) do -- we always call self:extraconf() to handle group value local extra = self:extraconf(name, value) local vs_conf = self:_visibility(extra) if bit.band(vs_required, vs_conf) ~= 0 then table.insert(results, value) end end if #results > 0 then return table.unwrap(results) end else return values end else -- only get the private values if bit.band(vs_required, vs_private) ~= 0 then return values end end end -- deprecated: get values from target dependencies function _instance:get_from_deps(name, opt) deprecated.add("target:get_from(%s, \"dep:*\")", "target:get_from_deps(%s)", name) local result = {} local values = self:get_from(name, "dep::*", opt) if values then for _, v in ipairs(values) do table.join2(result, v) end end return result end -- deprecated: get values from target options with {interface|public = ...} function _instance:get_from_opts(name, opt) deprecated.add("target:get_from(%s, \"option::*\")", "target:get_from_opts(%s)", name) local result = {} local values = self:get_from(name, "option::*", opt) if values then for _, v in ipairs(values) do table.join2(result, v) end end return result end -- deprecated: get values from target packages with {interface|public = ...} function _instance:get_from_pkgs(name, opt) deprecated.add("target:get_from(%s, \"package::*\")", "target:get_from_pkgs(%s)", name) local result = {} local values = self:get_from(name, "package::*", opt) if values then for _, v in ipairs(values) do table.join2(result, v) end end return result end -- get values from the given sources -- -- e.g. -- -- only from the current target: -- target:get_from("links") -- target:get_from("links", "self") -- -- from the given dep: -- target:get_from("links", "dep::foo") -- target:get_from("links", "dep::foo", {interface = true}) -- target:get_from("links", "dep::*") -- -- from the given option: -- target:get_from("links", "option::foo") -- target:get_from("links", "option::*") -- -- from the given package: -- target:get_from("links", "package::foo") -- target:get_from("links", "package::*") -- -- from the given dep/option, dep/package -- target:get_from("links", "dep::foo/option::bar") -- target:get_from("links", "dep::foo/option::*") -- target:get_from("links", "dep::foo/package::bar") -- target:get_from("links", "dep::foo/package::*") -- -- from the multiple sources: -- target:get_from("links", {"self", "option::foo", "dep::bar", "package::zoo"}) -- target:get_from("links", {"self", "option::*", "dep::*", "package::*"}) -- -- from all: -- target:get_from("links", "*") -- -- return: -- local values, sources = target:get_from("links", "*") -- for idx, value in ipairs(values) do -- local source = sources[idx] -- end -- function _instance:get_from(name, sources, opt) local result_values = {} local result_sources = {} sources = sources or "self" for _, source in ipairs(table.wrap(sources)) do self:_get_from_source(name, source, result_values, result_sources, opt) end if #result_values > 0 then return result_values, result_sources end end -- set the value to the target info function _instance:set(name, ...) self._INFO:apival_set(name, ...) self:_invalidate(name) end -- add the value to the target info function _instance:add(name, ...) self._INFO:apival_add(name, ...) self:_invalidate(name) end -- remove the value to the target info (deprecated) function _instance:del(name, ...) self._INFO:apival_del(name, ...) self:_invalidate(name) end -- remove the value to the target info function _instance:remove(name, ...) self._INFO:apival_remove(name, ...) self:_invalidate(name) end -- get the extra configuration function _instance:extraconf(name, item, key) return self._INFO:extraconf(name, item, key) end -- set the extra configuration function _instance:extraconf_set(name, item, key, value) self._INFO:extraconf_set(name, item, key, value) end -- get the extra configuration from the given source -- -- e.g. -- -- only from the current target: -- target:extraconf_from("links") -- target:extraconf_from("links", "self") -- -- from the given dep: -- target:extraconf_from("links", "dep::foo") -- -- from the given option: -- target:extraconf_from("links", "option::foo") -- -- from the given package: -- target:extraconf_from("links", "package::foo") -- -- from the given dep/option, dep/package -- target:extraconf_from("links", "dep::foo/option::bar") -- target:extraconf_from("links", "dep::foo/package::bar") -- function _instance:extraconf_from(name, source) if name:find("::") then local tmp = name name = source source = tmp utils.warning("please use target:extraconf_from(%s, %s) intead of target:extraconf_from(%s, %s)", name, source, source, name) end source = source or "self" if source == "self" then return self:extraconf(name) elseif source:startswith("dep::") then local depname = source:split("::", {plain = true, limit = 2})[2] local depsource local splitinfo = depname:split("/", {plain = true}) if #splitinfo == 2 then depname = splitinfo[1] depsource = splitinfo[2] end local dep = self:dep(depname) if dep then -- e.g. -- dep::foo/option::bar -- dep::foo/package::bar if depsource then return dep:extraconf_from(name, dep_source) else -- dep::foo return dep:extraconf(name) end end elseif source:startswith("option::") then local optname = source:split("::", {plain = true, limit = 2})[2] local opt_ = self:opt(optname, opt) if opt_ then return opt_:extraconf(name) end elseif source:startswith("package::") then local pkgname = source:split("::", {plain = true, limit = 2})[2] local pkg = self:pkg(pkgname, opt) if pkg then return pkg:extraconf(name) end else os.raise("target:extraconf_from(): unknown source %s", source) end end -- get configuration source information of the given api item function _instance:sourceinfo(name, item) return self._INFO:sourceinfo(name, item) end -- get user private data function _instance:data(name) return self._DATA and self._DATA[name] end -- set user private data function _instance:data_set(name, data) self._DATA = self._DATA or {} self._DATA[name] = data end -- add user private data function _instance:data_add(name, data) self._DATA = self._DATA or {} self._DATA[name] = table.unwrap(table.join(self._DATA[name] or {}, data)) end -- get values function _instance:values(name, sourcefile) -- get values from the source file first local values = {} if sourcefile then local fileconfig = self:fileconfig(sourcefile) if fileconfig then local filevalues = fileconfig.values if filevalues then -- we use '_' to simplify setting, for example: -- -- add_files("xxx.mof", {values = {wdk_mof_header = "xxx.h"}}) -- add_files("xxx.mof", {values = {["wdk.mof.header"] = "xxx.h"}}) -- table.join2(values, filevalues[name] or filevalues[name:gsub("%.", "_")]) end end end -- get values from target table.join2(values, self:get("values." .. name)) if #values > 0 then values = table.unwrap(values) else values = nil end return values end -- set values function _instance:values_set(name, ...) self:set("values." .. name, ...) end -- add values function _instance:values_add(name, ...) self:add("values." .. name, ...) end -- get the target info function _instance:info() return self._INFO:info() end -- get the type: target function _instance:type() return "target" end -- get the target name function _instance:name() return self._NAME end -- set the target name function _instance:name_set(name) self._NAME = name end -- get the target kind function _instance:kind() return self:get("kind") or "binary" end -- get the target kind (deprecated) function _instance:targetkind() return self:kind() end -- get the platform of this target function _instance:plat() return self:get("plat") or config.get("plat") or os.host() end -- get the architecture of this target function _instance:arch() return self:get("arch") or config.get("arch") or os.arch() end -- the current target is belong to the given platforms? function _instance:is_plat(...) local plat = self:plat() for _, v in ipairs(table.pack(...)) do if v and plat == v then return true end end end -- the current target is belong to the given architectures? function _instance:is_arch(...) local arch = self:arch() for _, v in ipairs(table.pack(...)) do if v and arch:find("^" .. v:gsub("%-", "%%-") .. "$") then return true end end end -- is 64bits architecture? function _instance:is_arch64() return self:is_arch(".+64.*") end -- get the platform instance function _instance:platform() local platform_inst = self._PLATFORM if platform_inst == nil then platform_inst, errors = platform.load(self:plat(), self:arch()) if not platform_inst then os.raise(errors) end self._PLATFORM = platform_inst end return platform_inst end -- get the cache key function _instance:cachekey() return string.format("%s_%d", tostring(self), self._CACHEID) end -- get the target version function _instance:version() local version = self:get("version") local version_build if version then version_build = self:extraconf("version", version, "build") if type(version_build) == "string" then version_build = os.date(version_build, os.time()) end end return version, version_build end -- get the target soname -- @see https://github.com/tboox/tbox/issues/214 -- -- set_version("1.0.1", {soname = "1.0"}) -> libfoo.so.1.0, libfoo.1.0.dylib -- set_version("1.0.1", {soname = "1"}) -> libfoo.so.1, libfoo.1.dylib -- set_version("1.0.1", {soname = true}) -> libfoo.so.1, libfoo.1.dylib -- set_version("1.0.1", {soname = ""}) -> libfoo.so, libfoo.dylib function _instance:soname() if not self:is_shared() then return end if self:is_plat("windows", "mingw", "cygwin", "msys") then return end local version = self:get("version") local version_soname if version then version_soname = self:extraconf("version", version, "soname") if version_soname == true then version_soname = version:split(".", {plain = true})[1] end end if not version_soname then return end local soname = self:filename() if type(version_soname) == "string" and #version_soname > 0 then local extension = path.extension(soname) if extension == ".dylib" then soname = path.basename(soname) .. "." .. version_soname .. extension else soname = soname .. "." .. version_soname end end return soname end -- get the target license function _instance:license() return self:get("license") end -- get the target policy function _instance:policy(name) local policies = self._POLICIES if not policies then policies = self:get("policy") self._POLICIES = policies if policies then local defined_policies = policy.policies() for name, _ in pairs(policies) do if not defined_policies[name] then utils.warning("unknown policy(%s), please run `xmake l core.project.policy.policies` if you want to all policies", name) end end end end local value if policies then value = policies[name] end if value == nil and target._project() then value = target._project().policy(name) end return policy.check(name, value) end -- get the base name of target file function _instance:basename() local filename = self:get("filename") if filename then return path.basename(filename) end return self:get("basename") or self:name() end -- get the target compiler function _instance:compiler(sourcekind) local compilerinst = self:_memcache():get("compiler") if not compilerinst then if not sourcekind then os.raise("please pass sourcekind to the first argument of target:compiler(), e.g. cc, cxx, as") end local instance, errors = compiler.load(sourcekind, self) if not instance then os.raise(errors) end compilerinst = instance self:_memcache():set("compiler", compilerinst) end return compilerinst end -- get the target linker function _instance:linker() local linkerinst = self:_memcache():get("linker") if not linkerinst then local instance, errors = linker.load(self:kind(), self:sourcekinds(), self) if not instance then os.raise(errors) end linkerinst = instance self:_memcache():set("linker", linkerinst) end return linkerinst end -- make linking command for this target function _instance:linkcmd(objectfiles) return self:linker():linkcmd(objectfiles or self:objectfiles(), self:targetfile(), {target = self}) end -- make linking arguments for this target function _instance:linkargv(objectfiles) return self:linker():linkargv(objectfiles or self:objectfiles(), self:targetfile(), {target = self}) end -- make link flags for the given target function _instance:linkflags() return self:linker():linkflags({target = self}) end -- get the given dependent target function _instance:dep(name) local deps = self:deps() if deps then return deps[name] end end -- get target deps function _instance:deps() if not self:_is_loaded() then os.raise("please call target:deps() or target:dep() in after_load()!") end if self._DEPS == nil then self:_build_deps() end return self._DEPS end -- get target ordered deps function _instance:orderdeps(opt) opt = opt or {} if not self:_is_loaded() then os.raise("please call target:orderdeps() in after_load()!") end if self._DEPS == nil then self:_build_deps() end return opt.inherit and self._INHERITDEPS or self._ORDERDEPS end -- get target rules function _instance:rules() return self._RULES end -- get target ordered rules function _instance:orderules() local rules = self._RULES local orderules = self._ORDERULES if orderules == nil and rules then orderules = instance_deps.sort(rules) self._ORDERULES = orderules end return orderules end -- get target rule from the given rule name function _instance:rule(name) if self._RULES then return self._RULES[name] end end -- add rule -- -- @note If a rule has the same name as a built-in rule, -- it will be replaced in the target:rules() and target:orderules(), but will be not replaced globally in the project.rules() function _instance:rule_add(r) self._RULES = self._RULES or {} self._RULES[r:name()] = r self._ORDERULES = nil end -- is phony target? function _instance:is_phony() local targetkind = self:kind() return not targetkind or targetkind == "phony" end -- is binary target? function _instance:is_binary() return self:kind() == "binary" end -- is shared library target? function _instance:is_shared() return self:kind() == "shared" end -- is static library target? function _instance:is_static() return self:kind() == "static" end -- is object files target? function _instance:is_object() return self:kind() == "object" end -- is headeronly target? function _instance:is_headeronly() return self:kind() == "headeronly" end -- is moduleonly target? function _instance:is_moduleonly() return self:kind() == "moduleonly" end -- is library target? function _instance:is_library() return self:is_static() or self:is_shared() or self:is_headeronly() or self:is_moduleonly() end -- is default target? function _instance:is_default() local default = self:get("default") return default == nil or default == true end -- is enabled? function _instance:is_enabled() return self:get("enabled") ~= false end -- is rebuilt? function _instance:is_rebuilt() return self:data("rebuilt") end -- is cross-compilation? function _instance:is_cross() return is_cross(self:plat(), self:arch()) end -- get the enabled option function _instance:opt(name, opt) return self:opts(opt)[name] end -- get the enabled options function _instance:opts(opt) opt = opt or {} local cachekey = "opts" if opt.public then cachekey = cachekey .. "_public" elseif opt.interface then cachekey = cachekey .. "_interface" end local opts = self:_memcache():get(cachekey) if not opts then opts = {} for _, opt_ in ipairs(self:orderopts(opt)) do opts[opt_:name()] = opt_ end self:_memcache():set(cachekey, opts) end return opts end -- get the enabled ordered options with {public|interface = ...} function _instance:orderopts(opt) opt = opt or {} local cachekey = "orderopts" if opt.public then cachekey = cachekey .. "_public" elseif opt.interface then cachekey = cachekey .. "_interface" end local orderopts = self:_memcache():get(cachekey) if not orderopts then orderopts = {} for _, name in ipairs(table.wrap(self:get("options", opt))) do local opt_ = nil if config.get(name) then opt_ = option.load(name) end if opt_ then table.insert(orderopts, opt_) end end self:_memcache():set(cachekey, orderopts) end return orderopts end -- get the enabled package function _instance:pkg(name, opt) return self:pkgs(opt)[name] end -- get the enabled packages function _instance:pkgs(opt) opt = opt or {} local cachekey = "pkgs" if opt.public then cachekey = cachekey .. "_public" elseif opt.interface then cachekey = cachekey .. "_interface" end local packages = self:_memcache():get(cachekey) if not packages then packages = {} for _, pkg in ipairs(self:orderpkgs(opt)) do packages[pkg:name()] = pkg end self:_memcache():set(cachekey, packages) end return packages end -- get the required packages with {interface|public = ..} function _instance:orderpkgs(opt) opt = opt or {} local cachekey = "orderpkgs" if opt.public then cachekey = cachekey .. "_public" elseif opt.interface then cachekey = cachekey .. "_interface" end local packages = self:_memcache():get(cachekey) if not packages then packages = {} local requires = target._project().required_packages() if requires then for _, packagename in ipairs(table.wrap(self:get("packages", opt))) do local pkg = requires[packagename] if pkg and pkg:enabled() then table.insert(packages, pkg) end end end self:_memcache():set(cachekey, packages) end return packages end -- get the environments of packages function _instance:pkgenvs() local pkgenvs = self._PKGENVS if pkgenvs == nil then local pkgs = hashset.new() for _, pkgname in ipairs(table.wrap(self:get("packages"))) do local pkg = self:pkg(pkgname) if pkg then pkgs:insert(pkg) end end -- we can also get package envs from deps (public package) -- @see https://github.com/xmake-io/xmake/issues/2729 for _, dep in ipairs(self:orderdeps()) do for _, pkgname in ipairs(table.wrap(dep:get("packages", {interface = true}))) do local pkg = dep:pkg(pkgname) if pkg then pkgs:insert(pkg) end end end for _, pkg in pkgs:orderkeys() do local envs = pkg:envs() if envs then for name, values in table.orderpairs(envs) do if type(values) == "table" then values = path.joinenv(values) end pkgenvs = pkgenvs or {} if pkgenvs[name] then pkgenvs[name] = pkgenvs[name] .. path.envsep() .. values else pkgenvs[name] = values end end end end self._PKGENVS = pkgenvs or false end return pkgenvs or nil end -- get the config info of the given package function _instance:pkgconfig(pkgname) local extra_packages = self:extraconf("packages") if extra_packages then return extra_packages[pkgname] end end -- get the object files directory function _instance:objectdir(opt) -- the object directory local objectdir = self:get("objectdir") if not objectdir then objectdir = path.join(config.buildir(), ".objs") end objectdir = path.join(objectdir, self:name()) -- get root directory of target local intermediate_directory = self:policy("build.intermediate_directory") if (opt and opt.root) or intermediate_directory == false then return objectdir end -- generate intermediate directory local plat = self:plat() if plat then objectdir = path.join(objectdir, plat) end local arch = self:arch() if arch then objectdir = path.join(objectdir, arch) end local mode = config.mode() if mode then objectdir = path.join(objectdir, mode) end return objectdir end -- get the dependent files directory function _instance:dependir(opt) -- init the dependent directory local dependir = self:get("dependir") if not dependir then dependir = path.join(config.buildir(), ".deps") end dependir = path.join(dependir, self:name()) -- get root directory of target local intermediate_directory = self:policy("build.intermediate_directory") if (opt and opt.root) or intermediate_directory == false then return dependir end -- generate intermediate directory local plat = self:plat() if plat then dependir = path.join(dependir, plat) end local arch = self:arch() if arch then dependir = path.join(dependir, arch) end local mode = config.mode() if mode then dependir = path.join(dependir, mode) end return dependir end -- get the autogen files directory function _instance:autogendir(opt) -- init the autogen directory local autogendir = self:get("autogendir") if not autogendir then autogendir = path.join(config.buildir(), ".gens") end autogendir = path.join(autogendir, self:name()) -- get root directory of target local intermediate_directory = self:policy("build.intermediate_directory") if (opt and opt.root) or intermediate_directory == false then return autogendir end -- generate intermediate directory local plat = self:plat() if plat then autogendir = path.join(autogendir, plat) end local arch = self:arch() if arch then autogendir = path.join(autogendir, arch) end local mode = config.mode() if mode then autogendir = path.join(autogendir, mode) end return autogendir end -- get the autogen file path from the given source file path function _instance:autogenfile(sourcefile, opt) -- get relative directory in the autogen directory local relativedir = nil local origindir = path.directory(path.absolute(sourcefile)) local autogendir = path.absolute(self:autogendir()) if origindir:startswith(autogendir) then relativedir = path.join("gens", path.relative(origindir, autogendir)) end -- get relative directory in the source directory if not relativedir then relativedir = path.directory(sourcefile) end -- translate path -- -- e.g. -- -- src/xxx.c -- project/xmake.lua -- build/.objs -- build/.gens -- -- objectfile: project/build/.objs/xxxx/../../xxx.c will be out of range for objectdir -- autogenfile: project/build/.gens/xxxx/../../xxx.c will be out of range for autogendir -- -- we need to replace '..' with '__' in this case -- if path.is_absolute(relativedir) and os.host() == "windows" then -- remove C:\\ and whitespaces and fix long path issue -- e.g. C:\\Program Files (x64)\\xxx\Windows.h -- -- @see -- https://github.com/xmake-io/xmake/issues/3021 -- https://github.com/xmake-io/xmake/issues/3715 relativedir = hash.uuid4(relativedir):gsub("%-", ""):lower() end relativedir = relativedir:gsub("%.%.", "__") local rootdir = (opt and opt.rootdir) and opt.rootdir or self:autogendir() if relativedir ~= "." then rootdir = path.join(rootdir, relativedir) end return path.join(rootdir, (opt and opt.filename) and opt.filename or path.filename(sourcefile)) end -- get the target directory function _instance:targetdir() -- the target directory local targetdir = self:get("targetdir") if not targetdir then targetdir = config.buildir() -- get root directory of target local intermediate_directory = self:policy("build.intermediate_directory") if intermediate_directory == false then return targetdir end -- generate intermediate directory local plat = self:plat() if plat then targetdir = path.join(targetdir, plat) end local arch = self:arch() if arch then targetdir = path.join(targetdir, arch) end local mode = config.mode() if mode then targetdir = path.join(targetdir, mode) end end return targetdir end -- get the target file name function _instance:filename() -- no target file? if self:is_object() or self:is_phony() or self:is_headeronly() or self:is_moduleonly() then return end -- make the target file name and attempt to use the format of linker first local targetkind = self:targetkind() local filename = self:get("filename") if not filename then local prefixname = self:get("prefixname") local suffixname = self:get("suffixname") local extension = self:get("extension") filename = target.filename(self:basename(), targetkind, { format = self:_format(), plat = self:plat(), arch = self:arch(), prefixname = prefixname, suffixname = suffixname, extension = extension}) end return filename end -- get the link name only for static/shared library function _instance:linkname() if self:is_static() or self:is_shared() then local filename = self:get("filename") if filename then return target.linkname(filename) else local linkname = self:basename() local suffixname = self:get("suffixname") if suffixname then linkname = linkname .. suffixname end return linkname end end end -- get the target file function _instance:targetfile() local filename = self:filename() if filename then return path.join(self:targetdir(), filename) end end -- get the symbol file function _instance:symbolfile() -- the target directory local targetdir = self:targetdir() assert(targetdir and type(targetdir) == "string") -- the symbol file name local prefixname = self:get("prefixname") local suffixname = self:get("suffixname") local filename = target.filename(self:basename(), "symbol", { plat = self:plat(), arch = self:arch(), format = self:_format("symbol"), prefixname = prefixname, suffixname = suffixname}) assert(filename) -- make the symbol file path return path.join(targetdir, filename) end -- get the script directory of xmake.lua function _instance:scriptdir() return self:get("__scriptdir") end -- get configuration output directory function _instance:configdir() return self:get("configdir") or config.buildir() end -- get run directory function _instance:rundir() return baseoption.get("workdir") or self:get("rundir") or path.directory(self:targetfile()) end -- get prefix directory function _instance:prefixdir() return self:get("prefixdir") end -- get the installed binary directory function _instance:bindir() local bindir = self:extraconf("prefixdir", self:prefixdir(), "bindir") if bindir == nil then bindir = "bin" end return self:installdir(bindir) end -- get the installed library directory function _instance:libdir() local libdir = self:extraconf("prefixdir", self:prefixdir(), "libdir") if libdir == nil then libdir = "lib" end return self:installdir(libdir) end -- get the installed include directory function _instance:includedir() local includedir = self:extraconf("prefixdir", self:prefixdir(), "includedir") if includedir == nil then includedir = "include" end return self:installdir(includedir) end -- get install directory function _instance:installdir(...) opt = opt or {} local installdir = baseoption.get("installdir") if not installdir then -- DESTDIR: be compatible with https://www.gnu.org/prep/standards/html_node/DESTDIR.html installdir = self:get("installdir") or os.getenv("INSTALLDIR") or os.getenv("PREFIX") or os.getenv("DESTDIR") or platform.get("installdir") if installdir then installdir = installdir:trim() end end if installdir then local prefixdir = self:prefixdir() if prefixdir then installdir = path.join(installdir, prefixdir) end return path.normalize(path.join(installdir, ...)) end end -- get package directory function _instance:packagedir() -- get the output directory local outputdir = baseoption.get("outputdir") or config.buildir() local packagename = self:name():lower() if #packagename > 1 and bit.band(packagename:byte(2), 0xc0) == 0x80 then utils.warning("package(%s): cannot generate package, becauese it contains unicode characters!", packagename) return end return path.join(outputdir, "packages", packagename:sub(1, 1), packagename) end -- get rules of the source file function _instance:filerules(sourcefile) -- add rules from file config local rules = {} local override = false local fileconfig = self:fileconfig(sourcefile) if fileconfig then local filerules = fileconfig.rules or fileconfig.rule if filerules then override = filerules.override for _, rulename in ipairs(table.wrap(filerules)) do local r = target._project().rule(rulename) or rule.rule(rulename) if r then table.insert(rules, r) end end end end -- override? e.g. add_files("src/*.c", {rules = {"xxx", override = true}}) if override then return rules, true end -- load all rules for this target with sourcekinds and extensions local key2rules = self:_memcache():get("key2rules") if not key2rules then key2rules = {} for _, r in pairs(table.wrap(self:rules())) do -- we can also get sourcekinds from add_rules("xxx", {sourcekinds = "cxx"}) local rule_sourcekinds = self:extraconf("rules", r:name(), "sourcekinds") or r:get("sourcekinds") for _, sourcekind in ipairs(table.wrap(rule_sourcekinds)) do key2rules[sourcekind] = key2rules[sourcekind] or {} table.insert(key2rules[sourcekind], r) end -- we can also get extensions from add_rules("xxx", {extensions = ".cpp"}) local rule_extensions = self:extraconf("rules", r:name(), "extensions") or r:get("extensions") for _, extension in ipairs(table.wrap(rule_extensions)) do extension = extension:lower() key2rules[extension] = key2rules[extension] or {} table.insert(key2rules[extension], r) end end self:_memcache():set("key2rules", key2rules) end -- get target rules from the given sourcekind or extension -- -- @note we prefer to use rules with extension because we need to be able to -- override the language code rules set by set_sourcekinds -- -- e.g. set_extensions(".bpf.c") will override c++ rules -- local rules_override = {} local filename = path.filename(sourcefile):lower() for _, r in ipairs(table.wrap(key2rules[path.extension(filename, 2)] or key2rules[path.extension(filename)] or key2rules[self:sourcekind_of(filename)])) do if self:extraconf("rules", r:name(), "override") then table.insert(rules_override, r) else table.insert(rules, r) end end -- we will use overrided rules first, e.g. add_rules("xxx", {override = true}) return #rules_override > 0 and rules_override or rules end -- get the config info of the given source file function _instance:fileconfig(sourcefile, opt) opt = opt or {} local filetype = opt.filetype or "files" -- get configs from user, e.g. target:fileconfig_set/add -- it has contained all original configs if self._FILESCONFIG_USER then local filesconfig = self._FILESCONFIG_USER[filetype] if filesconfig and filesconfig[sourcefile] then return filesconfig[sourcefile] end end -- get orignal configs from `add_xxxfiles()` self._FILESCONFIG = self._FILESCONFIG or {} local filesconfig = self._FILESCONFIG[filetype] if not filesconfig then filesconfig = {} for filepath, fileconfig in pairs(table.wrap(self:extraconf(filetype))) do local results = os.match(filepath) if #results > 0 then for _, file in ipairs(results) do if path.is_absolute(file) then file = path.relative(file, os.projectdir()) end filesconfig[file] = fileconfig end else -- we also need support always_added, @see https://github.com/xmake-io/xmake/issues/1634 if fileconfig.always_added then filesconfig[filepath] = fileconfig end end end self._FILESCONFIG[filetype] = filesconfig end return filesconfig[sourcefile] end -- set the config info to the given source file function _instance:fileconfig_set(sourcefile, info, opt) opt = opt or {} self._FILESCONFIG_USER = self._FILESCONFIG_USER or {} local filetype = opt.filetype or "files" local filesconfig = self._FILESCONFIG_USER[filetype] if not filesconfig then filesconfig = {} self._FILESCONFIG_USER[filetype] = filesconfig end filesconfig[sourcefile] = info end -- add the config info to the given source file function _instance:fileconfig_add(sourcefile, info, opt) opt = opt or {} self._FILESCONFIG_USER = self._FILESCONFIG_USER or {} local filetype = opt.filetype or "files" local filesconfig = self._FILESCONFIG_USER[filetype] if not filesconfig then filesconfig = {} self._FILESCONFIG_USER[filetype] = filesconfig end -- we fetch orignal configs first if no user configs local fileconfig = filesconfig[sourcefile] if not fileconfig then fileconfig = table.clone(self:fileconfig(sourcefile, opt)) filesconfig[sourcefile] = fileconfig end if fileconfig then for k, v in pairs(info) do if k == "force" then -- fileconfig_add("xxx.c", {force = {cxxflags = ""}}) local force = fileconfig[k] or {} for k2, v2 in pairs(v) do if force[k2] then force[k2] = table.join(force[k2], v2) else force[k2] = v2 end end fileconfig[k] = force else -- fileconfig_add("xxx.c", {cxxflags = ""}) if fileconfig[k] then fileconfig[k] = table.join(fileconfig[k], v) else fileconfig[k] = v end end end else filesconfig[sourcefile] = info end end -- get the source files function _instance:sourcefiles() -- cached? return it directly if self._SOURCEFILES then return self._SOURCEFILES, false end -- get files local files = self:get("files") if not files then return {}, false end -- match files local i = 1 local count = 0 local sourcefiles = {} local sourcefiles_removed = {} local sourcefiles_inserted = {} local removed_count = 0 local targetcache = memcache.cache("core.project.target") for _, file in ipairs(table.wrap(files)) do -- mark as removed files? local removed = false local prefix = "__remove_" if file:startswith(prefix) then file = file:sub(#prefix + 1) removed = true end -- find source files and try to cache the matching results of os.match across targets -- @see https://github.com/xmake-io/xmake/issues/1353 local results = targetcache:get2("sourcefiles", file) if not results then if removed then results = {file} else results = os.files(file) if #results == 0 then -- attempt to find source directories if maybe compile it as directory with the custom rules if #self:filerules(file) > 0 then results = os.dirs(file) end end -- Even if the current source file does not exist yet, we always add it. -- This is usually used for some rules that automatically generate code files, -- because they ensure that the code files have been generated before compilation. -- -- @see https://github.com/xmake-io/xmake/issues/1540 -- -- e.g. add_files("src/test.c", {always_added = true}) -- if #results == 0 and self:extraconf("files", file, "always_added") then results = {file} end end targetcache:set2("sourcefiles", file, results) end if #results == 0 then local sourceinfo = self:sourceinfo("files", file) or {} utils.warning("%s:%d${clear}: cannot match %s_files(\"%s\") in %s(%s)", sourceinfo.file or "", sourceinfo.line or -1, (removed and "remove" or "add"), file, self:type(), self:name()) end -- process source files for _, sourcefile in ipairs(results) do -- convert to the relative path if path.is_absolute(sourcefile) then sourcefile = path.relative(sourcefile, os.projectdir()) end -- add or remove it if removed then removed_count = removed_count + 1 table.insert(sourcefiles_removed, sourcefile) elseif not sourcefiles_inserted[sourcefile] then table.insert(sourcefiles, sourcefile) sourcefiles_inserted[sourcefile] = true end end end -- remove all source files which need be removed if removed_count > 0 then table.remove_if(sourcefiles, function (i, sourcefile) for _, removed_file in ipairs(sourcefiles_removed) do local pattern = path.translate((removed_file:gsub("|.*$", ""))) if pattern:sub(1, 2):find('%.[/\\]') then pattern = pattern:sub(3) end pattern = path.pattern(pattern) -- we need to match whole pattern, https://github.com/xmake-io/xmake/issues/3523 if sourcefile:match("^" .. pattern .. "$") then return true end end end) end self._SOURCEFILES = sourcefiles -- ok and sourcefiles are modified return sourcefiles, true end -- get object file from source file function _instance:objectfile(sourcefile) return self:autogenfile(sourcefile, {rootdir = self:objectdir(), filename = target.filename(path.filename(sourcefile), "object", { plat = self:plat(), arch = self:arch(), format = self:_format("object")})}) end -- get the object files function _instance:objectfiles() -- get source batches local sourcebatches, modified = self:sourcebatches() -- cached? return it directly if self._OBJECTFILES and not modified then return self._OBJECTFILES end -- get object files from source batches local objectfiles = {} local batchcount = 0 local sourcebatches = self:sourcebatches() local orderkeys = table.keys(sourcebatches) table.sort(orderkeys) -- @note we need to guarantee the order of objectfiles for depend.is_changed() and etc. for _, k in ipairs(orderkeys) do local sourcebatch = sourcebatches[k] table.join2(objectfiles, sourcebatch.objectfiles) batchcount = batchcount + 1 end -- some object files may be repeat and appear link errors if multi-batches exists, so we need to remove all repeat object files -- e.g. add_files("src/*.c", {rules = {"rule1", "rule2"}}) local deduplicate = batchcount > 1 -- get object files from all dependent targets (object kind) -- @note we only merge objects in plain deps, e.g. binary -> (static -> object, object ...) local plaindeps = self:get("deps") if plaindeps and (self:is_binary() or self:is_shared() or self:is_static()) then local function _get_all_objectfiles_of_object_dep (t) local _objectfiles = {} table.join2(_objectfiles, t:objectfiles()) local _plaindeps = t:get("deps") if _plaindeps then for _, depname in ipairs(table.wrap(_plaindeps)) do local dep = t:dep(depname) if dep and dep:is_object() then table.join2(_objectfiles, _get_all_objectfiles_of_object_dep(dep)) end end end return _objectfiles end for _, depname in ipairs(table.wrap(plaindeps)) do local dep = self:dep(depname) if dep and dep:is_object() then table.join2(objectfiles, _get_all_objectfiles_of_object_dep(dep)) deduplicate = true end end end -- remove repeat object files if deduplicate then objectfiles = table.unique(objectfiles) end -- cache it self._OBJECTFILES = objectfiles return objectfiles end -- get the header files function _instance:headerfiles(outputdir, opt) opt = opt or {} local headerfiles = self:get("headerfiles", opt) or {} -- add_headerfiles("src/*.h", {install = false}) -- @see https://github.com/xmake-io/xmake/issues/2577 if opt.installonly then local installfiles = {} for _, headerfile in ipairs(table.wrap(headerfiles)) do if self:extraconf("headerfiles", headerfile, "install") ~= false then table.insert(installfiles, headerfile) end end headerfiles = installfiles end if not headerfiles then return end if not outputdir then if self:includedir() then outputdir = self:includedir() end end return match_copyfiles(self, "headerfiles", outputdir, {copyfiles = headerfiles}) end -- get the configuration files function _instance:configfiles(outputdir) return match_copyfiles(self, "configfiles", outputdir or self:configdir(), {pathfilter = function (dstpath, fileinfo) if dstpath:endswith(".in") then dstpath = dstpath:sub(1, -4) end return dstpath end}) end -- get the install files function _instance:installfiles(outputdir, opt) local installfiles = self:get("installfiles", opt) or {} return match_copyfiles(self, "installfiles", outputdir or self:installdir(), {copyfiles = installfiles}) end -- get the extra files function _instance:extrafiles() return (match_copyfiles(self, "extrafiles")) end -- get depend file from object file function _instance:dependfile(objectfile) -- get the dependent original file and directory, @note relative to the root directory local originfile = path.absolute(objectfile and objectfile or self:targetfile()) local origindir = path.directory(originfile) -- get relative directory in the object directory local relativedir = nil local objectdir = path.absolute(self:objectdir()) if origindir:startswith(objectdir) then relativedir = path.relative(origindir, objectdir) end -- get relative directory in the target directory if not relativedir then local targetdir = path.absolute(self:targetdir()) if origindir:startswith(targetdir) then relativedir = path.relative(origindir, targetdir) end end -- get relative directory in the autogen directory if not relativedir then local autogendir = path.absolute(self:autogendir()) if origindir:startswith(autogendir) then relativedir = path.join("gens", path.relative(origindir, autogendir)) end end -- get relative directory in the build directory if not relativedir then local buildir = path.absolute(config.buildir()) if origindir:startswith(buildir) then relativedir = path.join("build", path.relative(origindir, buildir)) end end -- get relative directory in the project directory if not relativedir then local projectdir = os.projectdir() if origindir:startswith(projectdir) then relativedir = path.relative(origindir, projectdir) end end -- get the relative directory from the origin file if not relativedir then relativedir = origindir end if path.is_absolute(relativedir) and os.host() == "windows" then -- remove C:\\ and whitespaces and fix long path issue -- e.g. C:\\Program Files (x64)\\xxx\Windows.h -- -- @see -- https://github.com/xmake-io/xmake/issues/3021 -- https://github.com/xmake-io/xmake/issues/3715 relativedir = hash.uuid4(relativedir):gsub("%-", ""):lower() end -- originfile: project/build/.objs/xxxx/../../xxx.c will be out of range for objectdir -- -- we need to replace '..' to '__' in this case -- relativedir = relativedir:gsub("%.%.", "__") -- make dependent file -- full file name(not base) to avoid name-clash of original file return path.join(self:dependir(), relativedir, path.filename(originfile) .. ".d") end -- get the dependent include files function _instance:dependfiles() local sourcebatches, modified = self:sourcebatches() if self._DEPENDFILES and not modified then return self._DEPENDFILES end local dependfiles = {} for _, sourcebatch in pairs(self:sourcebatches()) do table.join2(dependfiles, sourcebatch.dependfiles) end self._DEPENDFILES = dependfiles return dependfiles end -- get the sourcekind for the given source file function _instance:sourcekind_of(sourcefile) -- get the sourcekind of this source file local sourcekind = language.sourcekind_of(sourcefile) local fileconfig = self:fileconfig(sourcefile) if fileconfig and fileconfig.sourcekind then -- we can override the sourcekind, e.g. add_files("*.c", {sourcekind = "cxx"}) sourcekind = fileconfig.sourcekind end return sourcekind end -- get the kinds of sourcefiles -- -- e.g. cc cxx mm mxx as ... -- function _instance:sourcekinds() local sourcekinds = self._SOURCEKINDS if not sourcekinds then sourcekinds = {} local sourcebatches = self:sourcebatches() for _, sourcebatch in table.orderpairs(sourcebatches) do local sourcekind = sourcebatch.sourcekind if sourcekind then table.insert(sourcekinds, sourcekind) end end -- if the source file is added dynamically, we may not be able to get the sourcekinds, -- so we can only continue to get it from the rule -- https://github.com/xmake-io/xmake/issues/1622#issuecomment-927726697 for _, ruleinst in ipairs(self:orderules()) do local rule_sourcekinds = ruleinst:get("sourcekinds") if rule_sourcekinds then table.insert(sourcekinds, rule_sourcekinds) end end sourcekinds = table.unique(sourcekinds) self._SOURCEKINDS = sourcekinds end return sourcekinds end -- get source count function _instance:sourcecount() return #self:sourcefiles() end -- get source batches function _instance:sourcebatches() -- get source files local sourcefiles, modified = self:sourcefiles() -- cached? return it directly if self._SOURCEBATCHES and not modified then return self._SOURCEBATCHES, false end -- make source batches for each source kinds local sourcebatches = {} for _, sourcefile in ipairs(sourcefiles) do -- get file rules local filerules, override = self:filerules(sourcefile) if #filerules == 0 then os.raise("unknown source file: %s", sourcefile) end -- add source batch for the file rules for _, filerule in ipairs(filerules) do -- get rule name local rulename = filerule:name() -- make this batch local sourcebatch = sourcebatches[rulename] or {sourcefiles = {}} sourcebatches[rulename] = sourcebatch -- save the rule name sourcebatch.rulename = rulename -- add source file to this batch table.insert(sourcebatch.sourcefiles, sourcefile) -- attempt to get source kind from the builtin languages local sourcekind = self:sourcekind_of(sourcefile) if sourcekind and filerule:get("sourcekinds") and not override then -- save source kind sourcebatch.sourcekind = sourcekind -- insert object files to source batches sourcebatch.objectfiles = sourcebatch.objectfiles or {} sourcebatch.dependfiles = sourcebatch.dependfiles or {} local objectfile = self:objectfile(sourcefile, sourcekind) table.insert(sourcebatch.objectfiles, objectfile) table.insert(sourcebatch.dependfiles, self:dependfile(objectfile)) end end end self._SOURCEBATCHES = sourcebatches return sourcebatches, modified end -- get xxx_script function _instance:script(name, generic) -- get script local script = self:get(name) local result = select_script(script, {plat = self:plat(), arch = self:arch()}) or generic -- imports some modules first if result and result ~= generic then local scope = getfenv(result) if scope then for _, modulename in ipairs(table.wrap(self:get("imports"))) do scope[sandbox_module.name(modulename)] = sandbox_module.import(modulename, {anonymous = true}) end end end return result end -- get the precompiled header file (xxx.[h|hpp|inl]) -- -- @param langkind c/cxx -- function _instance:pcheaderfile(langkind) local pcheaderfile = self:get("p" .. langkind .. "header") if table.empty(pcheaderfile) then pcheaderfile = nil end return pcheaderfile end -- set the precompiled header file function _instance:pcheaderfile_set(langkind, headerfile) self:set("p" .. langkind .. "header", headerfile) self._PCOUTPUTFILES = nil end -- get the output of precompiled header file (xxx.h.pch) -- -- @param langkind c/cxx -- function _instance:pcoutputfile(langkind) self._PCOUTPUTFILES = self._PCOUTPUTFILES or {} local pcoutputfile = self._PCOUTPUTFILES[langkind] if pcoutputfile then return pcoutputfile end -- get the precompiled header file in the object directory local pcheaderfile = self:pcheaderfile(langkind) if pcheaderfile then local is_gcc = false local is_msvc = false local sourcekinds = {c = "cc", cxx = "cxx", m = "mm", mxx = "mxx"} local sourcekind = assert(sourcekinds[langkind], "unknown language kind: " .. langkind) local _, toolname = self:tool(sourcekind) if toolname then if toolname == "gcc" or toolname == "gxx" then is_gcc = true elseif toolname == "cl" then is_msvc = true end end -- make precompiled output file -- -- @note gcc has not -include-pch option to set the pch file path -- pcoutputfile = self:objectfile(pcheaderfile) local pcoutputfilename = path.basename(pcoutputfile) if is_gcc then pcoutputfilename = pcoutputfilename .. ".gch" else -- different vs versions of pch files are not backward compatible, -- so we need to distinguish between them. -- -- @see https://github.com/xmake-io/xmake/issues/5413 local msvc = self:toolchain("msvc") if is_msvc and msvc then local vs_toolset = msvc:config("vs_toolset") if vs_toolset then vs_toolset = sandbox_module.import("private.utils.toolchain", {anonymous = true}).get_vs_toolset_ver(vs_toolset) end if vs_toolset then pcoutputfilename = pcoutputfilename .. "_" .. vs_toolset end end pcoutputfilename = pcoutputfilename .. ".pch" end pcoutputfile = path.join(path.directory(pcoutputfile), sourcekind, pcoutputfilename) self._PCOUTPUTFILES[langkind] = pcoutputfile return pcoutputfile end end -- get runtimes function _instance:runtimes() local runtimes = self:_memcache():get("runtimes") if runtimes == nil then runtimes = self:get("runtimes") if runtimes then local runtimes_supported = hashset.new() local toolchains = self:toolchains() or platform.load(self:plat(), self:arch()):toolchains() if toolchains then for _, toolchain_inst in ipairs(toolchains) do if toolchain_inst:is_standalone() and toolchain_inst:get("runtimes") then for _, runtime in ipairs(table.wrap(toolchain_inst:get("runtimes"))) do runtimes_supported:insert(runtime) end end end end local runtimes_current = {} for _, runtime in ipairs(table.wrap(runtimes)) do if runtimes_supported:has(runtime) then table.insert(runtimes_current, runtime) end end runtimes = table.unwrap(runtimes_current) end runtimes = runtimes or false self:_memcache():set("runtimes", runtimes) end return runtimes or nil end -- has the given runtime for the current toolchains? function _instance:has_runtime(...) local runtimes_set = self:_memcache():get("runtimes_set") if runtimes_set == nil then runtimes_set = hashset.from(table.wrap(self:runtimes())) self:_memcache():set("runtimes_set", runtimes_set) end for _, v in ipairs(table.pack(...)) do if runtimes_set:has(v) then return true end end end -- get the given toolchain function _instance:toolchain(name) local toolchains_map = self:_memcache():get("toolchains_map") if toolchains_map == nil then toolchains_map = {} for _, toolchain_inst in ipairs(self:toolchains()) do toolchains_map[toolchain_inst:name()] = toolchain_inst end self:_memcache():set("toolchains_map", toolchains_map) end return toolchains_map[name] end -- get the toolchains function _instance:toolchains() local toolchains = self:_memcache():get("toolchains") if toolchains == nil then -- load target toolchains first local has_standalone = false local target_toolchains = self:get("toolchains") if target_toolchains then toolchains = {} for _, name in ipairs(table.wrap(target_toolchains)) do local toolchain_opt = table.copy(self:extraconf("toolchains", name)) toolchain_opt.arch = self:arch() toolchain_opt.plat = self:plat() local toolchain_inst, errors = toolchain.load(name, toolchain_opt) -- attempt to load toolchain from project if not toolchain_inst and target._project() then toolchain_inst = target._project().toolchain(name, toolchain_opt) end if not toolchain_inst then os.raise(errors) end if toolchain_inst:is_standalone() then has_standalone = true end table.insert(toolchains, toolchain_inst) end -- we always need a standalone toolchain -- because we maybe only set partial toolchains in target, e.g. nasm toolchain -- -- @note platform has been checked in config/_check_target_toolchains if not has_standalone then for _, toolchain_inst in ipairs(self:platform():toolchains()) do if toolchain_inst:is_standalone() then table.insert(toolchains, toolchain_inst) has_standalone = true break end end end else toolchains = self:platform():toolchains() end self:_memcache():set("toolchains", toolchains) end return toolchains end -- get the program and name of the given tool kind function _instance:tool(toolkind) -- we cannot get tool in on_load, because target:toolchains() has been not checked in configuration stage. if not self._LOADED_AFTER then os.raise("we cannot get tool(%s) before target(%s) is loaded, maybe it is called on_load(), please call it in on_config().", toolkind, self:name()) end return toolchain.tool(self:toolchains(), toolkind, {cachekey = "target_" .. self:name(), plat = self:plat(), arch = self:arch(), before_get = function() -- get program from set_toolset local program = self:get("toolset." .. toolkind) -- get program from `xmake f --cc` if not program and not self:get("toolchains") then program = config.get(toolkind) end -- contain toolname? parse it, e.g. '[email protected]' -- https://github.com/xmake-io/xmake/issues/1361 local toolname if program then local pos = program:find('@', 1, true) if pos then -- we need to ignore valid path with `@`, e.g. /usr/local/opt/[email protected]/bin/go -- https://github.com/xmake-io/xmake/issues/2853 local prefix = program:sub(1, pos - 1) if prefix and not prefix:find("[/\\]") then toolname = prefix program = program:sub(pos + 1) end end end -- find toolname if program and not toolname then local find_toolname = sandbox_module.import("lib.detect.find_toolname", {anonymous = true}) toolname = find_toolname(program) end return program, toolname end}) end -- get tool configuration from the toolchains function _instance:toolconfig(name) return toolchain.toolconfig(self:toolchains(), name, {cachekey = "target_" .. self:name(), plat = self:plat(), arch = self:arch(), after_get = function(toolchain_inst) -- get flags from target.on_xxflags() local script = toolchain_inst:get("target.on_" .. name) if type(script) == "function" then local ok, result_or_errors = utils.trycall(script, nil, self) if ok then return result_or_errors else os.raise(result_or_errors) end end end}) end -- has source files with the given source kind? function _instance:has_sourcekind(...) local sourcekinds_set = self._SOURCEKINDS_SET if sourcekinds_set == nil then sourcekinds_set = hashset.from(self:sourcekinds()) self._SOURCEKINDS_SET = sourcekinds_set end for _, v in ipairs(table.pack(...)) do if sourcekinds_set:has(v) then return true end end end -- has the given tool for the current target? -- -- e.g. -- -- if target:has_tool("cc", "clang", "gcc") then -- ... -- end function _instance:has_tool(toolkind, ...) local _, toolname = self:tool(toolkind) if toolname then for _, v in ipairs(table.pack(...)) do if v and toolname:find("^" .. v:gsub("%-", "%%-") .. "$") then return true end end end end -- has the given c funcs? -- -- @param funcs the funcs -- @param opt the argument options, e.g. {includes = "xxx.h", configs = {defines = ""}} -- -- @return true or false, errors -- function _instance:has_cfuncs(funcs, opt) opt = opt or {} opt.target = self return sandbox_module.import("lib.detect.has_cfuncs", {anonymous = true})(funcs, opt) end -- has the given c++ funcs? -- -- @param funcs the funcs -- @param opt the argument options, e.g. {includes = "xxx.h", configs = {defines = ""}} -- -- @return true or false, errors -- function _instance:has_cxxfuncs(funcs, opt) opt = opt or {} opt.target = self return sandbox_module.import("lib.detect.has_cxxfuncs", {anonymous = true})(funcs, opt) end -- has the given c types? -- -- @param types the types -- @param opt the argument options, e.g. {configs = {defines = ""}} -- -- @return true or false, errors -- function _instance:has_ctypes(types, opt) opt = opt or {} opt.target = self return sandbox_module.import("lib.detect.has_ctypes", {anonymous = true})(types, opt) end -- has the given c++ types? -- -- @param types the types -- @param opt the argument options, e.g. {configs = {defines = ""}} -- -- @return true or false, errors -- function _instance:has_cxxtypes(types, opt) opt = opt or {} opt.target = self return sandbox_module.import("lib.detect.has_cxxtypes", {anonymous = true})(types, opt) end -- has the given c includes? -- -- @param includes the includes -- @param opt the argument options, e.g. {configs = {defines = ""}} -- -- @return true or false, errors -- function _instance:has_cincludes(includes, opt) opt = opt or {} opt.target = self return sandbox_module.import("lib.detect.has_cincludes", {anonymous = true})(includes, opt) end -- has the given c++ includes? -- -- @param includes the includes -- @param opt the argument options, e.g. {configs = {defines = ""}} -- -- @return true or false, errors -- function _instance:has_cxxincludes(includes, opt) opt = opt or {} opt.target = self return sandbox_module.import("lib.detect.has_cxxincludes", {anonymous = true})(includes, opt) end -- has the given c flags? -- -- @param flags the flags -- @param opt the argument options, e.g. { flagskey = "xxx" } -- -- @return true or false, errors -- function _instance:has_cflags(flags, opt) local compinst = self:compiler("cc") return compinst:has_flags(flags, "cflags", opt) end -- has the given c++ flags? -- -- @param flags the flags -- @param opt the argument options, e.g. { flagskey = "xxx" } -- -- @return true or false, errors -- function _instance:has_cxxflags(flags, opt) local compinst = self:compiler("cxx") return compinst:has_flags(flags, "cxxflags", opt) end -- has the given features? -- -- @param features the features, e.g. {"c_static_assert", "cxx_constexpr"} -- @param opt the argument options, e.g. {flags = ""} -- -- @return true or false, errors -- function _instance:has_features(features, opt) opt = opt or {} opt.target = self:_checked_target() return sandbox_module.import("core.tool.compiler", {anonymous = true}).has_features(features, opt) end -- check the size of type -- -- @param typename the typename -- @param opt the argument options, e.g. {includes = "xxx.h", configs = {defines = ""}} -- -- @return the type size -- function _instance:check_sizeof(typename, opt) opt = opt or {} opt.target = self:_checked_target() return sandbox_module.import("lib.detect.check_sizeof", {anonymous = true})(typename, opt) end -- check the endianness of compiler -- -- @param opt the argument options, e.g. {includes = "xxx.h", configs = {defines = ""}} -- -- @return the type size -- function _instance:check_bigendian(opt) opt = opt or {} opt.target = self:_checked_target() return sandbox_module.import("lib.detect.check_bigendian", {anonymous = true})(opt) end -- check the given c snippets? -- -- @param snippets the snippets -- @param opt the argument options, e.g. {includes = "xxx.h", configs = {defines = ""}} -- -- @return true or false, errors -- function _instance:check_csnippets(snippets, opt) opt = opt or {} opt.target = self:_checked_target() return sandbox_module.import("lib.detect.check_csnippets", {anonymous = true})(snippets, opt) end -- check the given c++ snippets? -- -- @param snippets the snippets -- @param opt the argument options, e.g. {includes = "xxx.h", configs = {defines = ""}} -- -- @return true or false, errors -- function _instance:check_cxxsnippets(snippets, opt) opt = opt or {} opt.target = self return sandbox_module.import("lib.detect.check_cxxsnippets", {anonymous = true})(snippets, opt) end -- check the given objc snippets? -- -- @param snippets the snippets -- @param opt the argument options, e.g. {includes = "xxx.h", configs = {defines = ""}} -- -- @return true or false, errors -- function _instance:check_msnippets(snippets, opt) opt = opt or {} opt.target = self:_checked_target() return sandbox_module.import("lib.detect.check_msnippets", {anonymous = true})(snippets, opt) end -- check the given objc++ snippets? -- -- @param snippets the snippets -- @param opt the argument options, e.g. {includes = "xxx.h", configs = {defines = ""}} -- -- @return true or false, errors -- function _instance:check_mxxsnippets(snippets, opt) opt = opt or {} opt.target = self:_checked_target() return sandbox_module.import("lib.detect.check_mxxsnippets", {anonymous = true})(snippets, opt) end -- get project function target._project() return target._PROJECT end -- get target apis function target.apis() return { values = { -- target.set_xxx "target.set_kind" , "target.set_plat" , "target.set_arch" , "target.set_strip" , "target.set_rules" , "target.set_group" , "target.add_filegroups" , "target.set_version" , "target.set_license" , "target.set_enabled" , "target.set_default" , "target.set_options" , "target.set_symbols" , "target.set_filename" , "target.set_basename" , "target.set_extension" , "target.set_prefixname" , "target.set_suffixname" , "target.set_warnings" , "target.set_fpmodels" , "target.set_optimize" , "target.set_runtimes" , "target.set_languages" , "target.set_toolchains" , "target.set_runargs" , "target.set_exceptions" , "target.set_encodings" , "target.set_prefixdir" -- target.add_xxx , "target.add_deps" , "target.add_rules" , "target.add_options" , "target.add_packages" , "target.add_imports" , "target.add_languages" , "target.add_vectorexts" , "target.add_toolchains" , "target.add_tests" } , keyvalues = { -- target.set_xxx "target.set_values" , "target.set_configvar" , "target.set_runenv" , "target.set_toolset" , "target.set_policy" -- target.add_xxx , "target.add_values" , "target.add_runenvs" } , paths = { -- target.set_xxx "target.set_targetdir" , "target.set_objectdir" , "target.set_dependir" , "target.set_autogendir" , "target.set_configdir" , "target.set_installdir" , "target.set_rundir" -- target.add_xxx , "target.add_files" , "target.add_cleanfiles" , "target.add_configfiles" , "target.add_installfiles" , "target.add_extrafiles" -- target.del_xxx (deprecated) , "target.del_files" -- target.remove_xxx , "target.remove_files" , "target.remove_headerfiles" , "target.remove_configfiles" , "target.remove_installfiles" , "target.remove_extrafiles" } , script = { -- target.on_xxx "target.on_run" , "target.on_test" , "target.on_load" , "target.on_config" , "target.on_link" , "target.on_build" , "target.on_build_file" , "target.on_build_files" , "target.on_clean" , "target.on_package" , "target.on_install" , "target.on_installcmd" , "target.on_uninstall" , "target.on_uninstallcmd" -- target.before_xxx , "target.before_run" , "target.before_test" , "target.before_link" , "target.before_build" , "target.before_build_file" , "target.before_build_files" , "target.before_clean" , "target.before_package" , "target.before_install" , "target.before_installcmd" , "target.before_uninstall" , "target.before_uninstallcmd" -- target.after_xxx , "target.after_run" , "target.after_test" , "target.after_load" , "target.after_link" , "target.after_build" , "target.after_build_file" , "target.after_build_files" , "target.after_clean" , "target.after_package" , "target.after_install" , "target.after_installcmd" , "target.after_uninstall" , "target.after_uninstallcmd" } } end -- get the filename from the given target name and kind function target.filename(targetname, targetkind, opt) opt = opt or {} assert(targetname and targetkind) -- make filename by format local filename = targetname local format = opt.format or platform.format(targetkind, opt.plat, opt.arch) or "$(name)" if format then local splitinfo = format:split("$(name)", {plain = true, strict = true}) local prefixname = splitinfo[1] or "" local suffixname = "" local extension = splitinfo[2] or "" splitinfo = extension:split('.', {plain = true, limit = 2, strict = true}) if #splitinfo == 2 and splitinfo[1] ~= "" then suffixname = splitinfo[1] extension = "." .. splitinfo[2] end if opt.prefixname then prefixname = opt.prefixname end if opt.suffixname then suffixname = opt.suffixname end if opt.extension then extension = opt.extension end filename = prefixname .. targetname .. suffixname .. extension end return filename end -- get the link name of the target file function target.linkname(filename, opt) -- for implib/mingw, e.g. libxxx.dll.a opt = opt or {} if filename:startswith("lib") and filename:endswith(".dll.a") then return filename:sub(4, #filename - 6) end -- for macOS, libxxx.tbd if filename:startswith("lib") and filename:endswith(".tbd") then return filename:sub(4, #filename - 4) end local linkname, count = filename:gsub(target.filename("__pattern__", "static", {plat = opt.plat}):gsub("%.", "%%."):gsub("__pattern__", "(.+)") .. "$", "%1") if count == 0 then linkname, count = filename:gsub(target.filename("__pattern__", "shared", {plat = opt.plat}):gsub("%.", "%%."):gsub("__pattern__", "(.+)") .. "$", "%1") end -- in order to be compatible with mingw/windows library with .lib if count == 0 and opt.plat == "mingw" then linkname, count = filename:gsub(target.filename("__pattern__", "static", {plat = "windows"}):gsub("%.", "%%."):gsub("__pattern__", "(.+)") .. "$", "%1") end if count > 0 and linkname then return linkname end -- fallback to the generic unix library name, libxxx.a, libxxx.so, .. if filename:startswith("lib") then if filename:endswith(".a") or filename:endswith(".so") then return path.basename(filename:sub(4)) end elseif filename:endswith(".so") or filename:endswith(".dylib") then -- for custom shared libraries name, xxx.so, xxx.dylib return filename end return nil end -- new a target instance function target.new(...) return _instance.new(...) end -- return module return target
0
repos/xmake/xmake/core
repos/xmake/xmake/core/project/config.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file config.lua -- -- define module local config = config or {} -- load modules local io = require("base/io") local os = require("base/os") local path = require("base/path") local table = require("base/table") local utils = require("base/utils") local option = require("base/option") local is_cross = require("base/private/is_cross") -- always use workingdir? -- -- If the -P/-F parameter is specified, we use workingdir as the configuration root -- -- But we cannot call `option.get("project")`, because the menu script -- will also fetch the configdir, but at this point, -- the option has not yet finished parsing. function config._use_workingdir() local use_workingdir = config._USE_WORKINGDIR if use_workingdir == nil then for _, arg in ipairs(xmake._ARGV) do if arg == "-P" or arg == "-F" or arg:startswith("--project=") or arg:startswith("--file=") then use_workingdir = true end end use_workingdir = use_workingdir or false config._USE_WORKINGDIR = use_workingdir end return use_workingdir end -- get the current given configuration function config.get(name) local value = nil if config._CONFIGS then value = config._CONFIGS[name] if type(value) == "string" and value == "auto" then value = nil end end return value end -- this config name is readonly? function config.readonly(name) return config._MODES and config._MODES["__readonly_" .. name] end -- set the given configure to the current -- -- @param name the name -- @param value the value -- @param opt the argument options, e.g. {readonly = false, force = false} -- function config.set(name, value, opt) opt = opt or {} assert(name) assert(opt.force or not config.readonly(name), "cannot set readonly config: " .. name) config._CONFIGS = config._CONFIGS or {} config._CONFIGS[name] = value if opt.readonly then config._MODES = config._MODES or {} config._MODES["__readonly_" .. name] = true end end -- get the current platform function config.plat() return config.get("plat") end -- get the current architecture function config.arch() return config.get("arch") end -- get the current mode function config.mode() return config.get("mode") end -- get the current host function config.host() return config.get("host") end -- get all options function config.options() -- remove values with "auto" and private item local configs = {} if config._CONFIGS then for name, value in pairs(config._CONFIGS) do if not name:find("^_%u+") and (type(value) ~= "string" or value ~= "auto") then configs[name] = value end end end return configs end -- get the buildir -- we can use `{absolute = true}` to force to get absolute path function config.buildir(opt) -- get the absolute path first opt = opt or {} local rootdir -- we always switch to independent working directory if `-P/-F` is set -- @see https://github.com/xmake-io/xmake/issues/3342 if not rootdir and config._use_workingdir() then rootdir = os.workingdir() end -- we switch to independent working directory if .xmake exists -- @see https://github.com/xmake-io/xmake/issues/820 if not rootdir and os.isdir(path.join(os.workingdir(), "." .. xmake._NAME)) then rootdir = os.workingdir() end if not rootdir then rootdir = os.projectdir() end local buildir = config.get("buildir") or "build" if not path.is_absolute(buildir) then buildir = path.absolute(buildir, rootdir) end -- adjust path for the current directory if not opt.absolute then buildir = path.relative(buildir, os.curdir()) end return buildir end -- get the configure file function config.filepath() return path.join(config.directory(), xmake._NAME .. ".conf") end -- get the local cache directory function config.cachedir() return path.join(config.directory(), "cache") end -- get the configure directory on the current host/arch platform function config.directory() if config._DIRECTORY == nil then local rootdir = os.getenv("XMAKE_CONFIGDIR") -- we always switch to independent working directory if `-P/-F` is set -- @see https://github.com/xmake-io/xmake/issues/3342 if not rootdir and config._use_workingdir() then rootdir = os.workingdir() end -- we switch to independent working directory if .xmake exists -- @see https://github.com/xmake-io/xmake/issues/820 if not rootdir and os.isdir(path.join(os.workingdir(), "." .. xmake._NAME)) then rootdir = os.workingdir() end if not rootdir then rootdir = os.projectdir() end config._DIRECTORY = path.join(rootdir, "." .. xmake._NAME, os.host(), os.arch()) end return config._DIRECTORY end -- load the project configuration -- -- @param opt {readonly = true, force = true} -- function config.load(filepath, opt) opt = opt or {} local configs, errors filepath = filepath or config.filepath() if os.isfile(filepath) then configs, errors = io.load(filepath) if not configs then utils.error(errors) return false end end -- merge into the current configuration local ok = false if configs then for name, value in pairs(configs) do if config.get(name) == nil or opt.force then config.set(name, value, opt) ok = true end end end return ok end -- save the project configuration -- -- @note we pass only_changed to avoid frequent changes to the file's mtime, -- because some plugins(vscode, compile_commands.autoupdate) depend on it's mtime. -- 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, {orderkeys = true, only_changed = true}) else return io.save(filepath, config.options(), {orderkeys = true, only_changed = true}) end end -- read value from the configuration file directly function config.read(name) local configs if os.isfile(config.filepath()) then configs = io.load(config.filepath()) end local value = nil if configs then value = configs[name] if type(value) == "string" and value == "auto" then value = nil end end return value end -- clear config function config.clear() config._MODES = nil config._CONFIGS = nil end -- the current mode is belong to the given modes? function config.is_mode(...) return config.is_value("mode", ...) end -- the current platform is belong to the given platforms? function config.is_plat(...) return config.is_value("plat", ...) end -- the current architecture is belong to the given architectures? function config.is_arch(...) return config.is_value("arch", ...) end -- is cross-compilation? function config.is_cross() return is_cross(config.plat(), config.arch()) end -- the current config is belong to the given config values? function config.is_value(name, ...) -- get the current config value local value = config.get(name) if not value then return false end -- exists this value? and escape '-' for _, v in ipairs(table.pack(...)) do if v and type(v) == "string" and value:find("^" .. v:gsub("%-", "%%-") .. "$") then return true end end return false end -- has the given configs? function config.has(...) for _, name in ipairs(table.pack(...)) do if name and type(name) == "string" and config.get(name) then return true end end return false end -- dump the configure function config.dump() if not option.get("quiet") then utils.print("configure") utils.print("{") for name, value in pairs(config.options()) do if not name:startswith("__") then utils.print(" %s = %s", name, value) end end utils.print("}") end end -- return module return config
0
repos/xmake/xmake/core
repos/xmake/xmake/core/project/project.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file project.lua -- -- define module: project local project = project or {} -- load modules local os = require("base/os") local io = require("base/io") local path = require("base/path") local task = require("base/task") local utils = require("base/utils") local table = require("base/table") local global = require("base/global") local process = require("base/process") local hashset = require("base/hashset") local baseoption = require("base/option") local deprecated = require("base/deprecated") local interpreter = require("base/interpreter") local instance_deps = require("base/private/instance_deps") local memcache = require("cache/memcache") local rule = require("project/rule") local target = require("project/target") local config = require("project/config") local option = require("project/option") local policy = require("project/policy") local project_package = require("project/package") local deprecated_project = require("project/deprecated/project") local package = require("package/package") local platform = require("platform/platform") local toolchain = require("tool/toolchain") local language = require("language/language") local sandbox_os = require("sandbox/modules/os") local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- register project to platform, rule and target platform._PROJECT = project target._PROJECT = project rule._PROJECT = project -- the current os is belong to the given os? function project._api_is_os(interp, ...) -- get the current os local os = platform.os() if not os then return false end -- exists this os? for _, o in ipairs(table.join(...)) do if o and type(o) == "string" and o == os then return true end end end -- the current mode is belong to the given modes? function project._api_is_mode(interp, ...) return config.is_mode(...) end -- the current platform is belong to the given platforms? function project._api_is_plat(interp, ...) return config.is_plat(...) end -- the current platform is belong to the given architectures? function project._api_is_arch(interp, ...) return config.is_arch(...) end -- the current platform and architecture is cross-complation? function project._api_is_cross(interp) return config.is_cross() end -- the current kind is belong to the given kinds? function project._api_is_kind(interp, ...) -- get the current kind local kind = config.get("kind") if not kind then return false end -- exists this kind? for _, k in ipairs(table.pack(...)) do if k and type(k) == "string" and k == kind then return true end end end -- the current config is belong to the given config values? function project._api_is_config(interp, name, ...) return config.is_value(name, ...) end -- some configs are enabled? function project._api_has_config(interp, ...) return config.has(...) end -- some packages are enabled? function project._api_has_package(interp, ...) -- only for loading targets local requires = project._memcache():get("requires") if requires then for _, name in ipairs(table.pack(...)) do local pkg = requires[name] if pkg and pkg:enabled() then return true end end end end -- get config from the given name function project._api_get_config(interp, name) return config.get(name) end -- add module directories function project._api_add_moduledirs(interp, ...) local scriptdir = project.interpreter():scriptdir() for _, dir in ipairs({...}) do if not path.is_absolute(dir) then dir = path.absolute(dir, scriptdir) end sandbox_module.add_directories(dir) end end -- add plugin directories load all plugins from the given directories function project._api_add_plugindirs(interp, ...) local scriptdir = project.interpreter():scriptdir() local plugindirs = {} for _, dir in ipairs({...}) do if not path.is_absolute(dir) then dir = path.absolute(dir, scriptdir) end table.insert(plugindirs, dir .. "/*") end interp:api_builtin_includes(plugindirs) end -- add platform directories function project._api_add_platformdirs(interp, ...) local scriptdir = project.interpreter():scriptdir() for _, dir in ipairs({...}) do if not path.is_absolute(dir) then dir = path.absolute(dir, scriptdir) end platform.add_directories(dir) end end -- load the project file function project._load(force, disable_filter) -- has already been loaded? if project._memcache():get("rootinfo") and not force then return true end -- enter the project directory local oldir, errors = os.cd(os.projectdir()) if not oldir then return false, errors end -- get interpreter local interp = project.interpreter() -- load script local ok, errors = interp:load(project.rootfile(), {on_load_data = function (data) for _, xmakerc_file in ipairs(project.rcfiles()) do if xmakerc_file and os.isfile(xmakerc_file) then local rcdata = io.readfile(xmakerc_file) if rcdata then data = rcdata .. "\n" .. data end end end return data end}) if not ok then return false, (errors or "load project file failed!") end -- load the root info of the project local rootinfo, errors = project._load_scope("root", true, not disable_filter) if not rootinfo then return false, errors end -- load the root info of the target local rootinfo_target, errors = project._load_scope("root.target", true, not disable_filter) if not rootinfo_target then return false, errors end -- save the root info project._memcache():set("rootinfo", rootinfo) project._memcache():set("rootinfo_target", rootinfo_target) -- leave the project directory oldir, errors = os.cd(oldir) if not oldir then return false, errors end return true end -- load scope from the project file function project._load_scope(scope_kind, deduplicate, enable_filter) -- enter the project directory local oldir, errors = os.cd(os.projectdir()) if not oldir then return nil, errors end -- get interpreter local interp = project.interpreter() -- load scope local results, errors = interp:make(scope_kind, deduplicate, enable_filter) if not results then return nil, errors end -- leave the project directory oldir, errors = os.cd(oldir) if not oldir then return nil, errors end return results end -- load tasks function project._load_tasks() -- the project file is not found? if not os.isfile(project.rootfile()) then return {}, nil end -- load the project file first and disable filter local ok, errors = project._load(true, true) if not ok then return nil, errors end -- load the tasks from the the project file local results, errors = project._load_scope("task", true, true) if not results then return nil, errors or "load project tasks failed!" end -- bind tasks for menu with an sandbox instance local ok, errors = task._bind(results, project.interpreter()) if not ok then return nil, errors end -- make task instances local tasks = {} for taskname, taskinfo in pairs(results) do tasks[taskname] = task.new(taskname, taskinfo) end return tasks end -- load rules function project._load_rules() -- load the project file first if has not been loaded? local ok, errors = project._load() if not ok then return nil, errors end -- load the rules from the the project file local results, errors = project._load_scope("rule", true, true) if not results then return nil, errors end -- make rule instances local rules = {} for rulename, ruleinfo in pairs(results) do rules[rulename] = rule.new(rulename, ruleinfo) end return rules end -- load toolchains function project._load_toolchains() -- load the project file first if has not been loaded? local ok, errors = project._load() if not ok then return nil, errors end -- load the toolchain from the the project file local results, errors = project._load_scope("toolchain", true, true) if not results then return nil, errors end -- make toolchain instances local toolchains = {} for toolchain_name, toolchain_info in pairs(results) do toolchains[toolchain_name] = toolchain_info end return toolchains end -- load targets function project._load_targets() -- mark targets have been loaded even if it may fail to load. -- because once loaded, there will be some cached state, such as options, -- so if we load it a second time, there will be some hidden state inconsistencies. project._memcache():set("targets_loaded", true) -- load all requires first and reload the project file to ensure has_package() works for targets local requires = project.required_packages() local ok, errors = project._load(true) if not ok then return nil, errors end -- load targets local results, errors = project._load_scope("target", true, true) if not results then return nil, errors end -- make targets local targets = {} for targetname, targetinfo in pairs(results) do local t = target.new(targetname, targetinfo) if t and (t:get("enabled") == nil or t:get("enabled") == true) then targets[targetname] = t end end -- load and attach target deps, rules and packages for _, t in pairs(targets) do -- load rules from target and language t._RULES = t._RULES or {} local rulenames = {} local extensions = {} table.join2(rulenames, t:get("rules")) for _, sourcefile in ipairs(table.wrap(t:get("files"))) do local extension = path.extension((sourcefile:gsub("|.*$", ""))) if not extensions[extension] then local lang = language.load_ex(extension) if lang and lang:rules() then table.join2(rulenames, lang:rules()) end extensions[extension] = true end end rulenames = table.unique(rulenames) for _, rulename in ipairs(rulenames) do local r = project.rule(rulename) or rule.rule(rulename) if r then -- only add target rules if r:kind() == "target" then t._RULES[rulename] = r for _, deprule in ipairs(r:orderdeps()) do t._RULES[deprule:name()] = deprule end end -- we need to ignore `@package/rulename`, it will be loaded later elseif not rulename:match("@.-/") then return nil, string.format("unknown rule(%s) in target(%s)!", rulename, t:name()) end end -- @note it's deprecated, please use on_load instead of before_load ok, errors = t:_load_before() if not ok then return nil, errors end -- we need to call on_load() before building deps/rules, -- so we can use `target:add("deps", "xxx")` to add deps in on_load ok, errors = t:_load() if not ok then return nil, errors end end return targets end -- load options function project._load_options(disable_filter) -- the project file is not found? if not os.isfile(project.rootfile()) then return {}, nil end -- reload the project file to ensure `if is_plat() then add_packagedirs() end` works local ok, errors = project._load(true, disable_filter) if not ok then return nil, errors end -- load the options from the the project file local results, errors = project._load_scope("option", true, not disable_filter) if not results then return nil, errors end -- load the options from the package directories, e.g. packagedir/*.pkg for _, packagedir in ipairs(table.wrap(project.get("packagedirs"))) do local packagefiles = os.files(path.join(packagedir, "*.pkg", "xmake.lua")) if packagefiles then for _, packagefile in ipairs(packagefiles) do -- load the package file local interp = option.interpreter() local ok, errors = interp:load(packagefile) if not ok then return nil, errors end -- load the package options from the the package file local packageinfos, errors = interp:make("option", true, not disable_filter) if not packageinfos then return nil, errors end -- transform includedirs and linkdirs local rootdir = path.directory(packagefile) for _, packageinfo in pairs(packageinfos) do local linkdirs = {} local includedirs = {} for _, linkdir in ipairs(table.wrap(packageinfo:get("linkdirs"))) do table.insert(linkdirs, path.is_absolute(linkdir) and linkdir or path.join(rootdir, linkdir)) end for _, includedir in ipairs(table.wrap(packageinfo:get("includedirs"))) do table.insert(includedirs, path.is_absolute(includedir) and includedir or path.join(rootdir, includedir)) end if #linkdirs > 0 then packageinfo:set("linkdirs", linkdirs) end if #includedirs > 0 then packageinfo:set("includedirs", includedirs) end end table.join2(results, packageinfos) end end end -- check options local options = {} for optionname, optioninfo in pairs(results) do local instance = option.new(optionname, optioninfo) options[optionname] = instance end -- load and attach options deps for _, opt in pairs(options) do opt._DEPS = opt._DEPS or {} opt._ORDERDEPS = opt._ORDERDEPS or {} instance_deps.load_deps(opt, options, opt._DEPS, opt._ORDERDEPS, {opt:name()}) end return options end -- load requires function project._load_requires() -- parse requires local requires = {} local requires_str, requires_extra = project.requires_str() requires_extra = requires_extra or {} for _, requirestr in ipairs(table.wrap(requires_str)) do -- get the package name local packagename = requirestr:split("%s")[1] -- get alias and requireconfs local alias = nil local requireconfs = requires_extra[requirestr] if requireconfs then alias = requireconfs.alias end -- load it from cache first local name = alias or packagename local instance = project_package.load(name) if not instance then local info = {__requirestr = requirestr, __requireconfs = requireconfs} instance = project_package.load_withinfo(name, info) end -- add require info requires[alias or packagename] = instance end return requires end -- load the packages from the the project file and disable filter, we will process filter after a while function project._load_packages() -- load the project file first if has not been loaded? local ok, errors = project._load() if not ok then return nil, errors end -- load packages return project._load_scope("package", true, false) end -- get project memcache function project._memcache() return memcache.cache("core.project.project") end -- get project toolchain infos (@note only with toolchain info) function project._toolchains() local toolchains = project._memcache():get("toolchains") if not toolchains then local errors toolchains, errors = project._load_toolchains() if not toolchains then os.raise(errors) end -- load toolchains from data file from "package.tools.xmake" module local toolchain_datafiles = os.getenv("XMAKE_TOOLCHAIN_DATAFILES") if toolchain_datafiles then toolchain_datafiles = path.splitenv(toolchain_datafiles) if toolchain_datafiles and #toolchain_datafiles > 0 then for _, toolchain_datafile in ipairs(toolchain_datafiles) do local toolchain_inst, errors = toolchain.load_fromfile(toolchain_datafile) if toolchain_inst then -- @note we use this passed toolchain configuration first if this toolchain has been defined in current project toolchains[toolchain_inst:name()] = toolchain_inst else os.raise(errors) end end end end project._memcache():set("toolchains", toolchains) end return toolchains end -- get project apis function project.apis() return { values = { -- set_xxx "set_project" , "set_description" , "set_allowedmodes" , "set_allowedplats" , "set_allowedarchs" , "set_defaultmode" , "set_defaultplat" , "set_defaultarchs" -- add_xxx , "add_requires" , "add_requireconfs" , "add_repositories" } , paths = { -- add_xxx "add_packagedirs" } , keyvalues = { "set_config" } , custom = { -- is_xxx {"is_os", project._api_is_os } , {"is_kind", project._api_is_kind } , {"is_arch", project._api_is_arch } , {"is_mode", project._api_is_mode } , {"is_plat", project._api_is_plat } , {"is_cross", project._api_is_cross } , {"is_config", project._api_is_config } -- get_xxx , {"get_config", project._api_get_config } -- has_xxx , {"has_config", project._api_has_config } , {"has_package", project._api_has_package } -- add_xxx , {"add_moduledirs", project._api_add_moduledirs } , {"add_plugindirs", project._api_add_plugindirs } , {"add_platformdirs", project._api_add_platformdirs } } } end -- get interpreter function project.interpreter() -- the interpreter has been initialized? return it directly if project._INTERPRETER then return project._INTERPRETER end -- init interpreter local interp = interpreter.new() assert(interp) -- set root directory interp:rootdir_set(project.directory()) -- set root scope interp:rootscope_set("target") -- define apis for rule interp:api_define(rule.apis()) -- define apis for task interp:api_define(task.apis()) -- define apis for target interp:api_define(target.apis()) -- define apis for option interp:api_define(option.apis()) -- define apis for package interp:api_define(package.apis()) -- define apis for language interp:api_define(language.apis()) -- define apis for toolchain interp:api_define(toolchain.apis()) -- define apis for project interp:api_define(project.apis()) -- we need to be able to precisely control the direction of deduplication of different types of values. -- the default is to de-duplicate from left to right, but like links/syslinks need to be de-duplicated from right to left. -- -- @see https://github.com/xmake-io/xmake/issues/1903 -- interp:deduplication_policy_set("links", "toleft") interp:deduplication_policy_set("syslinks", "toleft") interp:deduplication_policy_set("frameworks", "toleft") -- register api: deprecated deprecated_project.api_register(interp) -- set filter interp:filter():register("project", function (variable) -- check assert(variable) -- hack buildir first if variable == "buildir" then return config.buildir() end -- attempt to get it directly from the configure local result = config.get(variable) if not result or type(result) ~= "string" then -- init maps local maps = { os = platform.os() , host = os.host() , subhost = os.subhost() , tmpdir = function () return os.tmpdir() end , curdir = function () return os.curdir() end , scriptdir = function () return interp:pending() and interp:scriptdir() or sandbox_os.scriptdir() end , globaldir = global.directory() , configdir = config.directory() , projectdir = project.directory() , programdir = os.programdir() } -- map it result = maps[variable] if type(result) == "function" then result = result() end end return result end) -- save interpreter project._INTERPRETER = interp -- ok? return interp end -- get the root project file function project.rootfile() return os.projectfile() end -- get all loaded project files with subfiles (xmake.lua) function project.allfiles() local files = {} table.join2(files, project.interpreter():scriptfiles()) for _, rcfile in ipairs(project.rcfiles()) do if rcfile and os.isfile(rcfile) then table.insert(files, rcfile) end end return files end -- get the global rcfiles: ~/.xmakerc.lua function project.rcfiles() local rcfiles = project._XMAKE_RCFILES if rcfiles == nil then rcfiles = {} local rcpaths = {} local rcpaths_env = os.getenv("XMAKE_RCFILES") if rcpaths_env then table.join2(rcpaths, path.splitenv(rcpaths_env)) end table.join2(rcpaths, {"/etc/xmakerc.lua", "~/.xmakerc.lua", path.join(global.directory(), "xmakerc.lua")}) for _, rcfile in ipairs(rcpaths) do if os.isfile(rcfile) then table.insert(rcfiles, rcfile) end end project._XMAKE_RCFILES = rcfiles end return rcfiles end -- get the project directory function project.directory() return os.projectdir() end -- get the filelock of the whole project directory function project.filelock() local errors local filelock = project._FILELOCK if filelock == nil then filelock, errors = io.openlock(path.join(config.directory(), "project.lock")) project._FILELOCK = filelock end return filelock, errors end -- get the root configuration function project.get(name) local rootinfo if name and name:startswith("target.") then name = name:sub(8) rootinfo = project._memcache():get("rootinfo_target") else rootinfo = project._memcache():get("rootinfo") end return rootinfo and rootinfo:get(name) or nil end -- get the root extra configuration function project.extraconf(name, item, key) local rootinfo if name and name:startswith("target.") then name = name:sub(8) rootinfo = project._memcache():get("rootinfo_target") else rootinfo = project._memcache():get("rootinfo") end return rootinfo and rootinfo:extraconf(name, item, key) or nil end -- get the project name function project.name() local name = project.get("project") -- TODO multi project names? we only get the first name now. -- and we need to improve it in the future. if type(name) == "table" then name = name[1] end return name end -- get the project version, the root version of the target scope function project.version() return project.get("target.version") end -- get the project policy, the root policy of the target scope function project.policy(name) local policies = project._memcache():get("policies") if not policies then -- get policies from project, e.g. set_policy("xxx", true) policies = project.get("target.policy") -- get policies from config, e.g. xmake f --policies=package.precompiled:n,package.install_only -- @see https://github.com/xmake-io/xmake/issues/2318 local policies_config = config.get("policies") if policies_config then for _, policy in ipairs(policies_config:split(",", {plain = true})) do local splitinfo = policy:split(":", {limit = 2}) local name = splitinfo[1] if #splitinfo > 1 then policies = policies or {} policies[name] = baseoption.boolean(splitinfo[2]) else policies = policies or {} policies[name] = true end end end -- get policies from global, e.g. xmake g --policies=run.autobuild local policies_config_global = global.get("policies") if policies_config_global then for _, policy in ipairs(policies_config_global:split(",", {plain = true})) do local splitinfo = policy:split(":", {limit = 2}) local name = splitinfo[1] if #splitinfo > 1 then policies = policies or {} if policies[name] == nil then policies[name] = baseoption.boolean(splitinfo[2]) end else policies = policies or {} if policies[name] == nil then policies[name] = true end end end end project._memcache():set("policies", policies) if policies then local defined_policies = policy.policies() for name, _ in pairs(policies) do if not defined_policies[name] then utils.warning("unknown policy(%s), please run `xmake l core.project.policy.policies` if you want to all policies", name) end end end end return policy.check(name, policies and policies[name]) end -- project has been loaded? function project.is_loaded() return project._memcache():get("targets_loaded") end -- get the given target function project.target(name) local targets = project.targets() return targets and targets[name] end -- add the given target, @note if the target name is the same, it will be replaced function project.target_add(t) local targets = project.targets() if targets then targets[t:name()] = t project._memcache():set("ordertargets", nil) end end -- get targets function project.targets() local loading = false local targets = project._memcache():get("targets") if not targets then local errors targets, errors = project._load_targets() if errors then os.raise(errors) end project._memcache():set("targets", targets) loading = true end if loading then -- do after_load() for targets -- @note we must call it after finishing to cache targets -- because we maybe will call project.targets() in after_load, we need avoid dead recursion loop for _, t in ipairs(project.ordertargets()) do local ok, errors = t:_load_after() if not ok then os.raise(errors or string.format("load target %s failed", t:name())) end end end return targets end -- get order targets function project.ordertargets() local ordertargets = project._memcache():get("ordertargets") if not ordertargets then ordertargets = instance_deps.sort(project.targets()) project._memcache():set("ordertargets", ordertargets) end return ordertargets end -- get the given option function project.option(name) return project.options()[name] end -- get options function project.options() local options = project._memcache():get("options") if not options then local errors options, errors = project._load_options() if not options then os.raise(errors) end project._memcache():set("options", options) end return options end -- get the given required package function project.required_package(name) return project.required_packages()[name] end -- get required packages function project.required_packages() local requires = project._memcache():get("requires") if not requires then local errors requires, errors = project._load_requires() if not requires then os.raise(errors) end project._memcache():set("requires", requires) end return requires end -- get string requires function project.requires_str() local requires_str = project._memcache():get("requires_str") local requires_extra = project._memcache():get("requires_extra") if not requires_str then -- reload the project file to handle `has_config()` local ok, errors = project._load(true) if not ok then os.raise(errors) end -- get raw requires requires_str, requires_extra = project.get("requires"), project.get("__extra_requires") project._memcache():set("requires_str", requires_str or false) project._memcache():set("requires_extra", requires_extra) -- get raw requireconfs local requireconfs_str, requireconfs_extra = project.get("requireconfs"), project.get("__extra_requireconfs") project._memcache():set("requireconfs_str", requireconfs_str or false) project._memcache():set("requireconfs_extra", requireconfs_extra) end return requires_str or nil, requires_extra end -- get string requireconfs function project.requireconfs_str() project.requires_str() local requireconfs_str = project._memcache():get("requireconfs_str") local requireconfs_extra = project._memcache():get("requireconfs_extra") return requireconfs_str, requireconfs_extra end -- get requires lockfile function project.requireslock() return path.join(project.directory(), "xmake-requires.lock") end -- get the format version of requires lockfile function project.requireslock_version() return "1.0" end -- get the given rule function project.rule(name) return project.rules()[name] end -- get project rules function project.rules() local rules = project._memcache():get("rules") if not rules then local errors rules, errors = project._load_rules() if not rules then os.raise(errors) end project._memcache():set("rules", rules) end return rules end -- get the given toolchain function project.toolchain(name, opt) local toolchain_name = toolchain.parsename(name) -- we need to ignore `@packagename` local info = project._toolchains()[toolchain_name] if info then return toolchain.load_withinfo(name, info, opt) end end -- get project toolchains list function project.toolchains() return table.keys(project._toolchains()) end -- get the given task function project.task(name) return project.tasks()[name] end -- get tasks function project.tasks() local tasks = project._memcache():get("tasks") if not tasks then local errors tasks, errors = project._load_tasks() if not tasks then os.raise(errors) end project._memcache():set("tasks", tasks) end return tasks end -- get packages function project.packages() local packages = project._memcache():get("packages") if not packages then local errors packages, errors = project._load_packages() if not packages then return nil, errors end project._memcache():set("packages", packages) end return packages end -- get the mtimes function project.mtimes() local mtimes = project._MTIMES if not mtimes then mtimes = project.interpreter():mtimes() for _, rcfile in ipairs(project.rcfiles()) do mtimes[rcfile] = os.mtime(rcfile) end project._MTIMES = mtimes end return mtimes end -- get the project menu function project.menu() -- attempt to load options from the project file local options = nil local errors = nil if os.isfile(project.rootfile()) then options, errors = project._load_options(true) end -- failed? if not options then if errors then utils.error(errors) end return {} end -- arrange options by category local options_by_category = {} for _, opt in pairs(options) do -- make the category local category = "default" if opt:get("category") then category = table.unwrap(opt:get("category")) end options_by_category[category] = options_by_category[category] or {} -- append option to the current category options_by_category[category][opt:name()] = opt end -- make menu by category local menu = {} for k, opts in pairs(options_by_category) do -- insert options local first = true for name, opt in pairs(opts) do -- show menu? if opt:showmenu() ~= false then -- the default value local default = "auto" if opt:get("default") ~= nil then default = opt:get("default") end -- is first? if first then -- insert a separator table.insert(menu, {}) -- not first first = false end -- append it local longname = name local description = opt:description() if description then -- define menu option local menu_options = {nil, longname, "kv", default, description} -- handle set_description("xx", "xx") if type(description) == "table" then for i, description in ipairs(description) do menu_options[4 + i] = description end end -- insert option into menu table.insert(menu, menu_options) else table.insert(menu, {nil, longname, "kv", default, nil}) end end end end return menu end -- get the temporary directory of project function project.tmpdir(opt) local tmpdir = project._TMPDIR if not tmpdir then if os.isdir(config.directory()) then local tmpdir_root = path.join(config.directory(), "tmp") tmpdir = path.join(tmpdir_root, os.date("%y%m%d")) if not os.isdir(tmpdir) then os.mkdir(tmpdir) end else tmpdir = os.tmpdir() end end return tmpdir end -- generate the temporary file path of project -- -- e.g. -- project.tmpfile("key") -- project.tmpfile({key = "xxx"}) -- function project.tmpfile(opt_or_key) local opt local key = opt_or_key if type(key) == "table" then key = opt_or_key.key opt = opt_or_key end return path.join(project.tmpdir(opt), "_" .. (hash.uuid4(key):gsub("-", ""))) end -- get all modes function project.modes() local modes local allowed_modes = project.allowed_modes() if allowed_modes then modes = allowed_modes:to_array() else modes = {} for _, target in table.orderpairs(table.wrap(project.targets())) do for _, rule in ipairs(target:orderules()) do local name = rule:name() if name:startswith("mode.") then table.insert(modes, name:sub(6)) end end end modes = table.unique(modes) end return modes end -- get default architectures from the given platform -- -- set_defaultarchs("linux|x86_64", "iphoneos|arm64") -- function project.default_arch(plat) local default_archs = project._memcache():get("defaultarchs") if not default_archs then default_archs = {} for _, defaultarch in ipairs(table.wrap(project.get("defaultarchs"))) do local splitinfo = defaultarch:split('|') if #splitinfo == 2 then default_archs[splitinfo[1]] = splitinfo[2] elseif #splitinfo == 1 and not default_archs.default then default_archs.default = defaultarch end end project._memcache():set("defaultarchs", default_archs or false) end return default_archs[plat or "default"] or default_archs["default"] end -- get allowed modes -- -- set_allowedmodes("releasedbg", "debug") -- function project.allowed_modes() local allowed_modes_set = project._memcache():get("allowedmodes") if not allowed_modes_set then local allowed_modes = table.wrap(project.get("allowedmodes")) if #allowed_modes > 0 then allowed_modes_set = hashset.from(allowed_modes) end project._memcache():set("allowedmodes", allowed_modes_set or false) end return allowed_modes_set or nil end -- get allowed platforms -- -- set_allowedplats("windows", "mingw", "linux", "macosx") -- function project.allowed_plats() local allowed_plats_set = project._memcache():get("allowedplats") if not allowed_plats_set then local allowed_plats = table.wrap(project.get("allowedplats")) if #allowed_plats > 0 then allowed_plats_set = hashset.from(allowed_plats) end project._memcache():set("allowedplats", allowed_plats_set or false) end return allowed_plats_set or nil end -- get allowed architectures -- -- set_allowedarchs("macosx|arm64", "macosx|x86_64", "linux|i386") -- function project.allowed_archs(plat) plat = plat or "" local allowed_archs_set = project._memcache():get2("allowedarchs", plat) if not allowed_archs_set then local allowed_archs = table.wrap(project.get("allowedarchs")) if #allowed_archs > 0 then for _, allowed_arch in ipairs(allowed_archs) do local splitinfo = allowed_arch:split('|') local splitplat, splitarch if #splitinfo == 2 then splitplat = splitinfo[1] splitarch = splitinfo[2] elseif #splitinfo == 1 then splitarch = allowed_arch end if plat == splitplat or splitplat == nil then if not allowed_archs_set then allowed_archs_set = hashset.new() end allowed_archs_set:insert(splitarch) end end end project._memcache():set2("allowedarchs", plat, allowed_archs_set or false) end return allowed_archs_set or nil end -- return module: project return project
0
repos/xmake/xmake/core
repos/xmake/xmake/core/project/policy.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file policy.lua -- -- define module: policy local policy = policy or {} -- load modules local os = require("base/os") local io = require("base/io") local path = require("base/path") local table = require("base/table") local utils = require("base/utils") local string = require("base/string") -- get all defined policies function policy.policies() local policies = policy._POLICIES if not policies then policies = { -- We will check and ignore all unsupported flags by default, but we can also pass `{force = true}` to force to set flags, e.g. add_ldflags("-static", {force = true}) ["check.auto_ignore_flags"] = {description = "Enable check and ignore unsupported flags automatically.", default = true, type = "boolean"}, -- We will map gcc flags to the current compiler and linker by default. ["check.auto_map_flags"] = {description = "Enable map gcc flags to the current compiler and linker automatically.", default = true, type = "boolean"}, -- We will check the compatibility of target and package licenses ["check.target_package_licenses"] = {description = "Enable check the compatibility of target and package licenses.", default = true, type = "boolean"}, -- Generate intermediate build directory ["build.intermediate_directory"] = {description = "Generate intermediate build directory.", default = true, type = "boolean"}, -- Provide a way to block all targets build that depends on self ["build.fence"] = {description = "Block all targets build that depends on self.", default = false, type = "boolean"}, -- We can compile the source files for each target in parallel ["build.across_targets_in_parallel"] = {description = "Enable compile the source files for each target in parallel.", default = true, type = "boolean"}, -- Merge archive intead of linking for all dependent targets ["build.merge_archive"] = {description = "Enable merge archive intead of linking for all dependent targets.", default = false, type = "boolean"}, -- C/C++ build cache ["build.ccache"] = {description = "Enable C/C++ build cache.", type = "boolean"}, -- Use global storage if build.ccache is enabled ["build.ccache.global_storage"] = {description = "Use global storge if build.ccache is enabled.", type = "boolean"}, -- Always update configfiles when building ["build.always_update_configfiles"] = {description = "Always update configfiles when building.", type = "boolean"}, -- Enable build warning output, it's enabled by default. ["build.warning"] = {description = "Enable build warning output.", default = true, type = "boolean"}, -- Enable LTO linker-time optimization for c/c++ building. ["build.optimization.lto"] = {description = "Enable LTO linker-time optimization for c/c++ building.", type = "boolean"}, -- Enable address sanitizer for c/c++ building. ["build.sanitizer.address"] = {description = "Enable address sanitizer for c/c++ building.", type = "boolean"}, -- Enable thread sanitizer for c/c++ building. ["build.sanitizer.thread"] = {description = "Enable thread sanitizer for c/c++ building.", type = "boolean"}, -- Enable memort sanitizer for c/c++ building. ["build.sanitizer.memory"] = {description = "Enable memory sanitizer for c/c++ building.", type = "boolean"}, -- Enable leak sanitizer for c/c++ building. ["build.sanitizer.leak"] = {description = "Enable leak sanitizer for c/c++ building.", type = "boolean"}, -- Enable undefined sanitizer for c/c++ building. ["build.sanitizer.undefined"] = {description = "Enable undefined sanitizer for c/c++ building.", type = "boolean"}, -- Enable build rpath ["build.rpath"] = {description = "Enable build rpath.", default = true, type = "boolean"}, -- Enable C++ modules for C++ building, even if no .mpp is involved in the compilation ["build.c++.modules"] = {description = "Enable C++ modules for C++ building.", type = "boolean"}, -- Enable std module ["build.c++.modules.std"] = {description = "Enable std modules.", default = true, type = "boolean"}, -- Enable unreferenced and non-public named module culling ["build.c++.modules.culling"] = {description = "Enable unrefereced and non-public named module culling.", default = true, type = "boolean"}, -- Try to reuse compiled module bmi file if targets flags permit it ["build.c++.modules.tryreuse"] = {description = "Try to reuse compiled module if possible.", default = true, type = "boolean"}, -- Enable module taking defines acbount for bmi reuse discrimination ["build.c++.modules.tryreuse.discriminate_on_defines"] = {description = "Enable defines module reuse discrimination.", default = false, type = "boolean"}, -- Force C++ modules fallback dependency scanner for clang ["build.c++.clang.fallbackscanner"] = {description = "Force clang fallback module dependency scanner.", default = false, type = "boolean"}, -- Force C++ modules fallback dependency scanner for msvc ["build.c++.msvc.fallbackscanner"] = {description = "Force msvc fallback module dependency scanner.", default = false, type = "boolean"}, -- Force C++ modules fallback dependency scanner for gcc ["build.c++.gcc.fallbackscanner"] = {description = "Force gcc fallback module dependency scanner.", default = false, type = "boolean"}, -- Force to enable new cxx11 abi in C++ modules for gcc -- If in the future, gcc can support it well, we'll turn it on by default -- https://github.com/xmake-io/xmake/issues/3855 ["build.c++.gcc.modules.cxx11abi"] = {description = "Force to enable new cxx11 abi in C++ modules for gcc.", type = "boolean"}, -- Enable cuda device link ["build.cuda.devlink"] = {description = "Enable Cuda devlink.", type = "boolean"}, -- Enable windows UAC and set level, e.g. invoker, admin, highest ["windows.manifest.uac"] = {description = "Enable windows manifest UAC.", type = "string"}, -- Enable ui access for windows UAC ["windows.manifest.uac.ui"] = {description = "Enable windows manifest UAC.", type = "boolean"}, -- Automatically build before running ["run.autobuild"] = {description = "Automatically build before running.", type = "boolean"}, -- Enable install rpath ["install.rpath"] = {description = "Enable install rpath.", default = true, type = "boolean"}, -- Preprocessor configuration for ccache/distcc, we can disable linemarkers to speed up preprocess ["preprocessor.linemarkers"] = {description = "Enable linemarkers for preprocessor.", default = true, type = "boolean"}, -- Preprocessor configuration for ccache/distcc, we can disable it to avoid cache object file with __DATE__, __TIME__ ["preprocessor.gcc.directives_only"] = {description = "Enable -fdirectives-only for gcc preprocessor.", type = "boolean"}, -- We need to enable longpaths when building target or installing package ["platform.longpaths"] = {description = "Enable long paths when building target or installing package on windows.", default = false, type = "boolean"}, -- Lock required packages ["package.requires_lock"] = {description = "Enable xmake-requires.lock to lock required packages.", default = false, type = "boolean"}, -- Enable the precompiled packages, it will be enabled by default ["package.precompiled"] = {description = "Enable precompiled packages.", default = true, type = "boolean"}, -- Only fetch packages on system ["package.fetch_only"] = {description = "Only fetch packages on system.", type = "boolean"}, -- Only install packages from remote ["package.install_only"] = {description = "Only install packages from remote.", type = "boolean"}, -- Always install packages every time ["package.install_always"] = {description = "Always install packages every time.", type = "boolean"}, -- Install packages in the local project folder ["package.install_locally"] = {description = "Install packages in the local project folder.", default = false, type = "boolean"}, -- Set custom headers when downloading package ["package.download.http_headers"] = {description = "Set the custom http headers when downloading package."}, -- Use includes as external header files? e.g. -isystem .. ["package.include_external_headers"] = {description = "Use includes as external headers.", type = "boolean"}, -- Inherit the configs from the external command arguments, e.g. toolchains, `xmake f --toolchain=` ["package.inherit_external_configs"] = {description = "Inherit the configs from the external command arguments.", default = true, type = "boolean"}, -- Set strict compatibility for package and it's all child packages. we can just set it in package(). -- if true, then any updates to this package, such as buildhash changes due to version changes, -- will force all installed child packages to be recompiled and installed, @see https://github.com/xmake-io/xmake/issues/2719 ["package.strict_compatibility"] = {description = "Set strict compatibility for package and it's all child packages.", type = "boolean"}, -- Set strict compatibility for package and it's all library dependencies. we can set it in package() and user project configuration. -- if true, then any updates to library dependencies, such as buildhash changes due to version changes, -- will force the installed packages to be recompiled and installed. @see https://github.com/xmake-io/xmake/issues/2719 ["package.librarydeps.strict_compatibility"] = {description = "Set strict compatibility for package and it's all library dependencies.", type = "boolean"}, -- Automatically passes dependency configuration for inner xmake package -- https://github.com/xmake-io/xmake/issues/3952 ["package.xmake.pass_depconfs"] = {description = "Automatically passes dependency configuration for inner xmake package", default = true, type = "boolean"}, -- It will force cmake package use ninja for build ["package.cmake_generator.ninja"] = {description = "Set cmake package use ninja for build", default = false, type = "boolean"}, -- Enable msbuild MultiToolTask ["package.msbuild.multi_tool_task"] = {description = "Enable msbuild MultiToolTask.", default = false, type = "boolean"}, -- Stop to test on the first failure ["test.stop_on_first_failure"] = {description = "Stop to test on the first failure", default = false, type = "boolean"}, -- Return zero as exit code on failure ["test.return_zero_on_failure"] = {description = "Return zero as the exit code on failure", default = false, type = "boolean"}, -- Show diagnosis info for checking build dependencies ["diagnosis.check_build_deps"] = {description = "Show diagnosis info for checking build dependencies", default = false, type = "boolean"}, -- Set the network mode, e.g. public/private -- private: it will disable fetch remote package repositories ["network.mode"] = {description = "Set the network mode", type = "string"} } policy._POLICIES = policies end return policies end -- check policy value function policy.check(name, value) local defined_policy = policy.policies()[name] if defined_policy then if value == nil then value = defined_policy.default else local valtype = type(value) if valtype ~= defined_policy.type then utils.warning("policy(%s): invalid value type(%s), it shound be '%s'!", name, valtype, defined_policy.type) end end return value else os.raise("unknown policy(%s)!", name) end end -- return module: policy return policy
0
repos/xmake/xmake/core
repos/xmake/xmake/core/project/template.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file template.lua -- -- define module: template local template = template or {} local _instance = _instance or {} -- load modules local os = require("base/os") local io = require("base/io") local path = require("base/path") local table = require("base/table") local utils = require("base/utils") local string = require("base/string") local interpreter = require("base/interpreter") -- new an instance function _instance.new(name, info, scriptdir) local instance = table.inherit(_instance) instance._NAME = name instance._INFO = info instance._SCRIPTDIR = scriptdir return instance end -- get the package name function _instance:name() return self._NAME end -- get the package configure function _instance:get(name) -- get it from info first local value = self._INFO:get(name) if value ~= nil then return value end end -- get the script directory function _instance:scriptdir() return self._SCRIPTDIR end -- the interpreter function template._interpreter() -- the interpreter has been initialized? return it directly if template._INTERPRETER then return template._INTERPRETER end -- init interpreter local interp = interpreter.new() assert(interp) -- define apis interp:api_define { values = { -- add_xxx "template.add_configfiles" } , script = { -- after_xxx "template.after_create" } } -- save interpreter template._INTERPRETER = interp -- ok? return interp end -- get the language list function template.languages() -- make list local list = {} -- get the language list local languages = os.dirs(path.join(os.programdir(), "templates", "*")) if languages then for _, v in ipairs(languages) do table.insert(list, path.basename(v)) end end -- ok? return list end -- load all templates from the given language function template.templates(language) -- check assert(language) -- get interpreter local interp = template._interpreter() assert(interp) -- load all templates local templates = {} local templatefiles = os.files(path.join(os.programdir(), "templates", language, "*", "template.lua")) if templatefiles then -- load template for _, templatefile in ipairs(templatefiles) do -- load script local ok, errors = interp:load(templatefile) if not ok then os.raise(errors) end -- load template local results, errors = interp:make("template", true, true) if not results then os.raise(errors) end -- get the template name and info local templatename = nil local templateinfo = nil for name, info in pairs(results) do templatename = name templateinfo = info break end if not templateinfo then return nil, string.format("%s: package not found!", templatefile) end -- new an instance local instance = _instance.new(templatename, templateinfo, path.directory(templatefile)) -- insert to templates table.insert(templates, instance) end end return templates end -- return module: template return template
0
repos/xmake/xmake/core
repos/xmake/xmake/core/project/rule.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file rule.lua -- -- define module local rule = rule or {} local _instance = _instance or {} -- load modules local os = require("base/os") local path = require("base/path") local utils = require("base/utils") local table = require("base/table") local global = require("base/global") local interpreter = require("base/interpreter") local instance_deps = require("base/private/instance_deps") local select_script = require("base/private/select_script") local config = require("project/config") local sandbox = require("sandbox/sandbox") local sandbox_os = require("sandbox/modules/os") local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- get package function _instance:_package() return self._PACKAGE end -- invalidate the previous cache function _instance:_invalidate(name) if name == "deps" then self._DEPS = nil self._ORDERDEPS = nil end end -- build deps function _instance:_build_deps() local instances = table.clone(rule.rules()) if rule._project() then table.join2(instances, rule._project().rules()) end if self:_package() then table.join2(instances, self:_package():rules()) end self._DEPS = self._DEPS or {} self._ORDERDEPS = self._ORDERDEPS or {} instance_deps.load_deps(self, instances, self._DEPS, self._ORDERDEPS, {self:name()}) end -- clone rule function _instance:clone() local instance = rule.new(self:name(), self._INFO:clone()) instance._DEPS = self._DEPS instance._ORDERDEPS = self._ORDERDEPS instance._PACKAGE = self._PACKAGE return instance end -- get the rule info function _instance:get(name) return self._INFO:get(name) end -- set the value to the rule info function _instance:set(name, ...) self._INFO:apival_set(name, ...) self:_invalidate(name) end -- add the value to the rule info function _instance:add(name, ...) self._INFO:apival_add(name, ...) self:_invalidate(name) end -- get the extra configuration function _instance:extraconf(name, item, key) return self._INFO:extraconf(name, item, key) end -- set the extra configuration function _instance:extraconf_set(name, item, key, value) return self._INFO:extraconf_set(name, item, key, value) end -- get the rule name function _instance:name() return self._NAME end -- set the rule name function _instance:name_set(name) self._NAME = name end -- get the rule kind -- -- current supported kind: -- - target: default, only for each target -- - project: global rule, for whole project -- function _instance:kind() return self:get("kind") or "target" end -- get the given dependent rule function _instance:dep(name) local deps = self:deps() if deps then return deps[name] end end -- get rule deps function _instance:deps() if self._DEPS == nil then self:_build_deps() end return self._DEPS end -- get rule order deps function _instance:orderdeps() if self._DEPS == nil then self:_build_deps() end return self._ORDERDEPS end -- get xxx_script function _instance:script(name, generic) -- get script local script = self:get(name) local result = select_script(script, {plat = config.get("plat"), arch = config.get("arch")}) or generic -- imports some modules first if result and result ~= generic then local scope = getfenv(result) if scope then for _, modulename in ipairs(table.wrap(self:get("imports"))) do scope[sandbox_module.name(modulename)] = sandbox_module.import(modulename, {anonymous = true}) end end end return result end -- the directories of rule function rule._directories() return { path.join(global.directory(), "rules") , path.join(os.programdir(), "rules") } end -- the interpreter function rule._interpreter() -- the interpreter has been initialized? return it directly if rule._INTERPRETER then return rule._INTERPRETER end -- init interpreter local interp = interpreter.new() assert(interp) -- define apis interp:api_define(rule.apis()) -- set filter interp:filter():register("rule", function (variable) -- check assert(variable) -- attempt to get it directly from the configure local result = config.get(variable) if not result or type(result) ~= "string" then -- init maps local maps = { host = os.host() , tmpdir = function () return os.tmpdir() end , curdir = function () return os.curdir() end , scriptdir = function () return sandbox_os.scriptdir() end , globaldir = global.directory() , configdir = config.directory() , projectdir = os.projectdir() , programdir = os.programdir() } -- map it result = maps[variable] if type(result) == "function" then result = result() end end -- ok? return result end) -- save interpreter rule._INTERPRETER = interp return interp end -- get project function rule._project() return rule._PROJECT end -- load rule function rule._load(filepath) -- get interpreter local interp = rule._interpreter() assert(interp) -- load script local ok, errors = interp:load(filepath) if not ok then return nil, errors end -- load rules local results, errors = interp:make("rule", true, true) if not results then return nil, errors end return results end -- get rule apis function rule.apis() return { values = { -- rule.set_xxx "rule.set_extensions" , "rule.set_sourcekinds" , "rule.set_kind" -- rule.add_xxx , "rule.add_deps" , "rule.add_imports" } , script = { -- rule.on_xxx "rule.on_run" , "rule.on_test" , "rule.on_load" , "rule.on_config" , "rule.on_link" , "rule.on_build" , "rule.on_build_file" , "rule.on_build_files" , "rule.on_clean" , "rule.on_package" , "rule.on_install" , "rule.on_installcmd" , "rule.on_uninstall" , "rule.on_uninstallcmd" , "rule.on_linkcmd" , "rule.on_buildcmd" , "rule.on_buildcmd_file" , "rule.on_buildcmd_files" -- rule.before_xxx , "rule.before_run" , "rule.before_test" , "rule.before_load" , "rule.before_link" , "rule.before_build" , "rule.before_build_file" , "rule.before_build_files" , "rule.before_clean" , "rule.before_package" , "rule.before_install" , "rule.before_installcmd" , "rule.before_uninstall" , "rule.before_uninstallcmd" , "rule.before_linkcmd" , "rule.before_buildcmd" , "rule.before_buildcmd_file" , "rule.before_buildcmd_files" -- rule.after_xxx , "rule.after_run" , "rule.after_test" , "rule.after_load" , "rule.after_link" , "rule.after_build" , "rule.after_build_file" , "rule.after_build_files" , "rule.after_clean" , "rule.after_package" , "rule.after_install" , "rule.after_installcmd" , "rule.after_uninstall" , "rule.after_uninstallcmd" , "rule.after_linkcmd" , "rule.after_buildcmd" , "rule.after_buildcmd_file" , "rule.after_buildcmd_files" } } end -- new a rule instance function rule.new(name, info, opt) opt = opt or {} local instance = table.inherit(_instance) instance._NAME = name instance._INFO = info instance._PACKAGE = opt.package if opt.package then -- replace deps in package, @bar -> @zlib/bar -- @see https://github.com/xmake-io/xmake/issues/2374 -- -- packages/z/zlib/rules/foo.lua -- @code -- rule("foo") -- add_deps("@bar") -- @endcode -- -- package/z/zlib/rules/foo.lua -- @code -- rule("bar") -- ... -- @endcode -- local deps = {} for _, depname in ipairs(table.wrap(instance:get("deps"))) do -- @xxx -> @package/xxx if depname:startswith("@") and not depname:find("/", 1, true) then depname = "@" .. opt.package:name() .. "/" .. depname:sub(2) end table.insert(deps, depname) end deps = table.unwrap(deps) if deps and #deps > 0 then instance:set("deps", deps) end for depname, extraconf in pairs(table.wrap(instance:extraconf("deps"))) do if depname:startswith("@") and not depname:find("/", 1, true) then depname = "@" .. opt.package:name() .. "/" .. depname:sub(2) instance:extraconf_set("deps", depname, extraconf) end end end return instance end -- get the given global rule function rule.rule(name) return rule.rules()[name] end -- get global rules function rule.rules() local rules = rule._RULES if rules == nil then local ruleinfos = {} local dirs = rule._directories() for _, dir in ipairs(dirs) do local files = os.files(path.join(dir, "**/xmake.lua")) if files then for _, filepath in ipairs(files) do local results, errors = rule._load(filepath) if results then table.join2(ruleinfos, results) else os.raise(errors) end end end end -- make rule instances rules = {} for rulename, ruleinfo in pairs(ruleinfos) do local instance = rule.new(rulename, ruleinfo) rules[rulename] = instance end rule._RULES = rules end return rules end -- return module return rule
0
repos/xmake/xmake/core
repos/xmake/xmake/core/project/option.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file option.lua -- -- define module local option = {} local _instance = {} -- load modules local io = require("base/io") local os = require("base/os") local path = require("base/path") local table = require("base/table") local utils = require("base/utils") local baseoption = require("base/option") local global = require("base/global") local scopeinfo = require("base/scopeinfo") local interpreter = require("base/interpreter") local config = require("project/config") local localcache = require("cache/localcache") local linker = require("tool/linker") local compiler = require("tool/compiler") local sandbox = require("sandbox/sandbox") local language = require("language/language") local sandbox = require("sandbox/sandbox") local sandbox_os = require("sandbox/modules/os") local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- new an instance function _instance.new(name, info) local instance = table.inherit(_instance) instance._NAME = name instance._INFO = info instance._CACHEID = 1 return instance end -- save the option info to the cache function _instance:_save() -- clear scripts for caching to file local check = self:get("check") local check_after = self:get("check_after") local check_before = self:get("check_before") self:set("check", nil) self:set("check_after", nil) self:set("check_before", nil) -- save option option._cache():set(self:name(), self:info()) -- restore scripts self:set("check", check) self:set("check_after", check_after) self:set("check_before", check_before) end -- clear the option info for cache function _instance:_clear() option._cache():set(self:name(), nil) end -- check snippets function _instance:_do_check_cxsnippets(snippets) -- import check_cxsnippets() self._check_cxsnippets = self._check_cxsnippets or sandbox_module.import("lib.detect.check_cxsnippets", {anonymous = true}) -- check for c and c++ local passed = 0 local result_output for _, kind in ipairs({"c", "cxx"}) do -- get conditions local links = self:get("links") local snippets = self:get(kind .. "snippets") local types = self:get(kind .. "types") local funcs = self:get(kind .. "funcs") local includes = self:get(kind .. "includes") -- TODO it is deprecated local snippet = self:get(kind .. "snippet") if snippet then snippets = table.join(snippets or {}, snippet) end -- need check it? if snippets or types or funcs or links or includes then -- init source kind local sourcekind = kind if kind == "c" then sourcekind = "cc" end -- split snippets local snippets_build = {} local snippets_tryrun = {} local snippets_output = {} local snippets_binary_match = {} local snippet_binary_match = nil if snippets then for name, snippet in pairs(snippets) do if self:extraconf(kind .. "snippets", name, "output") then snippets_output[name] = snippet elseif self:extraconf(kind .. "snippets", name, "tryrun") then snippets_tryrun[name] = snippet elseif self:extraconf(kind .. "snippets", name, "binary_match") then snippets_binary_match[name] = snippet snippet_binary_match = self:extraconf(kind .. "snippets", name, "binary_match") else snippets_build[name] = snippet end end if #table.keys(snippets_output) > 1 then return false, -1, string.format("option(%s): only support for only one snippet with output!", self:name()) end end -- check snippets (run with output) if #table.keys(snippets_output) > 0 then local ok, results_or_errors, output = sandbox.load(self._check_cxsnippets, snippets_output, { target = self, sourcekind = sourcekind, types = types, funcs = funcs, includes = includes, tryrun = true, output = true}) if not ok then return false, -1, results_or_errors end -- passed or no passed? if results_or_errors then passed = 1 result_output = output else passed = -1 break end end -- check snippets (run only) if passed == 0 and #table.keys(snippets_tryrun) > 0 then local ok, results_or_errors = sandbox.load(self._check_cxsnippets, snippets_tryrun, { target = self, sourcekind = sourcekind, types = types, funcs = funcs, includes = includes, tryrun = true}) if not ok then return false, -1, results_or_errors end -- passed or no passed? if results_or_errors then passed = 1 else passed = -1 break end end -- check snippets (run with binary_match) if #table.keys(snippets_binary_match) > 0 then local ok, results_or_errors, output = sandbox.load(self._check_cxsnippets, snippets_binary_match, { target = self, sourcekind = sourcekind, types = types, funcs = funcs, includes = includes, binary_match = snippet_binary_match}) if not ok then return false, -1, results_or_errors end -- passed or no passed? if results_or_errors then passed = 1 result_output = output else passed = -1 break end end -- check snippets (build only) if passed == 0 or #table.keys(snippets_build) > 0 then local ok, results_or_errors = sandbox.load(self._check_cxsnippets, snippets_build, { target = self, sourcekind = sourcekind, types = types, funcs = funcs, includes = includes}) if not ok then return false, -1, results_or_errors end -- passed or no passed? if results_or_errors then passed = 1 else passed = -1 break end end end end return true, passed, result_output end -- check features function _instance:_do_check_features() local passed = 0 local features = self:get("features") if features then -- import core.tool.compiler self._core_tool_compiler = self._core_tool_compiler or sandbox_module.import("core.tool.compiler", {anonymous = true}) -- all features are supported? features = table.wrap(features) if self._core_tool_compiler.has_features(features, {target = self}) then passed = 1 end -- trace if baseoption.get("verbose") or baseoption.get("diagnosis") then for _, feature in ipairs(features) do utils.cprint("${dim}checking for feature(%s) ... %s", feature, passed > 0 and "${color.success}${text.success}" or "${color.nothing}${text.nothing}") end end end return true, passed end -- check option conditions function _instance:_do_check() -- check snippets local ok, passed, errors = self:_do_check_cxsnippets() if not ok then return false, errors end -- get snippet output local output if passed then output = errors end -- check features if passed == 0 then ok, passed, errors = self:_do_check_features() if not ok then return false, errors end end -- enable this option if be passed if passed > 0 then self:enable(true) if output then self:set_value(output) end end return true end -- on check function _instance:_on_check() -- get check script local check = self:script("check") if check then return sandbox.load(check, self) else return self:_do_check() end end -- check option function _instance:_check() -- disable this option first self:enable(false) -- check it local ok, errors = self:_on_check() -- get name local name = self:name() if name:startswith("__") then name = name:sub(3) end -- trace local result if self:enabled() then local value = self:value() result = "${color.success}" .. (type(value) == "boolean" and "${text.success}" or tostring(value)) else result = "${color.nothing}${text.nothing}" end utils.cprint("checking for %s ... %s", name, result) if not ok then os.raise(errors) end -- flush io buffer to update progress info io.flush() end -- invalidate the previous cache key function _instance:_invalidate() self._CACHEID = self._CACHEID + 1 end -- attempt to check option function _instance:check() -- the option name local name = self:name() -- get default value, TODO: enable will be deprecated local default = self:get("default") if default == nil then default = self:get("enable") end -- before and after check local check_before = self:script("check_before") local check_after = self:script("check_after") if check_before then check_before(self) end -- need check? (only force to check the automatical option without the default value) if config.get(name) == nil or default == nil then -- use it directly if the default value exists if default ~= nil then self:set_value(default) -- check option as boolean switch automatically if the default value not exists elseif default == nil then self:_check() -- disable this option in other case else self:enable(false) end -- need not check? only save this option to configuration directly elseif config.get(name) then self:_save() end -- after check if check_after then check_after(self) end end -- get the option value function _instance:value() return config.get(self:name()) end -- set the option value function _instance:set_value(value) config.set(self:name(), value) self:_save() end -- clear the option status and need recheck it function _instance:clear() config.set(self:name(), nil) self:_clear() end -- this option is enabled? function _instance:enabled() return config.get(self:name()) end -- enable or disable this option -- -- @param enabled enable option? -- @param opt the argument options, e.g. {readonly = true, force = false} -- function _instance:enable(enabled, opt) -- init options opt = opt or {} -- enable or disable this option? if not config.readonly(self:name()) or opt.force then config.set(self:name(), enabled, opt) end -- save or clear this option in cache if self:enabled() then self:_save() else self:_clear() end end -- get the option info function _instance:info() return self._INFO:info() end -- get the type: option function _instance:type() return "option" end -- get the option info function _instance:get(name) return self._INFO:get(name) end -- set the value to the option info function _instance:set(name, ...) self._INFO:apival_set(name, ...) self:_invalidate() end -- add the value to the option info function _instance:add(name, ...) self._INFO:apival_add(name, ...) self:_invalidate() end -- remove the value to the option info (deprecated) function _instance:del(name, ...) self._INFO:apival_del(name, ...) self:_invalidate() end -- remove the value to the option info function _instance:remove(name, ...) self._INFO:apival_remove(name, ...) self:_invalidate() end -- get the extra configuration function _instance:extraconf(name, item, key) return self._INFO:extraconf(name, item, key) end -- get configuration source information of the given api item function _instance:sourceinfo(name, item) return self._INFO:sourceinfo(name, item) end -- get the given dependent option function _instance:dep(name) local deps = self:deps() if deps then return deps[name] end end -- get option deps function _instance:deps() return self._DEPS end -- get option order deps function _instance:orderdeps() return self._ORDERDEPS end -- get the option name function _instance:name() return self._NAME end -- get the option description function _instance:description() return self:get("description") or ("The " .. self:name() .. " option") end -- get the cache key function _instance:cachekey() return string.format("%s_%d", tostring(self), self._CACHEID) end -- get xxx_script function _instance:script(name) -- imports some modules first local script = self:get(name) if script then local scope = getfenv(script) if scope then for _, modulename in ipairs(table.wrap(self:get("imports"))) do scope[sandbox_module.name(modulename)] = sandbox_module.import(modulename, {anonymous = true}) end end end return script end -- show menu? function _instance:showmenu() local showmenu = self:get("showmenu") if showmenu == nil then -- auto check mode? we hidden menu by default if self:get("ctypes") or self:get("cxxtypes") or self:get("cfuncs") or self:get("cxxfuncs") or self:get("cincludes") or self:get("cxxincludes") or self:get("links") or self:get("syslinks") or self:get("csnippets") or self:get("cxxsnippets") or self:get("features") then showmenu = false end end return showmenu end -- get cache function option._cache() return localcache.cache("option") end -- get option apis function option.apis() return { values = { -- option.set_xxx "option.set_values" , "option.set_default" , "option.set_showmenu" , "option.set_category" , "option.set_warnings" , "option.set_optimize" , "option.set_languages" , "option.set_description" -- option.add_xxx , "option.add_deps" , "option.add_imports" , "option.add_vectorexts" , "option.add_features" } , keyvalues = { -- option.set_xxx "option.set_configvar" } , script = { -- option.before_xxx "option.before_check" -- option.on_xxx , "option.on_check" -- option.after_xxx , "option.after_check" } } end -- get interpreter function option.interpreter() -- the interpreter has been initialized? return it directly if option._INTERPRETER then return option._INTERPRETER end -- init interpreter local interp = interpreter.new() -- define apis for option interp:api_define(option.apis()) -- define apis for language interp:api_define(language.apis()) -- we need to be able to precisely control the direction of deduplication of different types of values. -- the default is to de-duplicate from left to right, but like links/syslinks need to be de-duplicated from right to left. -- -- @see https://github.com/xmake-io/xmake/issues/1903 -- interp:deduplication_policy_set("links", "toleft") interp:deduplication_policy_set("syslinks", "toleft") interp:deduplication_policy_set("frameworks", "toleft") -- register filter handler interp:filter():register("option", function (variable) -- init maps local maps = { arch = function() return config.get("arch") or os.arch() end , plat = function() return config.get("plat") or os.host() end , mode = function() return config.get("mode") or "release" end , host = os.host() , subhost = os.subhost() , scriptdir = function () return interp:pending() and interp:scriptdir() or sandbox_os.scriptdir() end , globaldir = global.directory() , configdir = config.directory() , projectdir = os.projectdir() , programdir = os.programdir() } -- map it local result = maps[variable] if type(result) == "function" then result = result() end return result end) -- save interpreter option._INTERPRETER = interp -- ok? return interp end -- new an option instance function option.new(name, info) return _instance.new(name, info) end -- load the option info from the cache function option.load(name) -- check assert(name) -- get info local info = option._cache():get(name) if info == nil then return end return option.new(name, scopeinfo.new("option", info)) end -- save all options to the cache file function option.save() option._cache():save() end -- return module return option