Skip to content

Commit 0561f86

Browse files
committed
Brief: Fix missing dynamic :syspath inside binscript main.
Remove need for PEG for defn main in binscripts. Summary: Rather than try to add code into a main in a binscript, this change removes the extra line added to all binscripts that remove the dynamic :syspath, if it was added at the top. I'm not sure why it needs to be removed but certainly, removing it means it is not defined when main runs which means janet-pm tries to install into the system syspath, even when a dynamic syspath is set.
1 parent d286871 commit 0561f86

File tree

6 files changed

+17
-76
lines changed

6 files changed

+17
-76
lines changed

spork/declare-cc.janet

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -383,19 +383,6 @@
383383
[&named main]
384384
(install-rule main "bin" 8r755 (mkbin)))
385385

386-
(defn- main-replacer [dynamic-syspath hardcode-syspath l2 l3 l4]
387-
(def parts @[])
388-
(if (or dynamic-syspath hardcode-syspath) (array/push parts (string "\n " l2)))
389-
(if hardcode-syspath (array/push parts (string " " l3)))
390-
(if hardcode-syspath (array/push parts (string " " l4)))
391-
(fn [m & args] (string m (string/join parts "") "\n")))
392-
393-
(defn- hardcode-syspath-in-main [dynamic-syspath hardcode-syspath contents l2 l3 l4]
394-
(def patt (peg/compile '{:ws (some (choice :a :d :s "[" "&"))
395-
:defn (sequence "(defn" (any "-") :s "main" :ws "]" (any (choice " " "\n")))
396-
:main :defn}))
397-
(peg/replace patt (main-replacer dynamic-syspath hardcode-syspath l2 l3 l4) contents))
398-
399386
(defn declare-binscript
400387
``Declare a janet file to be installed as an executable script. Creates
401388
a shim on windows. If hardcode is true, will insert code into the script
@@ -420,10 +407,7 @@
420407
(if (or dynamic-syspath hardcode-syspath) second-line)
421408
(if hardcode-syspath third-line)
422409
(if hardcode-syspath fourth-line)
423-
(if hardcode-syspath
424-
(hardcode-syspath-in-main dynamic-syspath hardcode-syspath rest second-line third-line fourth-line)
425-
rest)
426-
(if dynamic-syspath last-line))))
410+
rest)))
427411
(install-buffer contents dest 8r755 (mkbin))
428412
(when (is-win-or-mingw)
429413
(def absdest (path/join (dyn *syspath*) dest))

test-project/bin/bin-no-hardcode

Lines changed: 0 additions & 7 deletions
This file was deleted.

test-project/bin/bin-with-main

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
(defn- main
66
[&]
7-
(printf "hello"))
7+
(printf (root-env :syspath)))

test-project/bin/bin-with-oneline-main

Lines changed: 0 additions & 5 deletions
This file was deleted.

test-project/project.janet

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@
1717
:hardcode-syspath true
1818
:is-janet true)
1919

20-
(declare-binscript
21-
:main "bin/bin-with-oneline-main"
22-
:hardcode-syspath true
23-
:is-janet true)
24-
25-
(declare-binscript
26-
:main "bin/bin-no-hardcode"
27-
:hardcode-syspath false
28-
:is-janet true)
29-
3020
(task "pre-build" ["pre-build-test"])
3121
(task "post-build" ["post-build-test"])
3222

test/suite-pm-pre-post.janet

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@
3333
(defn divider [title]
3434
(printf "------------------------------------------\n%s" title))
3535

36+
(defn dump-file [filename]
37+
(let [contents (slurp filename)]
38+
(printf "---------- %s -------------" filename)
39+
(var count 0)
40+
(loop [line :in (string/split "\n" contents)]
41+
(set count (inc count))
42+
(printf "%5d %s" count line))
43+
(print "----------------------------")))
44+
3645
(defn dump-out [output]
3746
(let [out (string/split "\n" (output :out))
3847
err (string/split "\n" (output :err))]
@@ -45,18 +54,6 @@
4554

4655
(def bat (if (= (os/which) :windows) ".bat" ""))
4756

48-
(defn- test-binscript [filename syscount printcount]
49-
(assert (sh/exists? filename))
50-
(let [contents (slurp filename)]
51-
(printf "---------- %s -------------" filename)
52-
(loop [line :in (string/split "\n" contents)]
53-
(print line))
54-
(print "----------------------------")
55-
(assert (= syscount (length (string/find-all "put root-env :install-time-syspath" contents))))
56-
(assert (= printcount (length (string/find-all "print" contents)))))
57-
# and finally make sure the script actually runs
58-
(assert (= "hello" (sh/exec-slurp (string filename bat)))))
59-
6057
# Create a temporary directory for our janet tree
6158
(math/seedrandom (os/cryptorand 16))
6259
(def syspath (randdir))
@@ -84,15 +81,8 @@
8481
(def binpath (path/join (dyn *syspath*) "bin"))
8582
(def janet-pm (path/join binpath (string "janet-pm")))
8683
(assert (sh/exists? janet-pm))
87-
(assert (= 2 (length (string/find-all "put root-env :install-time-syspath" (slurp janet-pm)))))
88-
89-
(def janet-format (path/join binpath (string "janet-format")))
90-
(assert (sh/exists? janet-format))
91-
(assert (= 2 (length (string/find-all "put root-env :install-time-syspath" (slurp janet-format)))))
92-
93-
(def janet-netrepl (path/join binpath (string "janet-netrepl")))
94-
(assert (sh/exists? janet-netrepl))
95-
(assert (= 2 (length (string/find-all "put root-env :install-time-syspath" (slurp janet-netrepl)))))
84+
(dump-out (sh/exec-slurp-all janet-pm "show-config"))
85+
(assert (= 1 (length (string/find-all "put root-env :install-time-syspath" (slurp janet-pm)))))
9686

9787
# check sub commands work, even without defining pre-/post-
9888

@@ -131,22 +121,11 @@
131121
(assert (after? "pre-install" "post-build" (install-out :out)))
132122
(assert (after? "post-install" "pre-install" (install-out :out)))
133123

134-
# now we look at the binscripts installed from the test-project
135-
# bin-no-main should only have one instance of the hardcoded syspath
136-
(def bin-no-main (path/join binpath (string "bin-no-main")))
137-
(test-binscript bin-no-main 1 1)
138-
139-
# bin-with-main should have 2 instances of hardcoded path
124+
# check that syspath is correctly set inside a main in a binscript
140125
(def bin-with-main (path/join binpath (string "bin-with-main")))
141-
(test-binscript bin-with-main 2 1)
142-
143-
# bin-with-oneline-main could be tricky
144-
(def bin-with-oneline-main (path/join binpath (string "bin-with-oneline-main")))
145-
(test-binscript bin-with-oneline-main 2 1)
146-
147-
# bin-no-hardcode should have zero instances of hardcoded paths
148-
(def bin-no-hardcode (path/join binpath (string "bin-no-hardcode")))
149-
(test-binscript bin-no-hardcode 0 1)
126+
(def bin-out (sh/exec-slurp-all (string bin-with-main bat)))
127+
(dump-out bin-out)
128+
(assert (string/find (dyn *syspath*) (bin-out :out)))
150129

151130
# check "test"
152131
(divider "Running janet-pm test")

0 commit comments

Comments
 (0)