From 6e7e522ffe3204243306cba8d128a7ec21f591f9 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 4 Jun 2018 17:25:39 -0300 Subject: build: make "builtin" the default build.type --- CHANGELOG.md | 1 + spec/build_spec.lua | 27 +++++++++++++++++++++++++++ spec/util/test_env.lua | 21 +++++++++++++-------- src/luarocks/build.lua | 10 ++++++++-- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cbf3d35..798f3c5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ Rockspec 3.0 These features are only enabled if `rockspec_format = "3.0"` is set in the rockspec: +* Build type `builtin` is the default if `build.type` is not specified. * New table `build_dependencies`: dependencies used only for running `luarocks build` but not when installing binary rocks. * New table `test_dependencies`: dependencies used only for running `luarocks test` diff --git a/spec/build_spec.lua b/spec/build_spec.lua index f042cbb9..b703478e 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua @@ -244,6 +244,33 @@ describe("LuaRocks build tests #integration", function() end) end) + describe("rockspec format 3.0 #rs3", function() + it("defaults to build.type == 'builtin'", function() + local rockspec = "a_rock-1.0-1.rockspec" + test_env.write_file(rockspec, [[ + rockspec_format = "3.0" + package = "a_rock" + version = "1.0-1" + source = { + url = "file://]] .. testing_paths.fixtures_dir .. [[/a_rock.lua" + } + description = { + summary = "An example rockspec", + } + dependencies = { + "lua >= 5.1" + } + build = { + modules = { + build = "a_rock.lua" + }, + } + ]], finally) + assert.truthy(run.luarocks_bool("build " .. rockspec)) + assert.is.truthy(run.luarocks("show a_rock")) + end) + end) + describe("#mock external dependencies", function() setup(function() test_env.mock_server_init() diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua index 08d5c850..0c140be7 100644 --- a/spec/util/test_env.lua +++ b/spec/util/test_env.lua @@ -344,12 +344,17 @@ local function download_rocks(urls, save_path) end --- Create a file containing a string. --- @param path string: path to file. +-- @param pathname string: path to file. -- @param str string: content of the file. -local function write_file(path, str) - local file = assert(io.open(path, "w")) +function test_env.write_file(pathname, str, finally) + local file = assert(io.open(pathname, "w")) file:write(str) file:close() + if finally then + finally(function() + os.remove(pathname) + end) + end end --- Create md5sum of directory structure recursively, based on filename and size @@ -666,8 +671,8 @@ local function create_configs() testing_cache = test_env.testing_paths.testing_cache }) - write_file(test_env.testing_paths.testrun_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") - write_file(test_env.testing_paths.testrun_dir .. "/testing_config_show_downloads.lua", config_content + test_env.write_file(test_env.testing_paths.testrun_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") + test_env.write_file(test_env.testing_paths.testrun_dir .. "/testing_config_show_downloads.lua", config_content .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") -- testing_config_sftp.lua @@ -691,7 +696,7 @@ local function create_configs() testing_cache = test_env.testing_paths.testing_cache }) - write_file(test_env.testing_paths.testrun_dir .. "/testing_config_sftp.lua", config_content) + test_env.write_file(test_env.testing_paths.testrun_dir .. "/testing_config_sftp.lua", config_content) -- luacov.config config_content = substitute([[ @@ -710,7 +715,7 @@ local function create_configs() testrun_dir = test_env.testing_paths.testrun_dir }) - write_file(test_env.testing_paths.testrun_dir .. "/luacov.config", config_content) + test_env.write_file(test_env.testing_paths.testrun_dir .. "/luacov.config", config_content) config_content = [[ -- Config file of mock LuaRocks.org site for tests @@ -720,7 +725,7 @@ local function create_configs() api_version = "1", } ]] - write_file(test_env.testing_paths.testrun_dir .. "/luarocks_site.lua", config_content) + test_env.write_file(test_env.testing_paths.testrun_dir .. "/luarocks_site.lua", config_content) end --- Remove testing directories. diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index fe004fb5..25e73b0d 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -170,8 +170,14 @@ function build.build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_m return nil, err, errcode elseif not rockspec.build then return nil, "Rockspec error: build table not specified" - elseif not rockspec.build.type then - return nil, "Rockspec error: build type not specified" + end + + if not rockspec.build.type then + if rockspec:format_is_at_least("3.0") then + rockspec.build.type = "builtin" + else + return nil, "Rockspec error: build type not specified" + end end if not build_only_deps then -- cgit v1.2.3-55-g6feb