Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: tools/gcmole/gcmole.lua

Issue 2352103002: [gn] Add gn support to gcmole (Closed)
Patch Set: Added todo Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/BUILD.gn ('k') | tools/gcmole/run-gcmole.isolate » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 -- Copyright 2011 the V8 project authors. All rights reserved. 1 -- Copyright 2011 the V8 project authors. All rights reserved.
2 -- Redistribution and use in source and binary forms, with or without 2 -- Redistribution and use in source and binary forms, with or without
3 -- modification, are permitted provided that the following conditions are 3 -- modification, are permitted provided that the following conditions are
4 -- met: 4 -- met:
5 -- 5 --
6 -- * Redistributions of source code must retain the above copyright 6 -- * Redistributions of source code must retain the above copyright
7 -- notice, this list of conditions and the following disclaimer. 7 -- notice, this list of conditions and the following disclaimer.
8 -- * Redistributions in binary form must reproduce the above 8 -- * Redistributions in binary form must reproduce the above
9 -- copyright notice, this list of conditions and the following 9 -- copyright notice, this list of conditions and the following
10 -- disclaimer in the documentation and/or other materials provided 10 -- disclaimer in the documentation and/or other materials provided
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 local pipe = io.popen(action) 176 local pipe = io.popen(action)
177 local success = SplitResults(pipe:lines(), func) 177 local success = SplitResults(pipe:lines(), func)
178 local closed = pipe:close() 178 local closed = pipe:close()
179 if not (success and closed) then error("Failed to run: " .. action) end 179 if not (success and closed) then error("Failed to run: " .. action) end
180 end 180 end
181 end 181 end
182 182
183 ------------------------------------------------------------------------------- 183 -------------------------------------------------------------------------------
184 -- GYP file parsing 184 -- GYP file parsing
185 185
186 -- TODO(machenbach): Remove this when deprecating gyp.
186 local function ParseGYPFile() 187 local function ParseGYPFile()
187 local result = {} 188 local result = {}
188 local gyp_files = { 189 local gyp_files = {
189 { "src/v8.gyp", "'([^']-%.cc)'", "src/" }, 190 { "src/v8.gyp", "'([^']-%.cc)'", "src/" },
190 { "test/cctest/cctest.gyp", "'(test-[^']-%.cc)'", "test/cctest/" } 191 { "test/cctest/cctest.gyp", "'(test-[^']-%.cc)'", "test/cctest/" }
191 } 192 }
192 193
193 for i = 1, #gyp_files do 194 for i = 1, #gyp_files do
194 local filename = gyp_files[i][1] 195 local filename = gyp_files[i][1]
195 local pattern = gyp_files[i][2] 196 local pattern = gyp_files[i][2]
196 local prefix = gyp_files[i][3] 197 local prefix = gyp_files[i][3]
197 local gyp_file = assert(io.open(filename), "failed to open GYP file") 198 local gyp_file = assert(io.open(filename), "failed to open GYP file")
198 local gyp = gyp_file:read('*a') 199 local gyp = gyp_file:read('*a')
199 for condition, sources in 200 for condition, sources in
200 gyp:gmatch "%[.-### gcmole%((.-)%) ###(.-)%]" do 201 gyp:gmatch "%[.-### gcmole%((.-)%) ###(.-)%]" do
201 if result[condition] == nil then result[condition] = {} end 202 if result[condition] == nil then result[condition] = {} end
202 for file in sources:gmatch(pattern) do 203 for file in sources:gmatch(pattern) do
203 table.insert(result[condition], prefix .. file) 204 table.insert(result[condition], prefix .. file)
204 end 205 end
205 end 206 end
206 gyp_file:close() 207 gyp_file:close()
207 end 208 end
208 209
209 return result 210 return result
210 end 211 end
211 212
213 local function ParseGNFile()
214 local result = {}
215 local gn_files = {
216 { "BUILD.gn", '"([^"]-%.cc)"', "" },
217 { "test/cctest/BUILD.gn", '"(test-[^"]-%.cc)"', "test/cctest/" }
218 }
219
220 for i = 1, #gn_files do
221 local filename = gn_files[i][1]
222 local pattern = gn_files[i][2]
223 local prefix = gn_files[i][3]
224 local gn_file = assert(io.open(filename), "failed to open GN file")
225 local gn = gn_file:read('*a')
226 for condition, sources in
227 gn:gmatch "### gcmole%((.-)%) ###(.-)%]" do
228 if result[condition] == nil then result[condition] = {} end
229 for file in sources:gmatch(pattern) do
230 table.insert(result[condition], prefix .. file)
231 end
232 end
233 gn_file:close()
234 end
235
236 return result
237 end
238
212 local function EvaluateCondition(cond, props) 239 local function EvaluateCondition(cond, props)
213 if cond == 'all' then return true end 240 if cond == 'all' then return true end
214 241
215 local p, v = cond:match "(%w+):(%w+)" 242 local p, v = cond:match "(%w+):(%w+)"
216 243
217 assert(p and v, "failed to parse condition: " .. cond) 244 assert(p and v, "failed to parse condition: " .. cond)
218 assert(props[p] ~= nil, "undefined configuration property: " .. p) 245 assert(props[p] ~= nil, "undefined configuration property: " .. p)
219 246
220 return props[p] == v 247 return props[p] == v
221 end 248 end
222 249
223 local function BuildFileList(sources, props) 250 local function BuildFileList(sources, props)
224 local list = {} 251 local list = {}
225 for condition, files in pairs(sources) do 252 for condition, files in pairs(sources) do
226 if EvaluateCondition(condition, props) then 253 if EvaluateCondition(condition, props) then
227 for i = 1, #files do table.insert(list, files[i]) end 254 for i = 1, #files do table.insert(list, files[i]) end
228 end 255 end
229 end 256 end
230 return list 257 return list
231 end 258 end
232 259
233 local sources = ParseGYPFile() 260
261 local gyp_sources = ParseGYPFile()
262 local gn_sources = ParseGNFile()
263
264 -- TODO(machenbach): Remove this comparison logic when deprecating gyp.
265 local function CompareSources(sources1, sources2, what)
266 for condition, files1 in pairs(sources1) do
267 local files2 = sources2[condition]
268 assert(
269 files2 ~= nil,
270 "Missing gcmole condition in " .. what .. ": " .. condition)
271
272 -- Turn into set for speed.
273 files2_set = {}
274 for i, file in pairs(files2) do files2_set[file] = true end
275
276 for i, file in pairs(files1) do
277 assert(
278 files2_set[file] ~= nil,
279 "Missing file " .. file .. " in " .. what .. " for condition " ..
280 condition)
281 end
282 end
283 end
284
285 CompareSources(gyp_sources, gn_sources, "GN")
286 CompareSources(gn_sources, gyp_sources, "GYP")
287
234 288
235 local function FilesForArch(arch) 289 local function FilesForArch(arch)
236 return BuildFileList(sources, { os = 'linux', 290 return BuildFileList(gn_sources, { os = 'linux',
237 arch = arch, 291 arch = arch,
238 mode = 'debug', 292 mode = 'debug',
239 simulator = ''}) 293 simulator = ''})
240 end 294 end
241 295
242 local mtConfig = {} 296 local mtConfig = {}
243 297
244 mtConfig.__index = mtConfig 298 mtConfig.__index = mtConfig
245 299
246 local function config (t) return setmetatable(t, mtConfig) end 300 local function config (t) return setmetatable(t, mtConfig) end
247 301
248 function mtConfig:extend(t) 302 function mtConfig:extend(t)
249 local e = {} 303 local e = {}
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 497
444 for _, arch in ipairs(ARCHS) do 498 for _, arch in ipairs(ARCHS) do
445 if not ARCHITECTURES[arch] then 499 if not ARCHITECTURES[arch] then
446 error ("Unknown arch: " .. arch) 500 error ("Unknown arch: " .. arch)
447 end 501 end
448 502
449 errors = SafeCheckCorrectnessForArch(arch, report) or errors 503 errors = SafeCheckCorrectnessForArch(arch, report) or errors
450 end 504 end
451 505
452 os.exit(errors and 1 or 0) 506 os.exit(errors and 1 or 0)
OLDNEW
« no previous file with comments | « test/cctest/BUILD.gn ('k') | tools/gcmole/run-gcmole.isolate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698