From 9446ac85d8bf085d2a6f0a02a6a432e14dddac61 Mon Sep 17 00:00:00 2001 From: Paul Ouellette Date: Fri, 15 Nov 2019 14:08:29 -0500 Subject: Support make --no-doc (#1092) * Support make --no-doc * Add test for make --no-doc --- spec/make_spec.lua | 16 ++++++++++++++++ src/luarocks/cmd/build.lua | 20 +++----------------- src/luarocks/cmd/install.lua | 14 +++----------- src/luarocks/cmd/make.lua | 11 ++++++++++- src/luarocks/util.lua | 17 ++++++++++++++++- 5 files changed, 48 insertions(+), 30 deletions(-) diff --git a/spec/make_spec.lua b/spec/make_spec.lua index 0fc5cd93..5ec99fa7 100644 --- a/spec/make_spec.lua +++ b/spec/make_spec.lua @@ -49,6 +49,22 @@ describe("LuaRocks make tests #integration", function() assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/luasocket/3.0rc1-2/luasocket-3.0rc1-2.rockspec")) end) + it("LuaRocks make --no-doc", function() + finally(function() + lfs.chdir(testing_paths.testrun_dir) + test_env.remove_dir("luasocket-3.0rc1-2") + os.remove("luasocket-3.0rc1-2.src.rock") + end) + + assert.is_true(run.luarocks_bool("download --source luasocket 3.0rc1-2")) + assert.is_true(run.luarocks_bool("unpack luasocket-3.0rc1-2.src.rock")) + lfs.chdir("luasocket-3.0rc1-2/luasocket-3.0-rc1/") + assert.is_true(run.luarocks_bool("make --no-doc luasocket-3.0rc1-2.rockspec")) + + assert.is_true(run.luarocks_bool("show luasocket")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/luasocket/3.0rc1-2/doc")) + end) + describe("LuaRocks making rockspecs (using lxsh)", function() --download lxsh and unpack it before_each(function() diff --git a/src/luarocks/cmd/build.lua b/src/luarocks/cmd/build.lua index ea47cbb0..1819d0da 100644 --- a/src/luarocks/cmd/build.lua +++ b/src/luarocks/cmd/build.lua @@ -3,7 +3,6 @@ -- Builds a rock, compiling its C parts if any. local cmd_build = {} -local dir = require("luarocks.dir") local pack = require("luarocks.pack") local path = require("luarocks.path") local util = require("luarocks.util") @@ -29,8 +28,7 @@ function cmd_build.add_to_parser(parser) cmd:argument("version", "Rock version.") :args("?") - cmd:flag("--only-deps", "Installs only the dependencies of the rock.") - cmd:flag("--no-doc", "Installs the rock without its documentation.") + cmd:flag("--only-deps", "Install only the dependencies of the rock.") cmd:option("--branch", "Override the `source.branch` field in the loaded ".. "rockspec. Allows to specify a different branch to fetch. Particularly ".. 'for "dev" rocks.') @@ -104,18 +102,6 @@ local function do_build(ns_name, version, opts) return build_rock(url, opts) end -local function remove_doc_dir(name, version) - local install_dir = path.install_dir(name, version) - for _, f in ipairs(fs.list_dir(install_dir)) do - local doc_dirs = { "doc", "docs" } - for _, d in ipairs(doc_dirs) do - if f == d then - fs.delete(dir.path(install_dir, f)) - end - end - end -end - --- Driver function for "build" command. -- If a package name is given, forwards the request to "search" and, -- if returned a result, installs the matching rock. @@ -148,7 +134,7 @@ function cmd_build.command(args) opts.build_only_deps = false local name, version, errcode = do_build(name, args.version, opts) if name and args.no_doc then - remove_doc_dir(name, version) + util.remove_doc_dir(name, version) end return name, version, errcode end) @@ -165,7 +151,7 @@ function cmd_build.command(args) name, version = ok, err if args.no_doc then - remove_doc_dir(name, version) + util.remove_doc_dir(name, version) end if opts.build_only_deps then diff --git a/src/luarocks/cmd/install.lua b/src/luarocks/cmd/install.lua index be4b0104..b4c87f7c 100644 --- a/src/luarocks/cmd/install.lua +++ b/src/luarocks/cmd/install.lua @@ -31,8 +31,8 @@ function install.add_to_parser(parser) "previously installed versions if it would break dependencies.") cmd:flag("--force-fast", "Like --force, but performs a forced removal ".. "without reporting dependency issues.") - cmd:flag("--only-deps", "Installs only the dependencies of the rock.") - cmd:flag("--no-doc", "Installs the rock without its documentation.") + cmd:flag("--only-deps", "Install only the dependencies of the rock.") + cmd:flag("--no-doc", "Install the rock without its documentation.") cmd:flag("--verify", "Verify signature of the rockspec or src.rock being ".. "built. If the rockspec or src.rock is being downloaded, LuaRocks will ".. "attempt to download the signature as well. Otherwise, the signature ".. @@ -190,15 +190,7 @@ local function install_rock_file(filename, opts) if not name then return nil, version end if opts.no_doc then - local install_dir = path.install_dir(name, version) - for _, f in ipairs(fs.list_dir(install_dir)) do - local doc_dirs = { "doc", "docs" } - for _, d in ipairs(doc_dirs) do - if f == d then - fs.delete(dir.path(install_dir, f)) - end - end - end + util.remove_doc_dir(name, version) end if (not opts.keep) and not cfg.keep_other_versions then diff --git a/src/luarocks/cmd/make.lua b/src/luarocks/cmd/make.lua index 3ff5c277..0a1f99f0 100644 --- a/src/luarocks/cmd/make.lua +++ b/src/luarocks/cmd/make.lua @@ -17,6 +17,7 @@ local writer = require("luarocks.manif.writer") local cmd = require("luarocks.cmd") function make.cmd_options(parser) + parser:flag("--no-doc", "Install the rock without its documentation.") parser:flag("--pack-binary-rock", "Do not install rock. Instead, produce a ".. ".rock file with the contents of compilation in the current directory.") parser:flag("--keep", "Do not remove previously installed versions of the ".. @@ -101,7 +102,11 @@ function make.command(args) if args.pack_binary_rock then return pack.pack_binary_rock(name, rockspec.version, args.sign, function() - return build.build_rockspec(rockspec, opts) + local name, version = build.build_rockspec(rockspec, opts) + if name and args.no_doc then + util.remove_doc_dir(name, version) + end + return name, version end) else local ok, err = fs.check_command_permissions(args) @@ -110,6 +115,10 @@ function make.command(args) if not ok then return nil, err end local name, version = ok, err + if args.no_doc then + util.remove_doc_dir(name, version) + end + if (not args.keep) and not cfg.keep_other_versions then local ok, err = remove.remove_other_versions(name, version, args.force, args.force_fast) if not ok then util.printerr(err) end diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 13ddf895..05b2566b 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -628,5 +628,20 @@ function util.get_rocks_provided(rockspec) return rocks_provided end -return util +function util.remove_doc_dir(name, version) + local path = require("luarocks.path") + local fs = require("luarocks.fs") + local dir = require("luarocks.dir") + + local install_dir = path.install_dir(name, version) + for _, f in ipairs(fs.list_dir(install_dir)) do + local doc_dirs = { "doc", "docs" } + for _, d in ipairs(doc_dirs) do + if f == d then + fs.delete(dir.path(install_dir, f)) + end + end + end +end +return util -- cgit v1.2.3-55-g6feb