%path schematic and basic test

This commit is contained in:
Ted Blackman 2018-05-10 13:34:25 -07:00
parent 88ab046d88
commit b20193e067
2 changed files with 194 additions and 8 deletions

View File

@ -12,6 +12,7 @@
=- ((slog -) ~)
^- tang
;: weld
test-tear
test-is-schematic-live
test-date-from-schematic
test-unify-jugs
@ -57,8 +58,26 @@
test-cache-reclamation-live-promote
test-five-oh-cache-reclamation
test-reef
test-path
test-plan-direct-hoon
==
++ test-tear
~& %test-tear
::
;: welp
%- expect-eq !>
:- ~['a' 'bc' 'de']
(tear:ford-gate 'a-bc-de')
::
%- expect-eq !>
:- ~['abc']
(tear:ford-gate 'abc')
::
%- expect-eq !>
:- ~['ab/c']
(tear:ford-gate 'ab/c')
==
::
++ test-is-schematic-live
~& %test-is-schematic-live
::
@ -3055,6 +3074,43 @@
(expect-ford-empty ford ~nul)
==
::
++ test-path
~& %test-path
::
=/ ford *ford-gate
::
=/ scry-results=(map [term beam] (unit cage))
%- my :~
:- [%cx [[~nul %desk %da ~1234.5.6] /hoon/bar/foo/lib]]
`[%hoon !>(*hoon)]
::
:- [%cx [[~nul %desk %da ~1234.5.6] /hoon/foo-bar/lib]]
~
==
::
=^ results1 ford
%- test-ford-call :*
ford
now=~1234.5.6
scry=(scry-with-results-and-failures scry-results)
::
^= call-args
:* duct=~[/path] type=~ %make ~nul
%pin ~1234.5.6
[%path disc=[~nul %desk] prefix='lib' raw-path='foo-bar']
==
::
^= moves
:~ :* duct=~[/path] %give %made ~1234.5.6 %complete
%success %pin ~1234.5.6
%success %path [[~nul %desk] /hoon/bar/foo/lib]
== == ==
::
;: weld
results1
(expect-ford-empty ford ~nul)
==
::
++ test-plan-direct-hoon
~& %test-plan-direct-hoon
::

View File

@ -319,20 +319,21 @@
==
:: %path: resolve a path with `-`s to a path with `/`s
::
:: Resolve +file-path to a path containing a file, replacing
:: Resolve +raw-path to a path containing a file, replacing
:: any `-`s in the path with `/`s if no file exists at the
:: original path. Produces an error if multiple files match,
:: e.g. a/b/c and a/b-c, or a/b/c and a-b/c.
::
:: TODO verify current implementation
::
$: %path
:: disc the +disc within which to resolve :file-path
:: disc: the +disc forming the base of the path to be resolved
::
location=disc
:: file-path: the path to resolve
=disc
:: prefix: path prefix under which to resolve :raw-path, e.g. lib
::
file-path=@tas
prefix=@tas
:: raw-path: the file path to be resolved
::
raw-path=@tas
==
:: %plan: build a hoon program from a preprocessed source file
::
@ -979,6 +980,40 @@
--
=, format
|%
:: +tear: split a +term into segments delimited by `-`
::
++ tear
|= a=term
^- (list term)
:: sym-no-heps: a parser for terms with no heps and a leading letter
::
=/ sym-no-heps (cook crip ;~(plug low (star ;~(pose low nud))))
::
(fall (rush a (most hep sym-no-heps)) /[a])
:: +segments: TODO rename
::
++ segments
|= path-part=@tas
^- (list path)
::
=/ join |=([a=@tas b=@tas] (crip "{(trip a)}-{(trip b)}"))
::
=/ torn=(list @tas) (tear path-part)
::
|- ^- (list (list @tas))
::
?< ?=(~ torn)
::
?: ?=([@ ~] torn)
~[torn]
::
%- zing
%+ turn $(torn t.torn)
|= s=(list @tas)
^- (list (list @tas))
::
?> ?=(^ s)
~[[i.torn s] [(join i.torn i.s) t.s]]
:: +build-to-tape: convert :build to a printable format
::
++ build-to-tape
@ -2446,7 +2481,7 @@
%mash !!
%mute !!
%pact !!
%path !!
%path (path-impl [disc prefix raw-path]:schematic.build)
%plan (plan [source-path query-string scaffold]:schematic.build)
%reef reef
%ride (ride [formula subject]:schematic.build)
@ -2583,6 +2618,101 @@
[build [%build-result %error message] accessed-builds]
==
::
++ path-impl
|= [=disc prefix=@tas raw-path=@tas]
^- build-receipt
:: possible-spurs: flopped paths to which :raw-path could resolve
::
=/ possible-spurs=(list spur) (turn (segments raw-path) flop)
:: sub-builds: scry builds to check each path in :possible-paths
::
=/ sub-builds=(list ^build)
%+ turn possible-spurs
|= possible-spur=spur
^- ^build
:: full-spur: wrap :possible-spur with :prefix and /hoon suffix
::
=/ full-spur=spur :(welp /hoon possible-spur /[prefix])
::
[date.build [%scry %c %x `rail`[disc full-spur]]]
:: results: accumulator for results of sub-builds
::
=| results=(list [kid=^build result=(unit build-result)])
:: depend on all the sub-builds and collect their results
::
=/ subs-results
|- ^+ [results accessed-builds]
?~ sub-builds [results accessed-builds]
::
=/ kid=^build i.sub-builds
::
=^ result accessed-builds (depend-on kid)
=. results [[kid result] results]
::
$(sub-builds t.sub-builds)
:: apply mutations from depending on sub-builds
::
=: results -.subs-results
accessed-builds +.subs-results
==
:: split :results into completed :mades and incomplete :blocks
::
=+ split-results=(skid results |=([* r=(unit build-result)] ?=(^ r)))
::
=/ mades=_results -.split-results
=/ blocks=_results +.split-results
:: if any builds blocked, produce them all in %blocks
::
?^ blocks
[build [%blocks (turn `_results`blocks head) ~] accessed-builds]
:: matches: builds that completed with a successful result
::
=/ matches=_results
%+ skim mades
|= [* r=(unit build-result)]
::
?=([~ %success *] r)
:: if no matches, error out
::
?~ matches
=/ =beam
[[ship.disc desk.disc [%da date.build]] /hoon/[raw-path]/[prefix]]
::
=/ message=tang [%leaf "%path: no matches for {<(en-beam beam)>}"]~
::
[build [%build-result %error message] accessed-builds]
:: if exactly one path matches, succeed with the matching path
::
?: ?=([* ~] matches)
=* kid kid.i.matches
?> ?=(%scry -.schematic.kid)
::
:* build
[%build-result %success %path rail.resource.schematic.kid]
accessed-builds
==
:: multiple paths matched; error out
::
=/ message=tang
:- [%leaf "multiple matches for %path: "]
:: tmi; cast :matches back to +list
::
%+ roll `_results`matches
|= [[kid=^build result=(unit build-result)] message=tang]
^- tang
::
?> ?=(%scry -.schematic.kid)
:: beam: reconstruct request from :kid's schematic and date
::
=/ =beam
:* [ship.disc desk.disc [%da date.kid]]
spur.rail.resource.schematic.kid
==
::
[[%leaf "{<(en-beam beam)>}"] message]
::
[build [%build-result %error message] accessed-builds]
::
++ plan
|= [source-path=rail query-string=coin =scaffold]
^- build-receipt