comparison vext.sml @ 1732:76872ffc03a3 vext

Update Vext and lock file
author Chris Cannam
date Mon, 10 Jul 2017 13:46:20 +0100
parents e4352ff029cf
children 669bd699082d
comparison
equal deleted inserted replaced
1731:5185ee58c44b 1732:76872ffc03a3
887 case Json.parse (FileBits.file_contents filename) of 887 case Json.parse (FileBits.file_contents filename) of
888 Json.OK json => json 888 Json.OK json => json
889 | Json.ERROR e => raise Fail ("Failed to parse file: " ^ e) 889 | Json.ERROR e => raise Fail ("Failed to parse file: " ^ e)
890 890
891 fun save_json_to filename json = 891 fun save_json_to filename json =
892 (* using binary I/O to avoid ever writing CR/LF line endings *)
892 let val jstr = Json.serialiseIndented json 893 let val jstr = Json.serialiseIndented json
893 val stream = TextIO.openOut filename 894 val stream = BinIO.openOut filename
894 in 895 in
895 TextIO.output (stream, jstr); 896 BinIO.output (stream, Byte.stringToBytes jstr);
896 TextIO.closeOut stream 897 BinIO.closeOut stream
897 end 898 end
898 899
899 fun lookup_optional json kk = 900 fun lookup_optional json kk =
900 let fun lookup key = 901 let fun lookup key =
901 case json of 902 case json of
1433 | _ => raise Fail "Array expected for accounts", 1434 | _ => raise Fail "Array expected for accounts",
1434 providers = Provider.load_providers conf_json 1435 providers = Provider.load_providers conf_json
1435 } 1436 }
1436 end 1437 end
1437 1438
1438 fun load_project (userconfig : userconfig) rootpath use_locks : project = 1439 datatype pintype =
1440 NO_LOCKFILE |
1441 USE_LOCKFILE
1442
1443 fun load_project (userconfig : userconfig) rootpath pintype : project =
1439 let val spec_file = FileBits.project_spec_path rootpath 1444 let val spec_file = FileBits.project_spec_path rootpath
1440 val lock_file = FileBits.project_lock_path rootpath 1445 val lock_file = FileBits.project_lock_path rootpath
1441 val _ = if OS.FileSys.access (spec_file, [OS.FileSys.A_READ]) 1446 val _ = if OS.FileSys.access (spec_file, [OS.FileSys.A_READ])
1442 handle OS.SysErr _ => false 1447 handle OS.SysErr _ => false
1443 then () 1448 then ()
1445 (VextFilenames.project_file) ^ " in " ^ 1450 (VextFilenames.project_file) ^ " in " ^
1446 rootpath ^ 1451 rootpath ^
1447 ".\nPlease ensure the spec file is in the " ^ 1452 ".\nPlease ensure the spec file is in the " ^
1448 "project root and run this from there.") 1453 "project root and run this from there.")
1449 val spec_json = JsonBits.load_json_from spec_file 1454 val spec_json = JsonBits.load_json_from spec_file
1450 val lock_json = if use_locks 1455 val lock_json = if pintype = USE_LOCKFILE
1451 then JsonBits.load_json_from lock_file 1456 then JsonBits.load_json_from lock_file
1452 handle IO.Io _ => Json.OBJECT [] 1457 handle IO.Io _ => Json.OBJECT []
1453 else Json.OBJECT [] 1458 else Json.OBJECT []
1454 val extdir = JsonBits.lookup_mandatory_string spec_json 1459 val extdir = JsonBits.lookup_mandatory_string spec_json
1455 ["config", "extdir"] 1460 ["config", "extdir"]
1605 then save_lock_file (#rootpath context) locks 1610 then save_lock_file (#rootpath context) locks
1606 else (); 1611 else ();
1607 return_code 1612 return_code
1608 end 1613 end
1609 1614
1610 fun load_local_project use_locks = 1615 fun load_local_project pintype =
1611 let val userconfig = load_userconfig () 1616 let val userconfig = load_userconfig ()
1612 val rootpath = OS.FileSys.getDir () 1617 val rootpath = OS.FileSys.getDir ()
1613 in 1618 in
1614 load_project userconfig rootpath use_locks 1619 load_project userconfig rootpath pintype
1615 end 1620 end
1616 1621
1617 fun with_local_project use_locks f = 1622 fun with_local_project pintype f =
1618 let val return_code = f (load_local_project use_locks) 1623 let val return_code = f (load_local_project pintype)
1619 handle e => 1624 handle e =>
1620 (print ("Failed with exception: " ^ 1625 (print ("Failed with exception: " ^
1621 (exnMessage e) ^ "\n"); 1626 (exnMessage e) ^ "\n");
1622 OS.Process.failure) 1627 OS.Process.failure)
1623 val _ = print "\n"; 1628 val _ = print "\n";
1624 in 1629 in
1625 return_code 1630 return_code
1626 end 1631 end
1627 1632
1628 fun review () = with_local_project false review_project 1633 fun review () = with_local_project NO_LOCKFILE review_project
1629 fun status () = with_local_project false status_of_project 1634 fun status () = with_local_project NO_LOCKFILE status_of_project
1630 fun update () = with_local_project false update_project 1635 fun update () = with_local_project NO_LOCKFILE update_project
1631 fun install () = with_local_project true update_project 1636 fun install () = with_local_project USE_LOCKFILE update_project
1632 1637
1633 fun version () = 1638 fun version () =
1634 (print ("v" ^ vext_version ^ "\n"); 1639 (print ("v" ^ vext_version ^ "\n");
1635 OS.Process.success) 1640 OS.Process.success)
1636 1641