Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file overlay_code.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223(* Yoann Padioleau
*
* Copyright (C) 2011 Facebook
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation, with the
* special exception on linking described in file license.txt.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file
* license.txt for more details.
*)openCommon(*****************************************************************************)(* Prelude *)(*****************************************************************************)(*
* Some code organizations are really bad. But because it's harder
* to convince people to change it, sometimes it's simpler to create
* a parallel organization, an "overlay" using simple symlinks
* that represent a better organization. One can then show
* statistics on those overlayed code organization, adapt layers,
* etc
*
* related: LFS on code.
*)(*****************************************************************************)(* Types *)(*****************************************************************************)typeoverlay={(* the filenames are in a readable path format *)orig_to_overlay:(Common.filename,Common.filename)Hashtbl.t;overlay_to_orig:(Common.filename,Common.filename)Hashtbl.t;data:(Common.filename(* overlay *)*Common.filename)list;(* in realpath format. This information is then specific
* to one user ... but infering back the root_orig/root_overlay
* from an arbitrary directory can be tedious.
*)root_orig:Common.dirname;root_overlay:Common.dirname;}(*****************************************************************************)(* IO *)(*****************************************************************************)letload_overlayfile=Common2.get_valuefileletsave_overlayoverlayfile=Common2.write_valueoverlayfile(*****************************************************************************)(* Check consistency *)(*****************************************************************************)letcheck_overlay~dir_orig~dir_overlay=letdir_orig=Common.fullpathdir_originletfiles=Common.files_of_dir_or_files_no_vcs_nofilter[dir_orig]+>Common.exclude(funfile->file=~".*/OVERLAY/.*")inletdir_overlay=Common.fullpathdir_overlayinletlinks=Common.cmd_to_list(spf"find %s -type l"dir_overlay)inletlinks=links+>Common.map_filter(funfile->trySome(Common.fullpathfile)withFailures->pr2s;None)inletfiles2=links+>List.map(funfile_or_dir->Common.files_of_dir_or_files_no_vcs_nofilter[file_or_dir])+>List.flatteninpr2(spf"#files orig = %d, #links overlay = %d, #files overlay = %d"(List.lengthfiles)(List.lengthlinks)(List.lengthfiles2));leth=Hashtbl.create101infiles2+>List.iter(funfile->ifHashtbl.memhfilethenpr2(spf"this one is a dupe: %s"file);Hashtbl.addhfiletrue;);let(_common,only_in_orig,only_in_overlay)=Common2.diff_set_efffilesfiles2inonly_in_orig+>List.iter(funl->pr2(spf"this one is missing: %s"l););only_in_overlay+>List.iter(funl->pr2(spf"this one is gone now: %s"l););ifnot(nullonly_in_orig&&nullonly_in_overlay)thenfailwith"Overlay is not OK"elsepr2"Overlay is OK"(*****************************************************************************)(* Generate equivalences *)(*****************************************************************************)letoverlay_equivalences~dir_orig~dir_overlay=letdir_overlay=Common.fullpathdir_overlayinletdir_orig=Common.fullpathdir_originletlinks=Common.cmd_to_list(spf"find %s -type l"dir_overlay)inletequiv=links+>List.map(funlink->letstat=Common2.unix_stat_efflinkinmatchstat.Unix.st_kindwith|Unix.S_DIR->let(children,_)=Common2.cmd_to_list_and_status(spf"cd %s; find * -type f"(link))inletdir=Common.fullpathlinkinchildren+>List.map(funchild->letoverlay=Filename.concatlinkchildinletorig=Filename.concatdirchildinoverlay,orig)|Unix.S_REG->[(link,Common.fullpathlink)]|_->[])+>List.flatteninletdata=equiv+>Common.map_filter(fun(overlay,orig)->trySome(Common.readable~root:dir_overlayoverlay,Common.readable~root:dir_origorig)withexn->pr2(spf"PB with %s, exn = %s"orig(Common.exn_to_sexn));None)in{data=data;overlay_to_orig=Common.hash_of_listdata;orig_to_overlay=Common.hash_of_list(data+>List.mapCommon2.swap);root_overlay=dir_overlay;root_orig=dir_orig;}letgen_overlay~dir_orig~dir_overlay~output=letequiv=overlay_equivalences~dir_orig~dir_overlayinequiv.data+>List.iterpr2_gen;save_overlayequivoutput(*****************************************************************************)(* Adapt layer *)(*****************************************************************************)letadapt_layerlayeroverlay={layerwithLayer_code.files=layer.Layer_code.files+>Common.map_filter(fun(file,info)->trySome(Hashtbl.findoverlay.orig_to_overlayfile,info)withNot_found->pr2(spf"PB could not find %s in overlay"file);None);}(* copy paste of the one in main_codemap.ml *)letlayers_in_dirdir=Common2.readdir_to_file_listdir+>Common.map_filter(funfile->iffile=~"layer.*marshall"thenSome(Filename.concatdirfile)elseNone)letadapt_layers~overlay~dir_layers_orig~dir_layers_overlay=letlayers=layers_in_dirdir_layers_originlayers+>List.iter(funlayer_filename->pr2(spf"processing %s"layer_filename);letlayer=Layer_code.load_layerlayer_filenameinletlayer'=adapt_layerlayeroverlayinLayer_code.save_layerlayer'(Filename.concatdir_layers_overlay(Common2.basenamelayer_filename)))(*****************************************************************************)(* Adapt database code *)(*****************************************************************************)letadapt_databasedboverlay={dbwithDatabase_code.files=db.Database_code.files+>Common.map_filter(fun(file,info)->trySome(Hashtbl.findoverlay.orig_to_overlayfile,info)withNot_found->pr2(spf"PB could not find %s in overlay"file);None);entities=db.Database_code.entities+>Array.map(fune->{ewithDatabase_code.e_file=try(Hashtbl.findoverlay.orig_to_overlaye.Database_code.e_file)withNot_found->"not_found_file_overlay";});}