Skip to content

Commit 56ad97d

Browse files
authored
Merge pull request #57 from constraintAutomaton/validation
Feature: Manifest Validation
2 parents 5cb2d47 + 43de9d5 commit 56ad97d

File tree

78 files changed

+937
-177
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+937
-177
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ A package is a directory with a `scryer-manifest.pl`, the current schema is some
1515
name("name_of_the_package").
1616
% Optional. The file that will be imported when this package is used.
1717
main_file("main.pl").
18+
% The license of the package
19+
license(name("Unlicense"), path("./UNLICENSE"))
1820
% Optional
1921
dependencies([
2022
% A git url to clone
@@ -33,7 +35,7 @@ dependencies([
3335

3436
Copy the `bakage.pl` file [from the
3537
releases](https://github.com/bakaq/bakage/releases) into your project. It is
36-
both the dependency manager and the package loader. Use `./bakage.pl install"`
38+
both the dependency manager and the package loader. Use `./bakage.pl install`
3739
to download the dependencies to a `scryer_libs` directory (it doesn't handle
3840
transitive dependencies yet). You can then import packages in your code as
3941
follows:

example/scryer-manifest.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name("name_of_the_package").
22
% Optional. The file that will be imported when this package is used.
33
main_file("main.pl").
4+
%License
5+
license(name("UNLICENSE")).
46
% Optional
57
dependencies([
68
% A git url to clone

justfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ build: codegen-scripts
1717
cat ./src/shebang.sh > "./build/{{BUILD_NAME}}"
1818
cat ./src/bakage.pl >> "./build/{{BUILD_NAME}}"
1919
printf "\n" >> "./build/{{BUILD_NAME}}"
20+
cat ./src/qupak.pl >> "./build/{{BUILD_NAME}}"
21+
printf "\n" >> "./build/{{BUILD_NAME}}"
22+
cat ./src/validation.pl >> "./build/{{BUILD_NAME}}"
23+
printf "\n" >> "./build/{{BUILD_NAME}}"
2024
cat ./src/cli.pl >> "./build/{{BUILD_NAME}}"
2125
printf "\n" >> "./build/{{BUILD_NAME}}"
2226
cat ./build/scripts.pl >> "./build/{{BUILD_NAME}}"
@@ -26,7 +30,7 @@ build: codegen-scripts
2630
codegen-scripts: ensure-build-directory
2731
#!/bin/sh
2832
set -eu
29-
33+
3034
touch ./build/scripts.pl
3135

3236
for file in scripts/*.sh; do

src/bakage.pl

Lines changed: 12 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -131,116 +131,14 @@
131131
current_output(Out),
132132
phrase_to_stream((portray_clause_(D), "is malformed: ", Error, "\n"), Out).
133133

134-
% A valid dependency
135-
valid_dependencies([]) --> [].
136-
137-
valid_dependencies([dependency(Name, path(Path))| Ds]) --> {
138-
if_(
139-
(memberd_t(';', Name)
140-
; memberd_t('|', Name)
141-
; memberd_t(';', Path)
142-
; memberd_t('|', Path)
143-
),
144-
(
145-
Error = "the name and the path of the dependency should not contain an \";\" or an \"|\" caracter",
146-
M = validate_dependency(dependency(Name, path(Path)))-error(Error),
147-
user_message_malformed_dependency(dependency(Name, path(Path)), Error)
148-
),
149-
M = validate_dependency(dependency(Name, path(Path)))-success
150-
)
151-
},
152-
[M],
153-
valid_dependencies(Ds).
154-
155-
valid_dependencies([dependency(Name, git(Url))| Ds]) --> {
156-
if_(
157-
(memberd_t(';', Name)
158-
; memberd_t('|', Name)
159-
; memberd_t(';', Url)
160-
; memberd_t('|', Url)
161-
),
162-
(
163-
Error = "the name of the dependency and the url should not contain an \";\" or an \"|\" caracter",
164-
M = validate_dependency(dependency(Name, git(Url)))-error(Error),
165-
user_message_malformed_dependency(dependency(Name, git(Url)), Error)
166-
),
167-
M = validate_dependency(dependency(Name, git(Url)))-success
168-
)
169-
},
170-
[M],
171-
valid_dependencies(Ds).
172-
173-
valid_dependencies([dependency(Name, git(Url, branch(Branch)))| Ds]) --> {
174-
if_(
175-
(memberd_t(';', Name)
176-
; memberd_t('|', Name)
177-
; memberd_t(';', Url)
178-
; memberd_t('|', Url)
179-
; memberd_t(';', Branch)
180-
; memberd_t('|', Branch)),
181-
(
182-
Error = "the name, the url and the branch of dependency should not contain an \";\" or an \"|\" caracter",
183-
M = validate_dependency(dependency(Name, git(Url, branch(Branch))))-error(Error),
184-
user_message_malformed_dependency(dependency(Name, git(Url, branch(Branch))), Error)
185-
),(
186-
M = validate_dependency(dependency(Name, git(Url, branch(Branch))))-success
187-
)
188-
)
189-
},
190-
[M],
191-
valid_dependencies(Ds).
192-
193-
valid_dependencies([dependency(Name, git(Url, tag(Tag)))|Ds]) --> {
194-
if_(
195-
(memberd_t(';', Name)
196-
; memberd_t('|', Name)
197-
; memberd_t(';', Url)
198-
; memberd_t('|', Url)
199-
; memberd_t(';', Tag)
200-
; memberd_t('|', Tag)),
201-
(
202-
Error = "the name, the url and the tag of dependency should not contain an \";\" or an \"|\" caracter",
203-
M = validate_dependency(dependency(Name, git(Url, tag(Tag))))-error(Error),
204-
user_message_malformed_dependency(dependency(Name, git(Url, tag(Tag))), Error)
205-
),
206-
M = validate_dependency(dependency(Name, git(Url, tag(Tag))))-success
207-
)
208-
},
209-
[M],
210-
valid_dependencies(Ds).
211-
212-
valid_dependencies([dependency(Name, git(Url, hash(Hash)))|Ds]) --> {
213-
if_(
214-
(memberd_t(';', Name)
215-
; memberd_t('|', Name)
216-
; memberd_t(';', Url)
217-
; memberd_t('|', Url)
218-
; memberd_t(';', Hash)
219-
; memberd_t('|', Hash)),
220-
(
221-
Error = "the name, the url and the hash of dependency should not contain an \";\" or an \"|\" caracter",
222-
M = validate_dependency(dependency(Name, git(Url, hash(Hash))))-error(Error),
223-
user_message_malformed_dependency(dependency(Name, git(Url, hash(Hash))), Error)
224-
),
225-
M = validate_dependency(dependency(Name, git(Url, hash(Hash))))-success
226-
)
227-
},
228-
[M],
229-
valid_dependencies(Ds).
230-
231-
all_dependencies_valid_t([], true).
232-
all_dependencies_valid_t([validate_dependency(_)-success| Vs], T) :- all_dependencies_valid_t(Vs, T).
233-
all_dependencies_valid_t([validate_dependency(_)-error(_)| _], false).
234-
235-
236134
% A prolog file knowledge base represented as a list of terms
237135
prolog_kb_list(Stream) --> {read(Stream, Term), dif(Term, end_of_file)}, [Term], prolog_kb_list(Stream).
238136
prolog_kb_list(Stream) --> {read(Stream, Term), Term == end_of_file}, [].
239137

240138
parse_manifest(Filename, Manifest) :-
241139
setup_call_cleanup(
242140
open(Filename, read, Stream),
243-
once(phrase(prolog_kb_list(Stream), Manifest)),
141+
catch(once(phrase(prolog_kb_list(Stream), Manifest)), error(E, I), throw(error_formating_of_manifest(E, I))),
244142
close(Stream)
245143
).
246144

@@ -291,23 +189,18 @@
291189
setenv("SHELL", "/bin/sh"),
292190
setenv("GIT_ADVICE", "0"),
293191
directory_files("scryer_libs/packages", Installed_Packages),
294-
(member(dependencies(Deps), Manifest) ->
295-
(
296-
phrase(valid_dependencies(Deps), Validation_Report),
297-
if_(all_dependencies_valid_t(Validation_Report),
298-
call_cleanup(
299-
(
300-
logical_plan(Plan, Deps, Installed_Packages),
301-
installation_execution(Plan, Installation_Report),
302-
append(Validation_Report, Installation_Report, Report)
303-
),
304-
delete_directory("scryer_libs/temp")
305-
),
192+
if_(valid_manifest_t(Manifest, Validation_Report),
193+
(member(dependencies(Deps), Manifest) ->
194+
call_cleanup(
306195
(
307-
Report = Validation_Report
308-
)
309-
)
310-
); Report = []
196+
logical_plan(Plan, Deps, Installed_Packages),
197+
installation_execution(Plan, Installation_Report),
198+
append(Validation_Report, Installation_Report, Report)
199+
),
200+
delete_directory("scryer_libs/temp")
201+
) ; Report = Validation_Report
202+
),
203+
Report = Validation_Report
311204
).
312205

313206
% A logical plan to install the dependencies

0 commit comments

Comments
 (0)