From f6974b40735b9300f7b529da6e602459d0db9c49 Mon Sep 17 00:00:00 2001
From: Thijs Schreijer <thijs@thijsschreijer.nl>
Date: Thu, 25 Jun 2015 00:14:50 +0200
Subject: config.lua is not being integrated, bug introduced in #385

---
 src/luarocks/cfg.lua | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index 2a92c4dd..03fc2ad2 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -159,6 +159,16 @@ env_for_config_file = {
      print(util.show_table(env_for_config_file, "global environment"))
    end,
 }
+-- Merge values from config files read into the `cfg` table
+local merge_overrides = function(overrides)
+   if overrides.rocks_trees then
+      cfg.rocks_trees = nil
+   end
+   if overrides.rocks_servers then
+      cfg.rocks_servers = nil
+   end
+   util.deep_merge(cfg, overrides)
+end
 
 sys_config_file = site_config.LUAROCKS_SYSCONFIG or sys_config_dir.."/config-"..cfg.lua_version..".lua"
 do
@@ -172,6 +182,7 @@ do
       io.stderr:write(err.."\n")
       os.exit(cfg.errorcodes.CONFIGFILE)
    end
+   merge_overrides(sys_config_ok)
 end
 
 if not site_config.LUAROCKS_FORCE_CONFIG then
@@ -190,13 +201,7 @@ if not site_config.LUAROCKS_FORCE_CONFIG then
    end
    if home_overrides then
       home_config_ok = true
-      if home_overrides.rocks_trees then
-         cfg.rocks_trees = nil
-      end
-      if home_overrides.rocks_servers then
-         cfg.rocks_servers = nil
-      end
-      util.deep_merge(cfg, home_overrides)
+      merge_overrides(home_overrides)
    else
       home_config_ok = home_overrides
       if errcode ~= "open" then
@@ -220,6 +225,7 @@ end
 local defaults = {
 
    local_by_default = false,
+   use_extensions = false,
    accept_unknown_fields = false,
    fs_use_modules = true,
    hooks_enabled = true,
-- 
cgit v1.2.3-55-g6feb


From e87c898a19b54de52e959014377f7658b363b7be Mon Sep 17 00:00:00 2001
From: Thijs Schreijer <thijs@thijsschreijer.nl>
Date: Thu, 25 Jun 2015 00:23:15 +0200
Subject: removed accidental reintroduced line

---
 src/luarocks/cfg.lua | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index 03fc2ad2..6a49c842 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -225,7 +225,6 @@ end
 local defaults = {
 
    local_by_default = false,
-   use_extensions = false,
    accept_unknown_fields = false,
    fs_use_modules = true,
    hooks_enabled = true,
-- 
cgit v1.2.3-55-g6feb


From 1a85cb5c7d23e041d2787e097fecbd4524a86792 Mon Sep 17 00:00:00 2001
From: Thijs Schreijer <thijs@thijsschreijer.nl>
Date: Thu, 25 Jun 2015 00:29:28 +0200
Subject: fix travis-ci error

---
 src/luarocks/cfg.lua | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index 6a49c842..2d3bb8bd 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -182,7 +182,9 @@ do
       io.stderr:write(err.."\n")
       os.exit(cfg.errorcodes.CONFIGFILE)
    end
-   merge_overrides(sys_config_ok)
+   if sys_config_ok then 
+      merge_overrides(sys_config_ok)
+   end
 end
 
 if not site_config.LUAROCKS_FORCE_CONFIG then
-- 
cgit v1.2.3-55-g6feb


From 3b58640f79c114e651e53858afee94bd7e7eb52d Mon Sep 17 00:00:00 2001
From: Thijs Schreijer <thijs@thijsschreijer.nl>
Date: Thu, 25 Jun 2015 12:14:04 +0200
Subject: do not reuse environments

---
 src/luarocks/cfg.lua | 57 ++++++++++++++++++++++++++++------------------------
 1 file changed, 31 insertions(+), 26 deletions(-)

diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index 2d3bb8bd..8321e9b9 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -144,39 +144,44 @@ end
 cfg.variables = {}
 cfg.rocks_trees = {}
 
--- The global environment in the config files;
-local env_for_config_file
-env_for_config_file = {
-   home = cfg.home,
-   lua_version = cfg.lua_version,
-   platform = util.make_shallow_copy(detected),
-   processor = cfg.target_cpu,   -- remains for compat reasons
-   target_cpu = cfg.target_cpu,  -- replaces `processor`
-   os_getenv = os.getenv, 
-   dump_env = function()
-     -- debug function, calling it from a config file will show all 
-     -- available globals to that config file
-     print(util.show_table(env_for_config_file, "global environment"))
-   end,
-}
+-- Create global environment for the config files;
+local env_for_config_file = function() 
+   local e 
+   e = {
+      home = cfg.home,
+      lua_version = cfg.lua_version,
+      platform = util.make_shallow_copy(detected),
+      processor = cfg.target_cpu,   -- remains for compat reasons
+      target_cpu = cfg.target_cpu,  -- replaces `processor`
+      os_getenv = os.getenv, 
+      dump_env = function()
+         -- debug function, calling it from a config file will show all 
+         -- available globals to that config file
+         print(util.show_table(e, "global environment"))
+      end,
+   }
+   return e
+end
+
 -- Merge values from config files read into the `cfg` table
 local merge_overrides = function(overrides)
-   if overrides.rocks_trees then
-      cfg.rocks_trees = nil
-   end
-   if overrides.rocks_servers then
-      cfg.rocks_servers = nil
-   end
+   -- remove some stuff we do not want to integrate
+   overrides.os_getenv = nil
+   overrides.dump_env = nil
+   -- remove tables to be copied verbatim instead of deeply merged
+   if overrides.rocks_trees   then cfg.rocks_trees   = nil end
+   if overrides.rocks_servers then cfg.rocks_servers = nil end
+   -- perform actual merge
    util.deep_merge(cfg, overrides)
 end
 
 sys_config_file = site_config.LUAROCKS_SYSCONFIG or sys_config_dir.."/config-"..cfg.lua_version..".lua"
 do
    local err, errcode
-   sys_config_ok, err, errcode = persist.load_into_table(sys_config_file, env_for_config_file)
+   sys_config_ok, err, errcode = persist.load_into_table(sys_config_file, env_for_config_file())
    if (not sys_config_ok) and errcode == "open" then -- file not found, so try alternate file
       sys_config_file = sys_config_dir.."/config.lua"
-      sys_config_ok, err, errcode = persist.load_into_table(sys_config_file, env_for_config_file)
+      sys_config_ok, err, errcode = persist.load_into_table(sys_config_file, env_for_config_file())
    end
    if (not sys_config_ok) and errcode ~= "open" then -- either "load" or "run"; bad config file, bail out with error
       io.stderr:write(err.."\n")
@@ -192,13 +197,13 @@ if not site_config.LUAROCKS_FORCE_CONFIG then
    local home_overrides, err, errcode
    home_config_file = os.getenv("LUAROCKS_CONFIG_" .. version_suffix) or os.getenv("LUAROCKS_CONFIG")
    if home_config_file then
-      home_overrides, err, errcode = persist.load_into_table(home_config_file, env_for_config_file)
+      home_overrides, err, errcode = persist.load_into_table(home_config_file, env_for_config_file())
    else
       home_config_file = home_config_dir.."/config-"..cfg.lua_version..".lua"
-      home_overrides, err, errcode = persist.load_into_table(home_config_file, env_for_config_file)
+      home_overrides, err, errcode = persist.load_into_table(home_config_file, env_for_config_file())
       if (not home_overrides) and (not errcode == "run") then
          home_config_file = home_config_dir.."/config.lua"
-         home_overrides, err, errcode = persist.load_into_table(home_config_file, env_for_config_file)
+         home_overrides, err, errcode = persist.load_into_table(home_config_file, env_for_config_file())
       end
    end
    if home_overrides then
-- 
cgit v1.2.3-55-g6feb


From f61e5a22d7d76561cfb10a8d83e14e324d2a772a Mon Sep 17 00:00:00 2001
From: Ignacio Burgueño <ignaciob@inconcertcc.com>
Date: Mon, 8 Jun 2015 12:19:11 -0300
Subject: cmake backend: Generate 64 bits build when appropiate

Adds -DCMAKE_GENERATOR_PLATFORM=x64 when needed. It seems that
CMake does not do that by default (although I might be wrong on that).

fixes #382
---
 src/luarocks/build/cmake.lua | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/luarocks/build/cmake.lua b/src/luarocks/build/cmake.lua
index c8f5a669..a1c08dfa 100644
--- a/src/luarocks/build/cmake.lua
+++ b/src/luarocks/build/cmake.lua
@@ -35,7 +35,6 @@ function cmake.run(rockspec)
       cmake_handler:close()
    end
 
-
    -- Execute cmake with variables.
    local args = ""
    if cfg.cmake_generator then
@@ -45,6 +44,11 @@ function cmake.run(rockspec)
       args = args .. ' -D' ..k.. '="' ..v.. '"'
    end
 
+   -- Generate 64 bit build if appropiate.
+   if not not cfg.arch:match("%-x86_64$") then
+      args = args .. " -DCMAKE_GENERATOR_PLATFORM=x64"
+   end
+
    if not fs.execute_string(rockspec.variables.CMAKE.." -H. -Bbuild.luarocks "..args) then
       return nil, "Failed cmake."
    end
-- 
cgit v1.2.3-55-g6feb


From b3a4e889dc3f06e83a299096710406920f18cd51 Mon Sep 17 00:00:00 2001
From: Ignacio Burgue o <ignaciob@inconcertcc.com>
Date: Wed, 17 Jun 2015 09:54:07 -0300
Subject: CMake needs a hint to use 64 bit target with msvc.

Only when using Windows 64 bits and the msvc compiler. CMake
uses the x86 generator by default. We need to tell it explicitly
that we wan't to use the x64 generator.

refs #382
---
 src/luarocks/build/cmake.lua | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/luarocks/build/cmake.lua b/src/luarocks/build/cmake.lua
index a1c08dfa..3d0f22a2 100644
--- a/src/luarocks/build/cmake.lua
+++ b/src/luarocks/build/cmake.lua
@@ -37,16 +37,16 @@ function cmake.run(rockspec)
 
    -- Execute cmake with variables.
    local args = ""
-   if cfg.cmake_generator then
+   
+   -- Try to pick the best generator. With msvc and x64, CMake does not select it by default so we need to be explicit.
+   if cfg.is_platform("mingw32") and cfg.cmake_generator then
       args = args .. ' -G"'..cfg.cmake_generator.. '"'
-   end
-   for k,v in pairs(variables) do
-      args = args .. ' -D' ..k.. '="' ..v.. '"'
+   elseif cfg.is_platform("windows") and cfg.arch:match("%-x86_64$") then
+      args = args .. " -DCMAKE_GENERATOR_PLATFORM=x64"
    end
 
-   -- Generate 64 bit build if appropiate.
-   if not not cfg.arch:match("%-x86_64$") then
-      args = args .. " -DCMAKE_GENERATOR_PLATFORM=x64"
+   for k,v in pairs(variables) do
+      args = args .. ' -D' ..k.. '="' ..tostring(v).. '"'
    end
 
    if not fs.execute_string(rockspec.variables.CMAKE.." -H. -Bbuild.luarocks "..args) then
-- 
cgit v1.2.3-55-g6feb


From 797b95f830c7a2fbd886e74ff7b441fbc41b0701 Mon Sep 17 00:00:00 2001
From: Ignacio Burgueño <ignaciob@inconcertcc.com>
Date: Wed, 24 Jun 2015 15:44:52 -0300
Subject: Use new key target_cpu

---
 src/luarocks/build/cmake.lua | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/luarocks/build/cmake.lua b/src/luarocks/build/cmake.lua
index 3d0f22a2..22ee2cde 100644
--- a/src/luarocks/build/cmake.lua
+++ b/src/luarocks/build/cmake.lua
@@ -41,7 +41,7 @@ function cmake.run(rockspec)
    -- Try to pick the best generator. With msvc and x64, CMake does not select it by default so we need to be explicit.
    if cfg.is_platform("mingw32") and cfg.cmake_generator then
       args = args .. ' -G"'..cfg.cmake_generator.. '"'
-   elseif cfg.is_platform("windows") and cfg.arch:match("%-x86_64$") then
+   elseif cfg.is_platform("windows") and cfg.target_cpu:match("x86_64$") then
       args = args .. " -DCMAKE_GENERATOR_PLATFORM=x64"
    end
 
-- 
cgit v1.2.3-55-g6feb


From 79ffabfb806ff608db0cb9356627c61889b73284 Mon Sep 17 00:00:00 2001
From: Ignacio Burgueño <ignaciob@inconcertcc.com>
Date: Thu, 25 Jun 2015 11:22:34 -0300
Subject: Don't restrict the generator override to mingw

---
 src/luarocks/build/cmake.lua | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/luarocks/build/cmake.lua b/src/luarocks/build/cmake.lua
index 22ee2cde..7b16fa51 100644
--- a/src/luarocks/build/cmake.lua
+++ b/src/luarocks/build/cmake.lua
@@ -39,7 +39,7 @@ function cmake.run(rockspec)
    local args = ""
    
    -- Try to pick the best generator. With msvc and x64, CMake does not select it by default so we need to be explicit.
-   if cfg.is_platform("mingw32") and cfg.cmake_generator then
+   if cfg.cmake_generator then
       args = args .. ' -G"'..cfg.cmake_generator.. '"'
    elseif cfg.is_platform("windows") and cfg.target_cpu:match("x86_64$") then
       args = args .. " -DCMAKE_GENERATOR_PLATFORM=x64"
-- 
cgit v1.2.3-55-g6feb


From e1badc44a12e99ffb4820bf216f1e9cc36dbf88a Mon Sep 17 00:00:00 2001
From: Ignacio Burgueño <iburgueno@gmail.com>
Date: Thu, 25 Jun 2015 18:42:16 -0300
Subject: Update appveyor test matrix to use Lua 5.3.1

---
 appveyor.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/appveyor.yml b/appveyor.yml
index 140308ce..abf15af6 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -11,7 +11,7 @@ environment:
   matrix:
   - LUA_VER: 5.1.5
   - LUA_VER: 5.2.4
-  - LUA_VER: 5.3.0
+  - LUA_VER: 5.3.1
   - LJ_VER: 2.0.4
   - LJ_VER: 2.1
 
-- 
cgit v1.2.3-55-g6feb


From 4c7a5bc9914b1dada3616057cd9b7b214200efe7 Mon Sep 17 00:00:00 2001
From: mpeterv <mpeterval@gmail.com>
Date: Fri, 26 Jun 2015 14:46:05 +0300
Subject: Add '--rockspec-format' option for write_rockspec command

'--rockspec-format' option allows selecting rockspec format version when
writing a rockspec.
---
 src/luarocks/util.lua           |  1 +
 src/luarocks/write_rockspec.lua | 26 ++++++++++++++------------
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua
index 6fecf863..c06c8354 100644
--- a/src/luarocks/util.lua
+++ b/src/luarocks/util.lua
@@ -118,6 +118,7 @@ local supported_flags = {
    ["rock-tree"] = true,
    ["rock-trees"] = true,
    ["rockspec"] = true,
+   ["rockspec-format"] = "<ver>",
    ["server"] = "<server>",
    ["skip-pack"] = true,
    ["source"] = true,
diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua
index 68942e07..972562c3 100644
--- a/src/luarocks/write_rockspec.lua
+++ b/src/luarocks/write_rockspec.lua
@@ -24,18 +24,19 @@ If a repository URL is given with no version, it creates an 'scm' rock.
 Note that the generated file is a _starting point_ for writing a
 rockspec, and is not guaranteed to be complete or correct.
 
---output=<file>       Write the rockspec with the given filename.
-                      If not given, a file is written in the current
-                      directory with a filename based on given name and version.
---license="<string>"  A license string, such as "MIT/X11" or "GNU GPL v3".
---summary="<txt>"     A short one-line description summary.
---detailed="<txt>"    A longer description string.
---homepage=<url>      Project homepage.
---lua-version=<ver>   Supported Lua versions. Accepted values are "5.1", "5.2",
-                      "5.3", "5.1,5.2", "5.2,5.3", or "5.1,5.2,5.3".
---tag=<tag>           Tag to use. Will attempt to extract version number from it.
---lib=<lib>[,<lib>]   A comma-separated list of libraries that C files need to
-                      link to.
+--output=<file>          Write the rockspec with the given filename.
+                         If not given, a file is written in the current
+                         directory with a filename based on given name and version.
+--license="<string>"     A license string, such as "MIT/X11" or "GNU GPL v3".
+--summary="<txt>"        A short one-line description summary.
+--detailed="<txt>"       A longer description string.
+--homepage=<url>         Project homepage.
+--lua-version=<ver>      Supported Lua versions. Accepted values are "5.1", "5.2",
+                         "5.3", "5.1,5.2", "5.2,5.3", or "5.1,5.2,5.3".
+--rockspec-format=<ver>  Rockspec format version, such as "1.0" or "1.1".
+--tag=<tag>              Tag to use. Will attempt to extract version number from it.
+--lib=<lib>[,<lib>]      A comma-separated list of libraries that C files need to
+                         link to.
 ]]
 
 local function open_file(name)
@@ -246,6 +247,7 @@ function write_rockspec.run(...)
    end
 
    local rockspec = {
+      rockspec_format = flags["rockspec-format"],
       package = name,
       name = name:lower(),
       version = version.."-1",
-- 
cgit v1.2.3-55-g6feb


From 19ce8a62a8ac32f9af9aa7255d3f9fa097eed676 Mon Sep 17 00:00:00 2001
From: mpeterv <mpeterval@gmail.com>
Date: Fri, 26 Jun 2015 14:47:19 +0300
Subject: Add a test for '--rockspec-format' option

---
 test/testing.lua | 1 +
 test/testing.sh  | 1 +
 2 files changed, 2 insertions(+)

diff --git a/test/testing.lua b/test/testing.lua
index 44c6f098..48d4ac0e 100644
--- a/test/testing.lua
+++ b/test/testing.lua
@@ -400,6 +400,7 @@ local tests = {
    end,   
    test_write_rockspec = function() return run "$luarocks write_rockspec git://github.com/keplerproject/luarocks" end,
    test_write_rockspec_lib = function() return run '$luarocks write_rockspec git://github.com/mbalmer/luafcgi --lib=fcgi --license="3-clause BSD" --lua-version=5.1,5.2' end,
+   test_write_rockspec_format = function() return run '$luarocks write_rockspec git://github.com/keplerproject/luarocks --rockspec-format=1.1 --lua-version=5.1,5.2' end,
    test_write_rockspec_fullargs = function() return run '$luarocks write_rockspec git://github.com/keplerproject/luarocks --lua-version=5.1,5.2 --license="MIT/X11" --homepage="http://www.luarocks.org" --summary="A package manager for Lua modules"' end,
    fail_write_rockspec_args = function() return run "$luarocks write_rockspec invalid" end,
    fail_write_rockspec_args_url = function() return run "$luarocks write_rockspec http://example.com/invalid.zip" end,
diff --git a/test/testing.sh b/test/testing.sh
index 4338e48f..c43b4d52 100755
--- a/test/testing.sh
+++ b/test/testing.sh
@@ -492,6 +492,7 @@ test_deps_mode_make_order_sys() { $luarocks build --tree="$testing_tree" lpeg &&
 
 test_write_rockspec() { $luarocks write_rockspec git://github.com/keplerproject/luarocks; }
 test_write_rockspec_lib() { $luarocks write_rockspec git://github.com/mbalmer/luafcgi --lib=fcgi --license="3-clause BSD" --lua-version=5.1,5.2; }
+test_write_rockspec_format() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --rockspec-format=1.1 --lua-version=5.1,5.2; }
 test_write_rockspec_fullargs() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --lua-version=5.1,5.2 --license="MIT/X11" --homepage="http://www.luarocks.org" --summary="A package manager for Lua modules"; }
 fail_write_rockspec_args() { $luarocks write_rockspec invalid; }
 fail_write_rockspec_args_url() { $luarocks write_rockspec http://example.com/invalid.zip; }
-- 
cgit v1.2.3-55-g6feb