From a1ec2d939bf10e6429f46b8b74c95927dcc3a6dc Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 5 Sep 2011 00:15:17 -0300 Subject: Add support for working on future extensions of the rockspec format; start with support for disabling the bin/ wrappers. --- src/luarocks/build.lua | 2 +- src/luarocks/command_line.lua | 6 ++++++ src/luarocks/install.lua | 7 ++++++- src/luarocks/rep.lua | 18 ++++++++++++++++-- src/luarocks/type_check.lua | 17 +++++++++++++++++ 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index dec61999..69f46fcc 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -225,7 +225,7 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode) ok, err = manif.make_rock_manifest(name, version) if err then return nil, err end - ok, err = rep.deploy_files(name, version) + ok, err = rep.deploy_files(name, version, rep.should_wrap_bin_scripts(rockspec)) if err then return nil, err end util.remove_scheduled_function(rollback) diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index 02793c5a..dfb28e99 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua @@ -79,6 +79,12 @@ function run_command(...) end end command = command:gsub("-", "_") + + if flags["extensions"] then + cfg.use_extensions = true + local type_check = require("luarocks.type_check") + type_check.load_extensions() + end if cfg.local_by_default then flags["local"] = true diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index e99b4ce0..c42542c9 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua @@ -65,7 +65,12 @@ function install_binary_rock(rock_file) ok, err, errcode = deps.fulfill_dependencies(rockspec) if err then return nil, err, errcode end - ok, err = rep.deploy_files(name, version) + local wrap_bin_scripts = true + if rockspec.deploy and rockspec.deploy.wrap_bin_scripts == false then + wrap_bin_scripts = false + end + + ok, err = rep.deploy_files(name, version, rep.should_wrap_bin_scripts(rockspec)) if err then return nil, err end util.remove_scheduled_function(rollback) diff --git a/src/luarocks/rep.lua b/src/luarocks/rep.lua index f8f1f694..5bb5fed5 100644 --- a/src/luarocks/rep.lua +++ b/src/luarocks/rep.lua @@ -194,9 +194,22 @@ local function resolve_conflict(target, deploy_dir, name, version) end end -function deploy_files(name, version) +function should_wrap_bin_scripts(rockspec) + assert(type(rockspec) == "table") + + if cfg.wrap_bin_scripts ~= nil then + return cfg.wrap_bin_scripts + end + if rockspec.deploy and rockspec.deploy.wrap_bin_scripts == false then + return false + end + return true +end + +function deploy_files(name, version, wrap_bin_scripts) assert(type(name) == "string") assert(type(version) == "string") + assert(type(wrap_bin_scripts) == "boolean") local function deploy_file_tree(file_tree, source_dir, deploy_dir, move_fn) if not move_fn then @@ -230,7 +243,8 @@ function deploy_files(name, version) local ok, err = true if rock_manifest.bin then - ok, err = deploy_file_tree(rock_manifest.bin, path.bin_dir(name, version), cfg.deploy_bin_dir, install_binary) + local move_bin_fn = wrap_bin_scripts and install_binary or fs.copy_binary + ok, err = deploy_file_tree(rock_manifest.bin, path.bin_dir(name, version), cfg.deploy_bin_dir, move_bin_fn) end if ok and rock_manifest.lua then ok, err = deploy_file_tree(rock_manifest.lua, path.lua_dir(name, version), cfg.deploy_lua_dir) diff --git a/src/luarocks/type_check.lua b/src/luarocks/type_check.lua index 0e4a73af..4c554809 100644 --- a/src/luarocks/type_check.lua +++ b/src/luarocks/type_check.lua @@ -4,6 +4,8 @@ -- loaded by LuaRocks. module("luarocks.type_check", package.seeall) +local cfg = require("luarocks.cfg") + rockspec_format = "1.0" rockspec_types = { @@ -72,6 +74,17 @@ rockspec_types = { } } +function load_extensions() + rockspec_format = "1.1" + rockspec_types.deploy = { + wrap_bin_scripts = true, + } +end + +if cfg.use_extensions then + load_extensions() +end + rockspec_types.build.platforms.ANY = rockspec_types.build rockspec_types.dependencies.platforms.ANY = rockspec_types.dependencies rockspec_types.external_dependencies.platforms.ANY = rockspec_types.external_dependencies @@ -218,6 +231,10 @@ end -- succeeded, or nil and an error message if it failed. function type_check_rockspec(rockspec) assert(type(rockspec) == "table") + if rockspec.rockspec_format then + -- relies on global state + load_extensions() + end return type_check_table(rockspec, rockspec_types, "") end -- cgit v1.2.3-55-g6feb