Skip to content

Commit

Permalink
Add better detection of issues
Browse files Browse the repository at this point in the history
  • Loading branch information
SquidDev committed Feb 26, 2016
1 parent 73689f7 commit 31522bc
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 14 deletions.
27 changes: 22 additions & 5 deletions bsrocks/commands/desc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local dependencies = require "bsrocks.rocks.dependencies"
local download = require "bsrocks.downloaders"
local install = require "bsrocks.rocks.install"
local match = require "bsrocks.lib.diffmatchpatch".match_main
local patchspec = require "bsrocks.rocks.patchspec"
local printColoured = require "bsrocks.lib.utils".printColoured
local rockspec = require "bsrocks.rocks.rockspec"
local settings = require "bsrocks.lib.settings"
Expand All @@ -12,10 +13,10 @@ local function execute(name)
if not name then error("Expected <name>", 0) end
name = name:lower()

local installed = install.getInstalled()
local installed, installedPatches = install.getInstalled()

local isInstalled = true
local spec = installed[name]
local spec, patchS = installed[name], installedPatches[name]

if not spec then
isInstalled = false
Expand All @@ -25,6 +26,10 @@ local function execute(name)

local version = rockspec.latestVersion(manifest, name)
spec = rockspec.fetchRockspec(manifest.server, name, version)


local patchManifest = patchspec.findPatchspec(name)
patchS = patchManifest and patchspec.fetchPatchspec(patchManifest.server, name)
end

write(name .. ": " .. spec.version .. " ")
Expand Down Expand Up @@ -56,9 +61,21 @@ local function execute(name)
end
end

if not download(spec.source, nil) then
printColoured("Incompatible: No downloader", colours.red)
printColoured("for " .. spec.source.url, colours.lightGrey)
if not isInstalled then
local error, issues = install.findIssues(spec, patchS)
if #issues > 0 then
printColoured("Issues", colours.orange)
if error then
printColoured("This package is incompatible", colors.red)
end

for _, v in ipairs(issues) do
local color = colors.yellow
if v[2] then color = colors.red end

printColoured(" " .. v[1], color)
end
end
end

if spec.dependencies and #spec.dependencies > 0 then
Expand Down
58 changes: 51 additions & 7 deletions bsrocks/rocks/install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,67 @@ local fetched = false
local installed = {}
local installedPatches = {}

local function save(rockS, patchS)
local function extractFiles(rockS, patchS)
local blacklist = {}
if patchspec and patchspec.remove then
for _, v in ipairs(patchspec.remove) do blacklist[v] = true end
if patchS and patchS.remove then
for _, v in ipairs(patchS.remove) do blacklist[v] = true end
end

local files = rockspec.extractFiles(rockS, blacklist)
return rockspec.extractFiles(rockS, blacklist)
end

local function findIssues(rockS, patchS, files)
files = files or extractFiles(rockS, patchS)

local issues = {}
local error = false

local source = patchspec.extractSource(rockS, patchS)
if not download(source, false) then
issues[#issues + 1] = { "Cannot find downloader for " .. source.url .. ". Please suggest this package to be patched.", true }
error = true
end

for _, file in ipairs(files) do
local ext = file:match("[^/]%.(%w+)$")
if ext and ext ~= "lua" then
warn("File extension is not lua for " .. file .. ". It may not work correctly.")
if ext == "c" or ext == "cpp" or ext == "h" or ext == "hpp" then
issues[#issues + 1] = { file .. " is a C file. This will not work.", true }
error = true
else
issues[#issues + 1] = { "File extension is not lua (for " .. file .. "). It may not work correctly.", false }
end
end
end

return error, issues
end

local function save(rockS, patchS)
local files = extractFiles(rockS, patchS)

local error, issues = findIssues(rockS, patchS, files)
if #issues > 0 then
utils.printColoured("This package is incompatible", colors.red)

for _, v in ipairs(issues) do
local color = colors.yellow
if v[2] then color = colors.red end

utils.printColoured(" " .. v[1], color)
end

if error then
error("This package is incompatible", 0)
end
end
local downloaded = download(patchspec.extractSource(rockS, patchS), files)

local source = patchspec.extractSource(rockS, patchS)
local downloaded = download(source, files)

if not downloaded then
error("Cannot find downloader for " .. rockS.source.url .. ". . Please suggest this package to be patched.", 0)
-- This should never be reached.
error("Cannot find downloader for " .. source.url .. ".", 0)
end

if patchS then
Expand Down Expand Up @@ -189,4 +232,5 @@ return {
getInstalled = getInstalled,
install = install,
remove = remove,
findIssues = findIssues,
}
4 changes: 2 additions & 2 deletions bsrocks/rocks/patchspec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ local function extractFiles(patch)
end

local function extractSource(rockS, patchS)
local source = patchS.source
local version = rockS.version
local source = patchS and patchS.source
if source then
local version = rockS.version
local out = {}
for k, v in pairs(source) do
if type(v) == "string" then v = v:gsub("%%{version}", version) end
Expand Down

0 comments on commit 31522bc

Please sign in to comment.