diff options
| author | Hisham <hisham@gobolinux.org> | 2016-10-26 15:28:23 -0200 |
|---|---|---|
| committer | Hisham <hisham@gobolinux.org> | 2016-10-26 15:28:23 -0200 |
| commit | f7ae6213f430798ec86883f9ab9917b156e1758d (patch) | |
| tree | 391d190ed49f72bd70eadc2b1d1716fcbff676d4 /src | |
| parent | 86e1bef85084b5bf09688bd19077a8eaa82ae15c (diff) | |
| download | luarocks-f7ae6213f430798ec86883f9ab9917b156e1758d.tar.gz luarocks-f7ae6213f430798ec86883f9ab9917b156e1758d.tar.bz2 luarocks-f7ae6213f430798ec86883f9ab9917b156e1758d.zip | |
Support user-defined platforms array.
Let the user set their own custom platform entries,
but also provide fallbacks to make sure things work.
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/cfg.lua | 87 |
1 files changed, 57 insertions, 30 deletions
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 9200dd26..1141acf6 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua | |||
| @@ -131,24 +131,27 @@ else | |||
| 131 | -- Fall back to Unix in unknown systems. | 131 | -- Fall back to Unix in unknown systems. |
| 132 | end | 132 | end |
| 133 | 133 | ||
| 134 | -- Set order for platform overrides | 134 | -- Set order for platform overrides. |
| 135 | -- More general platform identifiers should be listed first, | ||
| 136 | -- more specific ones later. | ||
| 135 | local platform_order = { | 137 | local platform_order = { |
| 136 | -- Unixes | 138 | -- Unixes |
| 137 | unix = 1, | 139 | "unix", |
| 138 | bsd = 2, | 140 | "bsd", |
| 139 | solaris = 3, | 141 | "solaris", |
| 140 | netbsd = 4, | 142 | "netbsd", |
| 141 | openbsd = 5, | 143 | "openbsd", |
| 142 | freebsd = 6, | 144 | "freebsd", |
| 143 | linux = 7, | 145 | "linux", |
| 144 | macosx = 8, | 146 | "macosx", |
| 145 | cygwin = 9, | 147 | "cygwin", |
| 146 | msys = 10, | 148 | "msys", |
| 147 | haiku = 11, | 149 | "haiku", |
| 148 | -- Windows | 150 | -- Windows |
| 149 | win32 = 12, | 151 | "win32", |
| 150 | mingw32 = 13, | 152 | "mingw32", |
| 151 | windows = 14 } | 153 | "windows", |
| 154 | } | ||
| 152 | 155 | ||
| 153 | -- Path configuration: | 156 | -- Path configuration: |
| 154 | local sys_config_file, home_config_file | 157 | local sys_config_file, home_config_file |
| @@ -274,26 +277,50 @@ if not next(cfg.rocks_trees) then | |||
| 274 | end | 277 | end |
| 275 | end | 278 | end |
| 276 | 279 | ||
| 277 | |||
| 278 | -- update platforms list; keyed -> array | 280 | -- update platforms list; keyed -> array |
| 279 | do | 281 | do |
| 280 | local lst = {} -- use temp array to not confuse `pairs` in loop | 282 | -- if explicitly given by user, |
| 281 | for plat in pairs(cfg.platforms) do | 283 | if cfg.platforms[1] then |
| 282 | if cfg.platforms[plat] then -- entries set to 'false' skipped | 284 | local is_windows = cfg.platforms.windows |
| 283 | if not platform_order[plat] then | 285 | -- Clear auto-detected values |
| 284 | local pl = "" | 286 | for k, _ in pairs(cfg.platforms) do |
| 285 | for k,_ in pairs(platform_order) do pl = pl .. ", " .. k end | 287 | if type(k) == "string" then |
| 286 | io.stderr:write("Bad platform given; "..tostring(plat)..". Valid entries are: "..pl:sub(3,-1) ..".\n") | 288 | cfg.platforms[k] = nil |
| 287 | os.exit(cfg.errorcodes.CONFIGFILE) | 289 | end |
| 290 | end | ||
| 291 | -- and set the ones given by the user. | ||
| 292 | for _, plat in ipairs(cfg.platforms) do | ||
| 293 | cfg.platforms[plat] = true | ||
| 294 | end | ||
| 295 | -- If no major platform family was set by the user, | ||
| 296 | if not (cfg.platforms.unix or cfg.platforms.windows) then | ||
| 297 | -- set some fallback defaults in case the user provides an incomplete configuration. | ||
| 298 | -- LuaRocks expects a set of defaults to be available. | ||
| 299 | -- This is used for setting defaults here only; the platform overrides | ||
| 300 | -- will use only the user's list. | ||
| 301 | if is_windows then | ||
| 302 | cfg.platforms.windows = true | ||
| 303 | table.insert(cfg.platforms, "windows") | ||
| 304 | else | ||
| 305 | cfg.platforms.unix = true | ||
| 306 | table.insert(cfg.platforms, "unix") | ||
| 307 | end | ||
| 308 | end | ||
| 309 | else | ||
| 310 | -- Sort detected platform defaults | ||
| 311 | local order = {} | ||
| 312 | for i, v in ipairs(platform_order) do | ||
| 313 | order[v] = i | ||
| 314 | end | ||
| 315 | local entries = {} | ||
| 316 | for k, v in pairs(cfg.platforms) do | ||
| 317 | if type(k) == "string" and v == true then | ||
| 318 | table.insert(entries, k) | ||
| 288 | end | 319 | end |
| 289 | table.insert(lst, plat) | ||
| 290 | else | ||
| 291 | cfg.platforms[plat] = nil | ||
| 292 | end | 320 | end |
| 321 | table.sort(entries, function(a, b) return order[a] < order[b] end) | ||
| 322 | util.deep_merge(cfg.platforms, entries) | ||
| 293 | end | 323 | end |
| 294 | -- platform overrides depent on the order, so set priorities | ||
| 295 | table.sort(lst, function(key1, key2) return platform_order[key1] < platform_order[key2] end) | ||
| 296 | util.deep_merge(cfg.platforms, lst) | ||
| 297 | end | 324 | end |
| 298 | 325 | ||
| 299 | -- Configure defaults: | 326 | -- Configure defaults: |
