aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c>2009-07-01 14:08:58 +0000
committerhisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c>2009-07-01 14:08:58 +0000
commit8a67d9d90ea580bb984bb85511e3adc6ac1d5d4c (patch)
tree36279fa12978bd1e48b39c94e204f8a91b533e77 /src
parentce672efef7e64b31d53dc1539470932bfd094ee6 (diff)
downloadluarocks-8a67d9d90ea580bb984bb85511e3adc6ac1d5d4c.tar.gz
luarocks-8a67d9d90ea580bb984bb85511e3adc6ac1d5d4c.tar.bz2
luarocks-8a67d9d90ea580bb984bb85511e3adc6ac1d5d4c.zip
Display warnings for undefined variables,
and missing necessary variables in make-type builds. Feature suggestions by Steve Donovan. git-svn-id: http://luarocks.org/svn/luarocks/trunk@34 9ca3f7c1-7366-0410-b1a3-b5c78f85698c
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/build/make.lua2
-rw-r--r--src/luarocks/util.lua59
2 files changed, 60 insertions, 1 deletions
diff --git a/src/luarocks/build/make.lua b/src/luarocks/build/make.lua
index b3e553a9..37486e5d 100644
--- a/src/luarocks/build/make.lua
+++ b/src/luarocks/build/make.lua
@@ -58,6 +58,8 @@ function run(rockspec)
58 end 58 end
59 end 59 end
60 60
61 util.warn_if_not_used(build.build_variables, { CFLAGS=true }, "variable %s was not passed in build_variables")
62
61 util.variable_substitutions(build.build_variables, rockspec.variables) 63 util.variable_substitutions(build.build_variables, rockspec.variables)
62 util.variable_substitutions(build.install_variables, rockspec.variables) 64 util.variable_substitutions(build.install_variables, rockspec.variables)
63 65
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua
index 50efaa9d..5686d0cf 100644
--- a/src/luarocks/util.lua
+++ b/src/luarocks/util.lua
@@ -122,6 +122,62 @@ function platform_overrides(tbl)
122 tbl.platforms = nil 122 tbl.platforms = nil
123end 123end
124 124
125local var_format_pattern = "%$%((%a[%a%d_]+)%)"
126
127--- Display a warning message.
128-- @param msg string: the warning message
129function warning(msg)
130 print()
131 print("Warning: "..msg)
132 print()
133end
134
135--- Create a new shallow copy of a table: a new table with
136-- the same keys and values. Keys point to the same objects as
137-- the original table (ie, does not copy recursively).
138-- @param tbl table: the input table
139-- @return table: a new table with the same contents.
140local function make_shallow_copy(tbl)
141 local copy = {}
142 for k,v in pairs(tbl) do
143 copy[k] = v
144 end
145 return copy
146end
147
148-- Check if a set of needed variables are referenced
149-- somewher in a list of definitions, warning teh user
150-- about any unused ones. Each key in needed_set should
151-- appear as a $(XYZ) variable at least once as a
152-- substring of some value of var_defs.
153-- @param var_defs: a table with string keys and string
154-- values, containing variable definitions.
155-- @param needed_set: a set where keys are the names of
156-- needed variables.
157-- @param msg string: the warning message to display.
158function warn_if_not_used(var_defs, needed_set, msg)
159 needed_set = make_shallow_copy(needed_set)
160 for var,val in pairs(var_defs) do
161 for used in val:gmatch(var_format_pattern) do
162 needed_set[used] = nil
163 end
164 end
165 for var,_ in pairs(needed_set) do
166 warning(msg:format(var))
167 end
168end
169
170-- Output any entries that might remain in $(XYZ) format,
171-- warning the user that substitutions have failed.
172-- @param line string: the input string
173local function warn_failed_matches(line)
174 if line:match(var_format_pattern) then
175 for unmatched in line:gmatch(var_format_pattern) do
176 warning("unmatched variable " .. unmatched)
177 end
178 end
179end
180
125--- Perform make-style variable substitutions on string values of a table. 181--- Perform make-style variable substitutions on string values of a table.
126-- For every string value tbl.x which contains a substring of the format 182-- For every string value tbl.x which contains a substring of the format
127-- "$(XYZ)" will have this substring replaced by vars["XYZ"], if that field 183-- "$(XYZ)" will have this substring replaced by vars["XYZ"], if that field
@@ -137,7 +193,8 @@ function variable_substitutions(tbl, vars)
137 local updated = {} 193 local updated = {}
138 for k, v in pairs(tbl) do 194 for k, v in pairs(tbl) do
139 if type(v) == "string" then 195 if type(v) == "string" then
140 updated[k] = v:gsub("%$%((%a[%a%d_]+)%)", vars) 196 updated[k] = v:gsub(var_format_pattern, vars)
197 warn_failed_matches(updated[k])
141 end 198 end
142 end 199 end
143 for k, v in pairs(updated) do 200 for k, v in pairs(updated) do