Skip to content

Commit 80879a6

Browse files
committed
Linking added
1 parent 5997bd8 commit 80879a6

File tree

2 files changed

+61
-50
lines changed

2 files changed

+61
-50
lines changed

cmd/packages.pony

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
1+
class val Binary
2+
let name: String
3+
let required: Bool
4+
5+
new val create(n: String, req: Bool = true) =>
6+
name = n
7+
required = req
8+
19
trait val PackageFoo
210
fun name(): String
3-
fun required_binaries(): Array[String] val
4-
fun optional_binaries(): Array[String] val
11+
fun binaries(): Array[Binary] val
512

613
primitive CorralPackage is PackageFoo
714
fun name(): String => "corral"
8-
fun required_binaries(): Array[String] val => ["corral"]
9-
fun optional_binaries(): Array[String] val => []
15+
fun binaries(): Array[Binary] val => [Binary("corral")]
1016

1117
primitive PonycPackage is PackageFoo
1218
fun name(): String => "ponyc"
13-
fun required_binaries(): Array[String] val => ["ponyc"]
14-
fun optional_binaries(): Array[String] val => ["pony-lsp"]
19+
fun binaries(): Array[Binary] val => [
20+
Binary("ponyc")
21+
Binary("pony-lsp", false)
22+
]
1523

1624
primitive PonyupPackage is PackageFoo
1725
fun name(): String => "ponyup"
18-
fun required_binaries(): Array[String] val => ["ponyup"]
19-
fun optional_binaries(): Array[String] val => []
26+
fun binaries(): Array[Binary] val => [Binary("ponyup")]
2027

2128
primitive ChangelogToolPackage is PackageFoo
2229
fun name(): String => "changelog-tool"
23-
fun required_binaries(): Array[String] val => ["changelog-tool"]
24-
fun optional_binaries(): Array[String] val => []
30+
fun binaries(): Array[Binary] val => [Binary("changelog-tool")]
2531

2632
primitive StablePackage is PackageFoo
2733
fun name(): String => "stable"
28-
fun required_binaries(): Array[String] val => ["stable"]
29-
fun optional_binaries(): Array[String] val => []
34+
fun binaries(): Array[Binary] val => [Binary("stable")]
3035

3136
primitive Packages
3237
fun apply(): Array[PackageFoo] box =>

cmd/ponyup.pony

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -211,55 +211,61 @@ actor Ponyup
211211
end
212212

213213
ifdef windows then
214-
let link_rel: String = Path.sep().join(["bin"; pkg'.name()].values())
215-
+ ".exe"
216-
let bin_rel: String = Path.sep().join([pkg'.string(); link_rel].values())
214+
for binary in pkg'.package.binaries().values() do
215+
let link_rel: String = Path.sep().join(["bin"; binary.name].values())
216+
+ ".exe"
217+
let bin_rel: String = Path.sep().join([pkg'.string(); link_rel].values())
217218

218-
try
219-
let bin_path = _root.join(bin_rel)?
220-
_notify.log(Info, " bin: " + bin_path.path)
219+
try
220+
let bin_path = _root.join(bin_rel)?
221+
// It is ok for optional binaries to not exist. If they don't then
222+
// we just skip them.
223+
if (not binary.required) and (not bin_path.exists()) then
224+
continue
225+
end
226+
_notify.log(Info, " bin: " + bin_path.path)
221227

222-
let link_dir = _root.join("bin")?
223-
if not link_dir.exists() then link_dir.mkdir() end
228+
let link_dir = _root.join("bin")?
229+
if not link_dir.exists() then link_dir.mkdir() end
224230

225-
let link_path = link_dir.join(pkg'.name() + ".bat")?
226-
_notify.log(Info, "link: " + link_path.path)
231+
let link_path = link_dir.join(pkg'.name() + ".bat")?
232+
_notify.log(Info, "link: " + link_path.path)
227233

228-
if link_path.exists() then link_path.remove() end
229-
with file = File.create(link_path) do
230-
file.print("@echo off")
231-
file.print("\"" + bin_path.path + "\" %*")
234+
if link_path.exists() then link_path.remove() end
235+
with file = File.create(link_path) do
236+
file.print("@echo off")
237+
file.print("\"" + bin_path.path + "\" %*")
238+
end
239+
else
240+
_notify.log(Err, "failed to create link batch file(s)")
232241
end
233-
else
234-
_notify.log(Err, "failed to create link batch file")
235242
end
236243
else
237-
// TODO STA:
238-
// bin_path is our primary required binaries
239-
// we need to loop over this for required to get link_rel for
240-
// all required. and do the existing logic.
241-
// for optional we need to loop over and if the bin_path exists,
242-
// do the link
243-
// instead of pkg'.name() we use the required or optional values
244-
//
245-
let link_rel: String = "/".join(["bin"; pkg'.name()].values())
246-
let bin_rel: String = "/".join([pkg'.string(); link_rel].values())
244+
for binary in pkg'.package.binaries().values() do
245+
let link_rel: String = "/".join(["bin"; binary.name].values())
246+
let bin_rel: String = "/".join([pkg'.string(); link_rel].values())
247247

248-
try
249-
let bin_path = _root.join(bin_rel)?
250-
_notify.log(Info, " bin: " + bin_path.path)
248+
try
249+
let bin_path = _root.join(bin_rel)?
250+
// It is ok for optional binaries to not exist. If they don't then
251+
// we just skip them.
252+
if (not binary.required) and (not bin_path.exists()) then
253+
continue
254+
end
255+
_notify.log(Info, " bin: " + bin_path.path)
251256

252-
let link_dir = _root.join("bin")?
253-
if not link_dir.exists() then link_dir.mkdir() end
257+
let link_dir = _root.join("bin")?
258+
if not link_dir.exists() then link_dir.mkdir() end
254259

255-
let link_path = link_dir.join(pkg'.name())?
256-
_notify.log(Info, "link: " + link_path.path)
260+
let link_path = link_dir.join(pkg'.name())?
261+
_notify.log(Info, "link: " + link_path.path)
257262

258-
if link_path.exists() then link_path.remove() end
259-
if not bin_path.symlink(link_path) then error end
260-
else
261-
_notify.log(Err, "failed to create symbolic link")
262-
return
263+
if link_path.exists() then link_path.remove() end
264+
if not bin_path.symlink(link_path) then error end
265+
else
266+
_notify.log(Err, "failed to create symbolic link(s)")
267+
return
268+
end
263269
end
264270
end
265271

0 commit comments

Comments
 (0)