annotate share/lua/5.2/luarocks/fetch.lua @ 3026:c8ea00fb641d

<shachaf> addquote <mnoqy> the theory\'s probably not bad, but calculus is one of those things that\'s so dang applicable that everyone only ever talks about how to apply it and compute with it and uuuuurgh(barf) <mnoqy> so i stay away from it
author HackBot
date Sun, 02 Jun 2013 04:42:47 +0000
parents d137f631bad5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1132
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
1
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
2 --- Functions related to fetching and loading local and remote files.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
3 module("luarocks.fetch", package.seeall)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
4
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
5 local fs = require("luarocks.fs")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
6 local dir = require("luarocks.dir")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
7 local type_check = require("luarocks.type_check")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
8 local path = require("luarocks.path")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
9 local deps = require("luarocks.deps")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
10 local persist = require("luarocks.persist")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
11 local util = require("luarocks.util")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
12 local cfg = require("luarocks.cfg")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
13
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
14 --- Fetch a local or remote file.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
15 -- Make a remote or local URL/pathname local, fetching the file if necessary.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
16 -- Other "fetch" and "load" functions use this function to obtain files.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
17 -- If a local pathname is given, it is returned as a result.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
18 -- @param url string: a local pathname or a remote URL.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
19 -- @param filename string or nil: this function attempts to detect the
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
20 -- resulting local filename of the remote file as the basename of the URL;
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
21 -- if that is not correct (due to a redirection, for example), the local
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
22 -- filename can be given explicitly as this second argument.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
23 -- @return string or (nil, string, [string]): the absolute local pathname for the
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
24 -- fetched file, or nil and a message in case of errors, followed by
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
25 -- an optional error code.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
26 function fetch_url(url, filename)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
27 assert(type(url) == "string")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
28 assert(type(filename) == "string" or not filename)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
29
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
30 local protocol, pathname = dir.split_url(url)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
31 if protocol == "file" then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
32 return fs.absolute_name(pathname)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
33 elseif protocol == "http" or protocol == "ftp" or protocol == "https" then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
34 local ok, err = fs.download(url, filename)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
35 if not ok then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
36 return nil, "Failed downloading "..url..(err and " - "..err or ""), "network"
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
37 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
38 return dir.path(fs.current_dir(), filename or dir.base_name(url))
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
39 else
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
40 return nil, "Unsupported protocol "..protocol
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
41 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
42 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
43
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
44 --- For remote URLs, create a temporary directory and download URL inside it.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
45 -- This temporary directory will be deleted on program termination.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
46 -- For local URLs, just return the local pathname and its directory.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
47 -- @param url string: URL to be downloaded
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
48 -- @param tmpname string: name pattern to use for avoiding conflicts
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
49 -- when creating temporary directory.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
50 -- @param filename string or nil: local filename of URL to be downloaded,
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
51 -- in case it can't be inferred from the URL.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
52 -- @return (string, string) or (nil, string, [string]): absolute local pathname of
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
53 -- the fetched file and temporary directory name; or nil and an error message
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
54 -- followed by an optional error code
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
55 function fetch_url_at_temp_dir(url, tmpname, filename)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
56 assert(type(url) == "string")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
57 assert(type(tmpname) == "string")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
58 assert(type(filename) == "string" or not filename)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
59 filename = filename or dir.base_name(url)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
60
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
61 local protocol, pathname = dir.split_url(url)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
62 if protocol == "file" then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
63 if fs.exists(pathname) then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
64 return pathname, dir.dir_name(fs.absolute_name(pathname))
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
65 else
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
66 return nil, "File not found: "..pathname
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
67 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
68 else
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
69 local temp_dir = fs.make_temp_dir(tmpname)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
70 if not temp_dir then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
71 return nil, "Failed creating temporary directory."
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
72 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
73 util.schedule_function(fs.delete, temp_dir)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
74 fs.change_dir(temp_dir)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
75 local file, err, errcode = fetch_url(url, filename)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
76 fs.pop_dir()
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
77 if not file then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
78 return nil, "Error fetching file: "..err, errcode
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
79 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
80 return file, temp_dir
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
81 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
82 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
83
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
84 --- Obtain a rock and unpack it.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
85 -- If a directory is not given, a temporary directory will be created,
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
86 -- which will be deleted on program termination.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
87 -- @param rock_file string: URL or filename of the rock.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
88 -- @param dest string or nil: if given, directory will be used as
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
89 -- a permanent destination.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
90 -- @return string or (nil, string, [string]): the directory containing the contents
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
91 -- of the unpacked rock.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
92 function fetch_and_unpack_rock(rock_file, dest)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
93 assert(type(rock_file) == "string")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
94 assert(type(dest) == "string" or not dest)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
95
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
96 local name = dir.base_name(rock_file):match("(.*)%.[^.]*%.rock")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
97
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
98 local rock_file, err, errcode = fetch_url_at_temp_dir(rock_file,"luarocks-rock-"..name)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
99 if not rock_file then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
100 return nil, "Could not fetch rock file: " .. err, errcode
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
101 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
102
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
103 rock_file = fs.absolute_name(rock_file)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
104 local unpack_dir
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
105 if dest then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
106 unpack_dir = dest
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
107 fs.make_dir(unpack_dir)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
108 else
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
109 unpack_dir = fs.make_temp_dir(name)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
110 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
111 if not dest then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
112 util.schedule_function(fs.delete, unpack_dir)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
113 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
114 fs.change_dir(unpack_dir)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
115 local ok = fs.unzip(rock_file)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
116 if not ok then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
117 return nil, "Failed unpacking rock file: " .. rock_file
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
118 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
119 fs.pop_dir()
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
120 return unpack_dir
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
121 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
122
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
123 --- Back-end function that actually loads the local rockspec.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
124 -- Performs some validation and postprocessing of the rockspec contents.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
125 -- @param filename string: The local filename of the rockspec file.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
126 -- @return table or (nil, string): A table representing the rockspec
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
127 -- or nil followed by an error message.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
128 function load_local_rockspec(filename)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
129 assert(type(filename) == "string")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
130 filename = fs.absolute_name(filename)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
131 local rockspec, err = persist.load_into_table(filename)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
132 if not rockspec then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
133 return nil, "Could not load rockspec file "..filename.." ("..err..")"
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
134 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
135
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
136 local ok, err = type_check.type_check_rockspec(rockspec)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
137 if not ok then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
138 return nil, filename..": "..err
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
139 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
140
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
141 if rockspec.rockspec_format then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
142 if deps.compare_versions(rockspec.rockspec_format, type_check.rockspec_format) then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
143 return nil, "Rockspec format "..rockspec.rockspec_format.." is not supported, please upgrade LuaRocks."
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
144 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
145 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
146
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
147 util.platform_overrides(rockspec.build)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
148 util.platform_overrides(rockspec.dependencies)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
149 util.platform_overrides(rockspec.external_dependencies)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
150 util.platform_overrides(rockspec.source)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
151 util.platform_overrides(rockspec.hooks)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
152
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
153 local basename = dir.base_name(filename)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
154 if basename == "rockspec" then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
155 rockspec.name = rockspec.package:lower()
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
156 else
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
157 rockspec.name = basename:match("(.*)-[^-]*-[0-9]*")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
158 if not rockspec.name then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
159 return nil, "Expected filename in format 'name-version-revision.rockspec'."
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
160 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
161 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
162
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
163 local protocol, pathname = dir.split_url(rockspec.source.url)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
164 if protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
165 rockspec.source.file = rockspec.source.file or dir.base_name(rockspec.source.url)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
166 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
167 rockspec.source.protocol, rockspec.source.pathname = protocol, pathname
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
168
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
169 -- Temporary compatibility
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
170 if rockspec.source.cvs_module then rockspec.source.module = rockspec.source.cvs_module end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
171 if rockspec.source.cvs_tag then rockspec.source.tag = rockspec.source.cvs_tag end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
172
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
173 local name_version = rockspec.package:lower() .. "-" .. rockspec.version
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
174 if basename ~= "rockspec" and basename ~= name_version .. ".rockspec" then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
175 return nil, "Inconsistency between rockspec filename ("..basename..") and its contents ("..name_version..".rockspec)."
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
176 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
177
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
178 rockspec.local_filename = filename
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
179 local filebase = rockspec.source.file or rockspec.source.url
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
180 local base = dir.base_name(filebase)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
181 base = base:gsub("%.[^.]*$", ""):gsub("%.tar$", "")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
182 rockspec.source.dir = rockspec.source.dir
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
183 or rockspec.source.module
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
184 or ((filebase:match(".lua$") or filebase:match(".c$")) and ".")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
185 or base
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
186 if rockspec.dependencies then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
187 for i = 1, #rockspec.dependencies do
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
188 local parsed = deps.parse_dep(rockspec.dependencies[i])
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
189 if not parsed then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
190 return nil, "Parse error processing dependency '"..rockspec.dependencies[i].."'"
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
191 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
192 rockspec.dependencies[i] = parsed
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
193 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
194 else
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
195 rockspec.dependencies = {}
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
196 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
197 local ok, err = path.configure_paths(rockspec)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
198 if err then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
199 return nil, "Error verifying paths: "..err
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
200 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
201
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
202 return rockspec
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
203 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
204
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
205 --- Load a local or remote rockspec into a table.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
206 -- This is the entry point for the LuaRocks tools.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
207 -- Only the LuaRocks runtime loader should use
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
208 -- load_local_rockspec directly.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
209 -- @param filename string: Local or remote filename of a rockspec.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
210 -- @param location string or nil: Where to download. If not given,
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
211 -- a temporary dir is created.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
212 -- @return table or (nil, string, [string]): A table representing the rockspec
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
213 -- or nil followed by an error message and optional error code.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
214 function load_rockspec(filename, location)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
215 assert(type(filename) == "string")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
216
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
217 local name
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
218 local basename = dir.base_name(filename)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
219 if basename == "rockspec" then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
220 name = "rockspec"
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
221 else
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
222 name = basename:match("(.*)%.rockspec")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
223 if not name and not basename == "rockspec" then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
224 return nil, "Filename '"..filename.."' does not look like a rockspec."
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
225 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
226 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
227
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
228 local err, errcode
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
229 if location then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
230 fs.change_dir(location)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
231 filename, err = fetch_url(filename)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
232 fs.pop_dir()
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
233 else
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
234 filename, err, errcode = fetch_url_at_temp_dir(filename,"luarocks-rockspec-"..name)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
235 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
236 if not filename then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
237 return nil, err, errcode
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
238 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
239
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
240 return load_local_rockspec(filename)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
241 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
242
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
243 --- Download sources for building a rock using the basic URL downloader.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
244 -- @param rockspec table: The rockspec table
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
245 -- @param extract boolean: Whether to extract the sources from
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
246 -- the fetched source tarball or not.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
247 -- @param dest_dir string or nil: If set, will extract to the given directory.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
248 -- @return (string, string) or (nil, string, [string]): The absolute pathname of
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
249 -- the fetched source tarball and the temporary directory created to
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
250 -- store it; or nil and an error message and optional error code.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
251 function get_sources(rockspec, extract, dest_dir)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
252 assert(type(rockspec) == "table")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
253 assert(type(extract) == "boolean")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
254 assert(type(dest_dir) == "string" or not dest_dir)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
255
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
256 local url = rockspec.source.url
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
257 local name = rockspec.name.."-"..rockspec.version
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
258 local filename = rockspec.source.file
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
259 local source_file, store_dir, err, errcode
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
260 if dest_dir then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
261 fs.change_dir(dest_dir)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
262 source_file, err, errcode = fetch_url(url, filename)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
263 fs.pop_dir()
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
264 store_dir = dest_dir
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
265 else
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
266 source_file, store_dir, errcode = fetch_url_at_temp_dir(url, "luarocks-source-"..name, filename)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
267 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
268 if not source_file then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
269 return nil, err or store_dir, errcode
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
270 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
271 if rockspec.source.md5 then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
272 if not fs.check_md5(source_file, rockspec.source.md5) then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
273 return nil, "MD5 check for "..filename.." has failed."
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
274 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
275 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
276 if extract then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
277 fs.change_dir(store_dir)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
278 fs.unpack_archive(rockspec.source.file)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
279 if not fs.exists(rockspec.source.dir) then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
280 return nil, "Directory "..rockspec.source.dir.." not found inside archive "..rockspec.source.file
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
281 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
282 fs.pop_dir()
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
283 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
284 return source_file, store_dir
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
285 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
286
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
287 --- Download sources for building a rock, calling the appropriate protocol method.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
288 -- @param rockspec table: The rockspec table
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
289 -- @param extract boolean: When downloading compressed formats, whether to extract
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
290 -- the sources from the fetched archive or not.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
291 -- @param dest_dir string or nil: If set, will extract to the given directory.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
292 -- @return (string, string) or (nil, string): The absolute pathname of
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
293 -- the fetched source tarball and the temporary directory created to
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
294 -- store it; or nil and an error message.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
295 function fetch_sources(rockspec, extract, dest_dir)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
296 assert(type(rockspec) == "table")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
297 assert(type(extract) == "boolean")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
298 assert(type(dest_dir) == "string" or not dest_dir)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
299
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
300 local protocol = rockspec.source.protocol
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
301 local ok, proto
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
302 if protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
303 proto = require("luarocks.fetch")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
304 else
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
305 ok, proto = pcall(require, "luarocks.fetch."..protocol:gsub("[+-]", "_"))
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
306 if not ok then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
307 return nil, "Unknown protocol "..protocol
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
308 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
309 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
310
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
311 if cfg.only_sources_from
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
312 and rockspec.source.pathname
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
313 and #rockspec.source.pathname > 0 then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
314 if #cfg.only_sources_from == 0 then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
315 return nil, "Can't download "..rockspec.source.url.." -- download from remote servers disabled"
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
316 elseif rockspec.source.pathname:find(cfg.only_sources_from, 1, true) ~= 1 then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
317 return nil, "Can't download "..rockspec.source.url.." -- only downloading from "..cfg.only_sources_from
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
318 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
319 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
320 return proto.get_sources(rockspec, extract, dest_dir)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
321 end