-
Notifications
You must be signed in to change notification settings - Fork 590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid cyclic dependencies between modules #1400
Comments
nevermind, it can't happen on master. /me have too many patches |
Should we define some hard rules on what might depend on what to make sure we have no cyclic dependencies? For example, I would propose that gears must not use beautiful... |
Sure. It will however require some changes as gears depends on awful.util. gears: depends on nothing
|
why not to move |
I don't think we should start monkey-patching standard Lua things. We already do that too much. That leads to too much confusion. Also 'util' is too much of a generic name that eventually some name collision will occur. |
(My plan is to implement a tool that tries to automatically check the above rules and complains if they are not followed.) |
Following program run in the awesome source directory: local depgraph = require("depgraph")
local allowed_deps = {
gears = {
lgi = true,
},
beautiful = {
gears = true,
lgi = true,
},
wibox = {
beautiful = true,
gears = true,
lgi = true,
},
awful = {
beautiful = true,
gears = true,
lgi = true,
wibox = true,
},
naughty = {
awful = true,
beautiful = true,
gears = true,
lgi = true,
wibox = true,
},
menubar = {
awful = true,
beautiful = true,
gears = true,
lgi = true,
wibox = true,
}
}
local graph = assert(depgraph.make_graph({"lib"}, {}, "lib", nil, nil))
for _, module in ipairs(graph.modules) do
local base_name = string.match(module.name, "%a*")
local allowed = allowed_deps[base_name] or {}
for _, dep in ipairs(module.deps) do
local dep_base_name = string.match(dep.name, "%a*")
if base_name ~= dep_base_name and not allowed[dep_base_name] then
print(string.format("Unallowed dependency by %s to %s (%s -> %s)",
module.name, dep.name, base_name, dep_base_name))
end
end
end produces the following output:
So... how do we get from here to a situation that does not violate the proposed rules? |
Also: We might want to run |
Currently, "everything can require everything". It's an unstructured mess which sometimes causes problems. This commit adds a tool that enforces a white-list of require() uses. It uses depgraph to scan the source code and then each use of require() that is found is checked. If any violations are found, the tool returns a failure. This tool is wired up to a new target "make check-requires" which is included in "make check". Thus, Travis will run this. Reference: awesomeWM#1400 Signed-off-by: Uli Schlachter <psychon@znc.in>
gears.color->beautiful.init->beautiful.theme_assets->gears.color = BOOM
How this got past the CI...
Simplest solution, don't require theme_assets in beautiful.init
The text was updated successfully, but these errors were encountered: