From e95bfca9f1f1e417a2f554cb756cd44a7eb105cb Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sun, 29 Nov 2015 12:51:28 -0200 Subject: Add explicit macosx_deployment_target option for Mac users. --- src/luarocks/build.lua | 30 ++++++++++++++++++++++++++++++ src/luarocks/cfg.lua | 6 +++--- src/luarocks/util.lua | 14 ++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 68f20264..dd0b4441 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -149,6 +149,31 @@ local function install_default_docs(name, version) end end +local function check_macosx_deployment_target(rockspec) + local target = rockspec.build.macosx_deployment_target + local function minor(version) + return tonumber(version and version:match("^[^.]+%.([^.]+)")) + end + local function patch_variable(var, target) + if rockspec.variables[var]:match("MACOSX_DEPLOYMENT_TARGET") then + rockspec.variables[var] = (rockspec.variables[var]):gsub("MACOSX_DEPLOYMENT_TARGET=[^ ]*", "MACOSX_DEPLOYMENT_TARGET="..target) + else + rockspec.variables[var] = "env MACOSX_DEPLOYMENT_TARGET="..target.." "..rockspec.variables[var] + end + end + if cfg.platforms.macosx and deps.format_is_at_least(rockspec, "3.0") and target then + local version = util.popen_read("sw_vers -productVersion") + local versionminor = minor(version) + local targetminor = minor(target) + if targetminor > versionminor then + return nil, ("This rock requires Mac OSX 10.%d, and you are running 10.%d."):format(targetminor, versionminor) + end + patch_variable("CC", target) + patch_variable("LD", target) + end + return true +end + --- Build and install a rock given a rockspec. -- @param rockspec_file string: local or remote filename of a rockspec. -- @param need_to_fetch boolean: true if sources need to be fetched, @@ -244,6 +269,11 @@ function build.build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_m end end + ok, err = check_macosx_deployment_target(rockspec) + if not ok then + return nil, err + end + if build_spec.type ~= "none" then -- Temporary compatibility diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 4fb1b23b..6706468c 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -76,8 +76,8 @@ end -- so that this detection does not run every time. When it is -- performed, we use the Unix way to identify the system, -- even on Windows (assuming UnxUtils or Cygwin). -local system = site_config.LUAROCKS_UNAME_S or io.popen("uname -s"):read("*l") -local proc = site_config.LUAROCKS_UNAME_M or io.popen("uname -m"):read("*l") +local system = site_config.LUAROCKS_UNAME_S or util.popen_read("uname -s") +local proc = site_config.LUAROCKS_UNAME_M or util.popen_read("uname -m") if proc:match("i[%d]86") then cfg.target_cpu = "x86" elseif proc:match("amd64") or proc:match("x86_64") then @@ -531,7 +531,7 @@ if cfg.platforms.macosx then defaults.variables.LIBFLAG = "-bundle -undefined dynamic_lookup -all_load" defaults.variables.STAT = "/usr/bin/stat" defaults.variables.STATFLAG = "-f '%A'" - local version = io.popen("sw_vers -productVersion"):read("*l") + local version = util.popen_read("sw_vers -productVersion") version = tonumber(version and version:match("^[^.]+%.([^.]+)")) or 3 if version >= 10 then version = 8 diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index c06c8354..8c4bd974 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -9,6 +9,20 @@ local util = {} local unpack = unpack or table.unpack +--- Run a process and read a its output. +-- Equivalent to io.popen(cmd):read("*l"), except that it +-- closes the fd right away. +-- @param cmd string: The command to execute +-- @param spec string: "*l" by default, to read a single line. +-- May be used to read more, passing, for instance, "*a". +-- @return string: the output of the program. +function popen_read(cmd, spec) + local fd = io.open(cmd) + local out = fd:read(spec or "*l") + fd:close() + return out +end + local scheduled_functions = {} local debug = require("debug") -- cgit v1.2.3-55-g6feb