Skip to content

Commit 33d32b0

Browse files
committed
FEAT: automatic download of the well known extension modules
1 parent c78ff1a commit 33d32b0

File tree

5 files changed

+133
-34
lines changed

5 files changed

+133
-34
lines changed

.github/workflows/main.yml

+9
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ jobs:
3939
- name: Test Rebol/SQLite extension
4040
run: ./rebol3-bulk-windows-x64.exe -s ./src/tests/test-extension-sqlite.r3
4141

42+
- name: Test Rebol/Blend2D extension
43+
run: ./rebol3-bulk-windows-x64.exe -s ./src/tests/test-extension-blend2d.r3
44+
4245

4346
###############################################################################
4447
# Collecting build artifacts...
@@ -77,6 +80,9 @@ jobs:
7780
- name: Test Rebol/SQLite extension
7881
run: ./build/rebol3-bulk-linux-x64 -s ./src/tests/test-extension-sqlite.r3
7982

83+
- name: Test Rebol/Blend2D extension
84+
run: ./build/rebol3-bulk-linux-x64 -s ./src/tests/test-extension-blend2d.r3
85+
8086
- name: Prepare 64bit Rebol/Bulk for upload
8187
run: |
8288
mv ./build/rebol3-bulk-linux-x64 ./rebol3-bulk-linux-x64
@@ -116,6 +122,9 @@ jobs:
116122
- name: Test Rebol/SQLite extension
117123
run: ./build/rebol3-bulk-macos-x64 -s ./src/tests/test-extension-sqlite.r3
118124

125+
- name: Test Rebol/Blend2D extension
126+
run: ./build/rebol3-bulk-macos-x64 -s ./src/tests/test-extension-blend2d.r3
127+
119128
- name: Prepare 64bit Rebol/Bulk for upload
120129
run: |
121130
mv ./build/rebol3-bulk-macos-x64 ./rebol3-bulk-macos-x64

src/boot/sysobj.reb

+5-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ state: object [
9797
last-result: none ; used to store last console result
9898
]
9999

100-
modules: object []
100+
modules: object [
101+
blend2d: https://github.com/Siskin-framework/Rebol-Blend2D/releases/download/0.0.18.0/
102+
sqlite: https://github.com/Siskin-framework/Rebol-SQLite/releases/download/3.38.5.0/
103+
httpd: https://raw.githubusercontent.com/Oldes/Rebol3/master/src/modules/httpd.reb
104+
]
101105

102106
codecs: object []
103107

src/mezz/sys-load.reb

+62-2
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,8 @@ load-module: function [
539539
delay: no-share: none hdr: spec-of mod
540540
assert/type [hdr/options [block! none!]]
541541
]
542-
block? mod [set/any [hdr: code:] mod]
543-
; module/block mod used later for override testing
542+
block? mod [set/any [hdr: code:] mod] ; module/block mod used later for override testing
543+
url? mod [return none ] ; used by `import` for downloading extensions
544544

545545
; Get and process the header
546546
not hdr [
@@ -579,6 +579,7 @@ load-module: function [
579579
case/all [
580580
module? :mod0 [hdr0: spec-of mod0] ; final header
581581
block? :mod0 [hdr0: first mod0] ; cached preparsed header
582+
url? :mod0 [hdr0: object [version: 0.0.0 url: :mod0 checksum: none]]
582583
;assert/type [name0 word! hdr0 object! sum0 [binary! none!]] none
583584
;not tuple? set/any 'ver0 :hdr0/version [ver0: 0.0.0] ;@@ remove?
584585
]
@@ -647,6 +648,49 @@ load-module: function [
647648
reduce [name if module? mod [mod]]
648649
]
649650

651+
locate-extension: function[name [word!]][
652+
foreach path system/options/module-paths [
653+
file: append to file! name %.rebx
654+
if exists? path/:file [ return path/:file ]
655+
file: repend to file! name [#"-" system/build/os #"-" system/build/arch %.rebx]
656+
if exists? path/:file [ return path/:file ]
657+
]
658+
none
659+
]
660+
661+
download-extension: function[
662+
"Downloads extension from a given url and stores it in a current directory!"
663+
name [word!]
664+
url [url!]
665+
][
666+
either dir? url [
667+
file: repend to file! name [#"-" system/build/os #"-" system/build/arch %.rebx]
668+
url: append copy url file
669+
if system/platform <> 'Windows [append url %.gz]
670+
][
671+
file: select decode-url url 'target
672+
]
673+
opt: system/options/log
674+
try/except [
675+
if exists? file [
676+
; we don't want to overwrite existing files!
677+
log/error ["File already exists:^[[m" file]
678+
return file
679+
]
680+
log/info 'REBOL ["Downloading:^[[m" url]
681+
system/options/log: make map! [http: 0 tls: 0]
682+
bin: read url
683+
if %.gz = suffix? url [bin: decompress bin 'gzip]
684+
write file bin
685+
file: to-real-file file ; makes it absolute
686+
][
687+
log/error ["Failed to download:^[[m" file]
688+
file: none
689+
]
690+
system/options/log: opt
691+
file
692+
]
693+
650694
import: function [
651695
"Imports a module; locate, load, make, and setup its bindings."
652696
module [word! file! url! string! binary! module! block!]
@@ -677,7 +721,23 @@ import: function [
677721
path/:file version ver check sum no-share no-lib /import /as module
678722
] [break]
679723
]
724+
unless name [
725+
; try to locate as an extension...
726+
if file: any [
727+
locate-extension module
728+
all [
729+
url? mod: select system/modules module
730+
download-extension module mod
731+
]
732+
][
733+
log/info 'REBOL ["Importing extension:^[[m" file]
734+
set [name: mod:] apply :load-module [
735+
file version ver check sum no-share no-lib /import /as module
736+
]
737+
]
738+
]
680739
]
740+
681741
any [file? module url? module] [
682742
cause-error 'access 'cannot-open reduce [module "not found or not valid"]
683743
]

src/tests/test-extension-blend2d.r3

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Rebol [
2+
Title: "Test Blend2D extension"
3+
File: %test-extension-blend2d.r3
4+
Author: "Oldes"
5+
Date: 15-Jun-2022
6+
Version: 1.0.0
7+
]
8+
9+
blend2d: import 'blend2d
10+
11+
print blend2d/info
12+
13+
img: draw 480x480 [
14+
line-width 20 pen gray
15+
line-join miter line 140x20 40x80 140x80
16+
line-join round line 300x20 200x80 300x80
17+
line-join bevel line 460x20 360x80 460x80
18+
19+
line-join miter line 140x120 40x180 140x180
20+
line-join miter line 300x140 200x180 300x180
21+
line-join miter line 460x150 360x180 460x180
22+
23+
line-join miter round line 140x220 40x280 140x280
24+
line-join miter round line 300x240 200x280 300x280
25+
line-join miter round line 460x250 360x280 460x280
26+
27+
line-join miter bevel line 140x320 40x380 140x380
28+
line-join miter bevel line 300x340 200x380 300x380
29+
line-join miter bevel line 460x350 360x380 460x380
30+
31+
32+
line-join miter
33+
line-width 1 pen black
34+
line 140x20 40x80 140x80
35+
line 300x20 200x80 300x80
36+
line 460x20 360x80 460x80
37+
38+
line 140x120 40x180 140x180
39+
line 300x140 200x180 300x180
40+
line 460x150 360x180 460x180
41+
42+
line 140x220 40x280 140x280
43+
line 300x240 200x280 300x280
44+
line 460x250 360x280 460x280
45+
46+
line 140x320 40x380 140x380
47+
line 300x340 200x380 300x380
48+
line 460x350 360x380 460x380
49+
]
50+
51+
save %test-blend2d-result.png img

src/tests/test-extension-sqlite.r3

+6-31
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,13 @@
11
Rebol [
2-
Title: "Test SQLite extension"
3-
Date: 10-Nov-2021
4-
Author: "Oldes"
5-
File: %test-extension-sqlite.r3
6-
Version: 1.0.0
2+
Title: "Test SQLite extension"
3+
File: %test-extension-sqlite.r3
4+
Author: "Oldes"
5+
Date: 15-Jun-2022
6+
Version: 1.1.0
77
]
88

9-
unless find system/modules 'sqlite [
10-
unless exists? %sqlite.rebx [
11-
;@@ this part should be part of the built-in system!
12-
use [url bin compressed?][
13-
;-- download extension for correct platform...
14-
url: rejoin [
15-
https://github.com/Siskin-framework/Rebol-SQLite/releases/latest/download/
16-
%sqlite- system/build/os #"-" system/build/arch %.rebx
17-
]
18-
if system/build/os <> 'windows [
19-
append url %.gz
20-
compressed?: true
21-
]
9+
sqlite: import 'sqlite
2210

23-
print [as-green "Downloading:" as-yellow url]
24-
;if "true" = get-env "CI" [
25-
; ;enhancing verbosity to try locate source of occasional read errors in CI
26-
; system/schemes/tls/set-verbose 4
27-
; codecs/der/verbose: 4
28-
;]
29-
bin: read url
30-
if compressed? [ bin: decode 'GZIP bin ]
31-
write %sqlite.rebx bin
32-
]
33-
]
34-
sqlite: import %sqlite.rebx
35-
]
3611
? sqlite
3712

3813
print sqlite/info

0 commit comments

Comments
 (0)