Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file common.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134(* This Source Code Form is subject to the terms of the Mozilla Public License,
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at http://mozilla.org/MPL/2.0/. *)typepoint_definition={offset:int;identifier:int;}(* Utility functions *)lettry_finallyxfh=letres=tryfxwithe->(tryhxwith_->());raiseein(tryhxwith_->());reslettry_in_channelbinxf=letopen_ch=ifbinthenopen_in_binelseopen_inintry_finally(open_chx)f(close_in_noerr)lettry_out_channelbinxf=letopen_ch=ifbinthenopen_out_binelseopen_outintry_finally(open_chx)f(close_out_noerr)(* I/O functions *)(* filename + reason *)exceptionInvalid_fileofstring*stringexceptionUnsupported_versionofstringexceptionModified_fileofstringletmagic_number_rtd=Bytes.of_string"BISECT-RTD"letsupported_versions=[2,0]letformat_version=(2,0)letwrite_channelchannelmagicwrite_digestx=output_byteschannelmagic;output_valuechannelformat_version;(matchwrite_digestwith|Somefile->output_valuechannel(Digest.filefile)|None->());output_valuechannelxletcheck_channelchannelfilenamemagiccheck_digest=letmagic_length=Bytes.lengthmagicinletfile_magic=Bytes.createmagic_lengthinbegintryreally_inputchannelfile_magic0magic_length;withEnd_of_file->raise(Invalid_file(filename,"unexpected end of file while reading magic number"))end;letfile_version=iffile_magic=magicthenletfile_version:(int*int)=input_valuechannelinifnot(List.memfile_versionsupported_versions)thenraise(Unsupported_versionfilename)elsefile_versionelseraise(Invalid_file(filename,"bad magic number"))in(matchcheck_digestwith|Somefile->letfile_digest:string=input_valuechannelinletdigest=Digest.filefileiniffile_digest<>digestthenraise(Modified_filefilename)|None->());file_versionletwrite_runtime_datachannelcontent=write_channelchannelmagic_number_rtdNone(Array.of_listcontent)letwrite_pointspoints=letpoints_array=Array.of_listpointsinArray.sortcomparepoints_array;Marshal.to_stringpoints_array[]letread_runtime_data'filename=try_in_channeltruefilename(funchannel->letversion=check_channelchannelfilenamemagic_number_rtdNoneinmatchversionwith|2,0->letfile_content:(string*(intarray*string))array=tryinput_valuechannelwithe->raise(Invalid_file(filename,"exception reading data: "^Printexc.to_stringe))inArray.to_listfile_content|_->assertfalse)letread_points's=letpoints_array:point_definitionarray=Marshal.from_strings0inArray.sortcomparepoints_array;Array.to_listpoints_array(* Simulate the old behavior for current ocveralls. This is quite fragile,
because it depends on two things:
- read_points is only called after all .out files are read with
read_runtime_data.
- There are no duplicate source file names anywhere in the project. This is
necessary because read_runtime_data finds unprefixed source file names,
while read_points receives file names with the -I option already
applied. *)letpoints:(string,point_definitionlist)Hashtbl.t=Hashtbl.create17letread_runtime_datafilename=letdata=read_runtime_data'filenameindata|>List.map(fun(source_file,(counts,file_points))->letbasename=Filename.basenamesource_fileinHashtbl.replacepointsbasename(read_points'file_points);source_file,counts)letread_pointsfilename=Hashtbl.findpoints(Filename.basenamefilename)