setup.ml 172 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754
  1. (* setup.ml generated for the first time by OASIS v0.4.5 *)
  2. (* OASIS_START *)
  3. (* DO NOT EDIT (digest: 0acb29932d46fc4db1c79b9707c7a420) *)
  4. (*
  5. Regenerated by OASIS v0.4.4
  6. Visit http://oasis.forge.ocamlcore.org for more information and
  7. documentation about functions used in this file.
  8. *)
  9. module OASISGettext = struct
  10. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISGettext.ml" *)
  11. let ns_ str =
  12. str
  13. let s_ str =
  14. str
  15. let f_ (str: ('a, 'b, 'c, 'd) format4) =
  16. str
  17. let fn_ fmt1 fmt2 n =
  18. if n = 1 then
  19. fmt1^^""
  20. else
  21. fmt2^^""
  22. let init =
  23. []
  24. end
  25. module OASISContext = struct
  26. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISContext.ml" *)
  27. open OASISGettext
  28. type level =
  29. [ `Debug
  30. | `Info
  31. | `Warning
  32. | `Error]
  33. type t =
  34. {
  35. (* TODO: replace this by a proplist. *)
  36. quiet: bool;
  37. info: bool;
  38. debug: bool;
  39. ignore_plugins: bool;
  40. ignore_unknown_fields: bool;
  41. printf: level -> string -> unit;
  42. }
  43. let printf lvl str =
  44. let beg =
  45. match lvl with
  46. | `Error -> s_ "E: "
  47. | `Warning -> s_ "W: "
  48. | `Info -> s_ "I: "
  49. | `Debug -> s_ "D: "
  50. in
  51. prerr_endline (beg^str)
  52. let default =
  53. ref
  54. {
  55. quiet = false;
  56. info = false;
  57. debug = false;
  58. ignore_plugins = false;
  59. ignore_unknown_fields = false;
  60. printf = printf;
  61. }
  62. let quiet =
  63. {!default with quiet = true}
  64. let fspecs () =
  65. (* TODO: don't act on default. *)
  66. let ignore_plugins = ref false in
  67. ["-quiet",
  68. Arg.Unit (fun () -> default := {!default with quiet = true}),
  69. s_ " Run quietly";
  70. "-info",
  71. Arg.Unit (fun () -> default := {!default with info = true}),
  72. s_ " Display information message";
  73. "-debug",
  74. Arg.Unit (fun () -> default := {!default with debug = true}),
  75. s_ " Output debug message";
  76. "-ignore-plugins",
  77. Arg.Set ignore_plugins,
  78. s_ " Ignore plugin's field.";
  79. "-C",
  80. (* TODO: remove this chdir. *)
  81. Arg.String (fun str -> Sys.chdir str),
  82. s_ "dir Change directory before running."],
  83. fun () -> {!default with ignore_plugins = !ignore_plugins}
  84. end
  85. module OASISString = struct
  86. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISString.ml" *)
  87. (** Various string utilities.
  88. Mostly inspired by extlib and batteries ExtString and BatString libraries.
  89. @author Sylvain Le Gall
  90. *)
  91. let nsplitf str f =
  92. if str = "" then
  93. []
  94. else
  95. let buf = Buffer.create 13 in
  96. let lst = ref [] in
  97. let push () =
  98. lst := Buffer.contents buf :: !lst;
  99. Buffer.clear buf
  100. in
  101. let str_len = String.length str in
  102. for i = 0 to str_len - 1 do
  103. if f str.[i] then
  104. push ()
  105. else
  106. Buffer.add_char buf str.[i]
  107. done;
  108. push ();
  109. List.rev !lst
  110. (** [nsplit c s] Split the string [s] at char [c]. It doesn't include the
  111. separator.
  112. *)
  113. let nsplit str c =
  114. nsplitf str ((=) c)
  115. let find ~what ?(offset=0) str =
  116. let what_idx = ref 0 in
  117. let str_idx = ref offset in
  118. while !str_idx < String.length str &&
  119. !what_idx < String.length what do
  120. if str.[!str_idx] = what.[!what_idx] then
  121. incr what_idx
  122. else
  123. what_idx := 0;
  124. incr str_idx
  125. done;
  126. if !what_idx <> String.length what then
  127. raise Not_found
  128. else
  129. !str_idx - !what_idx
  130. let sub_start str len =
  131. let str_len = String.length str in
  132. if len >= str_len then
  133. ""
  134. else
  135. String.sub str len (str_len - len)
  136. let sub_end ?(offset=0) str len =
  137. let str_len = String.length str in
  138. if len >= str_len then
  139. ""
  140. else
  141. String.sub str 0 (str_len - len)
  142. let starts_with ~what ?(offset=0) str =
  143. let what_idx = ref 0 in
  144. let str_idx = ref offset in
  145. let ok = ref true in
  146. while !ok &&
  147. !str_idx < String.length str &&
  148. !what_idx < String.length what do
  149. if str.[!str_idx] = what.[!what_idx] then
  150. incr what_idx
  151. else
  152. ok := false;
  153. incr str_idx
  154. done;
  155. if !what_idx = String.length what then
  156. true
  157. else
  158. false
  159. let strip_starts_with ~what str =
  160. if starts_with ~what str then
  161. sub_start str (String.length what)
  162. else
  163. raise Not_found
  164. let ends_with ~what ?(offset=0) str =
  165. let what_idx = ref ((String.length what) - 1) in
  166. let str_idx = ref ((String.length str) - 1) in
  167. let ok = ref true in
  168. while !ok &&
  169. offset <= !str_idx &&
  170. 0 <= !what_idx do
  171. if str.[!str_idx] = what.[!what_idx] then
  172. decr what_idx
  173. else
  174. ok := false;
  175. decr str_idx
  176. done;
  177. if !what_idx = -1 then
  178. true
  179. else
  180. false
  181. let strip_ends_with ~what str =
  182. if ends_with ~what str then
  183. sub_end str (String.length what)
  184. else
  185. raise Not_found
  186. let replace_chars f s =
  187. let buf = String.make (String.length s) 'X' in
  188. for i = 0 to String.length s - 1 do
  189. buf.[i] <- f s.[i]
  190. done;
  191. buf
  192. end
  193. module OASISUtils = struct
  194. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISUtils.ml" *)
  195. open OASISGettext
  196. module MapExt =
  197. struct
  198. module type S =
  199. sig
  200. include Map.S
  201. val add_list: 'a t -> (key * 'a) list -> 'a t
  202. val of_list: (key * 'a) list -> 'a t
  203. val to_list: 'a t -> (key * 'a) list
  204. end
  205. module Make (Ord: Map.OrderedType) =
  206. struct
  207. include Map.Make(Ord)
  208. let rec add_list t =
  209. function
  210. | (k, v) :: tl -> add_list (add k v t) tl
  211. | [] -> t
  212. let of_list lst = add_list empty lst
  213. let to_list t = fold (fun k v acc -> (k, v) :: acc) t []
  214. end
  215. end
  216. module MapString = MapExt.Make(String)
  217. module SetExt =
  218. struct
  219. module type S =
  220. sig
  221. include Set.S
  222. val add_list: t -> elt list -> t
  223. val of_list: elt list -> t
  224. val to_list: t -> elt list
  225. end
  226. module Make (Ord: Set.OrderedType) =
  227. struct
  228. include Set.Make(Ord)
  229. let rec add_list t =
  230. function
  231. | e :: tl -> add_list (add e t) tl
  232. | [] -> t
  233. let of_list lst = add_list empty lst
  234. let to_list = elements
  235. end
  236. end
  237. module SetString = SetExt.Make(String)
  238. let compare_csl s1 s2 =
  239. String.compare (String.lowercase s1) (String.lowercase s2)
  240. module HashStringCsl =
  241. Hashtbl.Make
  242. (struct
  243. type t = string
  244. let equal s1 s2 =
  245. (String.lowercase s1) = (String.lowercase s2)
  246. let hash s =
  247. Hashtbl.hash (String.lowercase s)
  248. end)
  249. module SetStringCsl =
  250. SetExt.Make
  251. (struct
  252. type t = string
  253. let compare = compare_csl
  254. end)
  255. let varname_of_string ?(hyphen='_') s =
  256. if String.length s = 0 then
  257. begin
  258. invalid_arg "varname_of_string"
  259. end
  260. else
  261. begin
  262. let buf =
  263. OASISString.replace_chars
  264. (fun c ->
  265. if ('a' <= c && c <= 'z')
  266. ||
  267. ('A' <= c && c <= 'Z')
  268. ||
  269. ('0' <= c && c <= '9') then
  270. c
  271. else
  272. hyphen)
  273. s;
  274. in
  275. let buf =
  276. (* Start with a _ if digit *)
  277. if '0' <= s.[0] && s.[0] <= '9' then
  278. "_"^buf
  279. else
  280. buf
  281. in
  282. String.lowercase buf
  283. end
  284. let varname_concat ?(hyphen='_') p s =
  285. let what = String.make 1 hyphen in
  286. let p =
  287. try
  288. OASISString.strip_ends_with ~what p
  289. with Not_found ->
  290. p
  291. in
  292. let s =
  293. try
  294. OASISString.strip_starts_with ~what s
  295. with Not_found ->
  296. s
  297. in
  298. p^what^s
  299. let is_varname str =
  300. str = varname_of_string str
  301. let failwithf fmt = Printf.ksprintf failwith fmt
  302. end
  303. module PropList = struct
  304. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/PropList.ml" *)
  305. open OASISGettext
  306. type name = string
  307. exception Not_set of name * string option
  308. exception No_printer of name
  309. exception Unknown_field of name * name
  310. let () =
  311. Printexc.register_printer
  312. (function
  313. | Not_set (nm, Some rsn) ->
  314. Some
  315. (Printf.sprintf (f_ "Field '%s' is not set: %s") nm rsn)
  316. | Not_set (nm, None) ->
  317. Some
  318. (Printf.sprintf (f_ "Field '%s' is not set") nm)
  319. | No_printer nm ->
  320. Some
  321. (Printf.sprintf (f_ "No default printer for value %s") nm)
  322. | Unknown_field (nm, schm) ->
  323. Some
  324. (Printf.sprintf
  325. (f_ "Field %s is not defined in schema %s") nm schm)
  326. | _ ->
  327. None)
  328. module Data =
  329. struct
  330. type t =
  331. (name, unit -> unit) Hashtbl.t
  332. let create () =
  333. Hashtbl.create 13
  334. let clear t =
  335. Hashtbl.clear t
  336. (* # 78 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/PropList.ml" *)
  337. end
  338. module Schema =
  339. struct
  340. type ('ctxt, 'extra) value =
  341. {
  342. get: Data.t -> string;
  343. set: Data.t -> ?context:'ctxt -> string -> unit;
  344. help: (unit -> string) option;
  345. extra: 'extra;
  346. }
  347. type ('ctxt, 'extra) t =
  348. {
  349. name: name;
  350. fields: (name, ('ctxt, 'extra) value) Hashtbl.t;
  351. order: name Queue.t;
  352. name_norm: string -> string;
  353. }
  354. let create ?(case_insensitive=false) nm =
  355. {
  356. name = nm;
  357. fields = Hashtbl.create 13;
  358. order = Queue.create ();
  359. name_norm =
  360. (if case_insensitive then
  361. String.lowercase
  362. else
  363. fun s -> s);
  364. }
  365. let add t nm set get extra help =
  366. let key =
  367. t.name_norm nm
  368. in
  369. if Hashtbl.mem t.fields key then
  370. failwith
  371. (Printf.sprintf
  372. (f_ "Field '%s' is already defined in schema '%s'")
  373. nm t.name);
  374. Hashtbl.add
  375. t.fields
  376. key
  377. {
  378. set = set;
  379. get = get;
  380. help = help;
  381. extra = extra;
  382. };
  383. Queue.add nm t.order
  384. let mem t nm =
  385. Hashtbl.mem t.fields nm
  386. let find t nm =
  387. try
  388. Hashtbl.find t.fields (t.name_norm nm)
  389. with Not_found ->
  390. raise (Unknown_field (nm, t.name))
  391. let get t data nm =
  392. (find t nm).get data
  393. let set t data nm ?context x =
  394. (find t nm).set
  395. data
  396. ?context
  397. x
  398. let fold f acc t =
  399. Queue.fold
  400. (fun acc k ->
  401. let v =
  402. find t k
  403. in
  404. f acc k v.extra v.help)
  405. acc
  406. t.order
  407. let iter f t =
  408. fold
  409. (fun () -> f)
  410. ()
  411. t
  412. let name t =
  413. t.name
  414. end
  415. module Field =
  416. struct
  417. type ('ctxt, 'value, 'extra) t =
  418. {
  419. set: Data.t -> ?context:'ctxt -> 'value -> unit;
  420. get: Data.t -> 'value;
  421. sets: Data.t -> ?context:'ctxt -> string -> unit;
  422. gets: Data.t -> string;
  423. help: (unit -> string) option;
  424. extra: 'extra;
  425. }
  426. let new_id =
  427. let last_id =
  428. ref 0
  429. in
  430. fun () -> incr last_id; !last_id
  431. let create ?schema ?name ?parse ?print ?default ?update ?help extra =
  432. (* Default value container *)
  433. let v =
  434. ref None
  435. in
  436. (* If name is not given, create unique one *)
  437. let nm =
  438. match name with
  439. | Some s -> s
  440. | None -> Printf.sprintf "_anon_%d" (new_id ())
  441. in
  442. (* Last chance to get a value: the default *)
  443. let default () =
  444. match default with
  445. | Some d -> d
  446. | None -> raise (Not_set (nm, Some (s_ "no default value")))
  447. in
  448. (* Get data *)
  449. let get data =
  450. (* Get value *)
  451. try
  452. (Hashtbl.find data nm) ();
  453. match !v with
  454. | Some x -> x
  455. | None -> default ()
  456. with Not_found ->
  457. default ()
  458. in
  459. (* Set data *)
  460. let set data ?context x =
  461. let x =
  462. match update with
  463. | Some f ->
  464. begin
  465. try
  466. f ?context (get data) x
  467. with Not_set _ ->
  468. x
  469. end
  470. | None ->
  471. x
  472. in
  473. Hashtbl.replace
  474. data
  475. nm
  476. (fun () -> v := Some x)
  477. in
  478. (* Parse string value, if possible *)
  479. let parse =
  480. match parse with
  481. | Some f ->
  482. f
  483. | None ->
  484. fun ?context s ->
  485. failwith
  486. (Printf.sprintf
  487. (f_ "Cannot parse field '%s' when setting value %S")
  488. nm
  489. s)
  490. in
  491. (* Set data, from string *)
  492. let sets data ?context s =
  493. set ?context data (parse ?context s)
  494. in
  495. (* Output value as string, if possible *)
  496. let print =
  497. match print with
  498. | Some f ->
  499. f
  500. | None ->
  501. fun _ -> raise (No_printer nm)
  502. in
  503. (* Get data, as a string *)
  504. let gets data =
  505. print (get data)
  506. in
  507. begin
  508. match schema with
  509. | Some t ->
  510. Schema.add t nm sets gets extra help
  511. | None ->
  512. ()
  513. end;
  514. {
  515. set = set;
  516. get = get;
  517. sets = sets;
  518. gets = gets;
  519. help = help;
  520. extra = extra;
  521. }
  522. let fset data t ?context x =
  523. t.set data ?context x
  524. let fget data t =
  525. t.get data
  526. let fsets data t ?context s =
  527. t.sets data ?context s
  528. let fgets data t =
  529. t.gets data
  530. end
  531. module FieldRO =
  532. struct
  533. let create ?schema ?name ?parse ?print ?default ?update ?help extra =
  534. let fld =
  535. Field.create ?schema ?name ?parse ?print ?default ?update ?help extra
  536. in
  537. fun data -> Field.fget data fld
  538. end
  539. end
  540. module OASISMessage = struct
  541. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISMessage.ml" *)
  542. open OASISGettext
  543. open OASISContext
  544. let generic_message ~ctxt lvl fmt =
  545. let cond =
  546. if ctxt.quiet then
  547. false
  548. else
  549. match lvl with
  550. | `Debug -> ctxt.debug
  551. | `Info -> ctxt.info
  552. | _ -> true
  553. in
  554. Printf.ksprintf
  555. (fun str ->
  556. if cond then
  557. begin
  558. ctxt.printf lvl str
  559. end)
  560. fmt
  561. let debug ~ctxt fmt =
  562. generic_message ~ctxt `Debug fmt
  563. let info ~ctxt fmt =
  564. generic_message ~ctxt `Info fmt
  565. let warning ~ctxt fmt =
  566. generic_message ~ctxt `Warning fmt
  567. let error ~ctxt fmt =
  568. generic_message ~ctxt `Error fmt
  569. end
  570. module OASISVersion = struct
  571. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISVersion.ml" *)
  572. open OASISGettext
  573. type s = string
  574. type t = string
  575. type comparator =
  576. | VGreater of t
  577. | VGreaterEqual of t
  578. | VEqual of t
  579. | VLesser of t
  580. | VLesserEqual of t
  581. | VOr of comparator * comparator
  582. | VAnd of comparator * comparator
  583. (* Range of allowed characters *)
  584. let is_digit c =
  585. '0' <= c && c <= '9'
  586. let is_alpha c =
  587. ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')
  588. let is_special =
  589. function
  590. | '.' | '+' | '-' | '~' -> true
  591. | _ -> false
  592. let rec version_compare v1 v2 =
  593. if v1 <> "" || v2 <> "" then
  594. begin
  595. (* Compare ascii string, using special meaning for version
  596. * related char
  597. *)
  598. let val_ascii c =
  599. if c = '~' then -1
  600. else if is_digit c then 0
  601. else if c = '\000' then 0
  602. else if is_alpha c then Char.code c
  603. else (Char.code c) + 256
  604. in
  605. let len1 = String.length v1 in
  606. let len2 = String.length v2 in
  607. let p = ref 0 in
  608. (** Compare ascii part *)
  609. let compare_vascii () =
  610. let cmp = ref 0 in
  611. while !cmp = 0 &&
  612. !p < len1 && !p < len2 &&
  613. not (is_digit v1.[!p] && is_digit v2.[!p]) do
  614. cmp := (val_ascii v1.[!p]) - (val_ascii v2.[!p]);
  615. incr p
  616. done;
  617. if !cmp = 0 && !p < len1 && !p = len2 then
  618. val_ascii v1.[!p]
  619. else if !cmp = 0 && !p = len1 && !p < len2 then
  620. - (val_ascii v2.[!p])
  621. else
  622. !cmp
  623. in
  624. (** Compare digit part *)
  625. let compare_digit () =
  626. let extract_int v p =
  627. let start_p = !p in
  628. while !p < String.length v && is_digit v.[!p] do
  629. incr p
  630. done;
  631. let substr =
  632. String.sub v !p ((String.length v) - !p)
  633. in
  634. let res =
  635. match String.sub v start_p (!p - start_p) with
  636. | "" -> 0
  637. | s -> int_of_string s
  638. in
  639. res, substr
  640. in
  641. let i1, tl1 = extract_int v1 (ref !p) in
  642. let i2, tl2 = extract_int v2 (ref !p) in
  643. i1 - i2, tl1, tl2
  644. in
  645. match compare_vascii () with
  646. | 0 ->
  647. begin
  648. match compare_digit () with
  649. | 0, tl1, tl2 ->
  650. if tl1 <> "" && is_digit tl1.[0] then
  651. 1
  652. else if tl2 <> "" && is_digit tl2.[0] then
  653. -1
  654. else
  655. version_compare tl1 tl2
  656. | n, _, _ ->
  657. n
  658. end
  659. | n ->
  660. n
  661. end
  662. else
  663. begin
  664. 0
  665. end
  666. let version_of_string str = str
  667. let string_of_version t = t
  668. let version_compare_string s1 s2 =
  669. version_compare (version_of_string s1) (version_of_string s2)
  670. let chop t =
  671. try
  672. let pos =
  673. String.rindex t '.'
  674. in
  675. String.sub t 0 pos
  676. with Not_found ->
  677. t
  678. let rec comparator_apply v op =
  679. match op with
  680. | VGreater cv ->
  681. (version_compare v cv) > 0
  682. | VGreaterEqual cv ->
  683. (version_compare v cv) >= 0
  684. | VLesser cv ->
  685. (version_compare v cv) < 0
  686. | VLesserEqual cv ->
  687. (version_compare v cv) <= 0
  688. | VEqual cv ->
  689. (version_compare v cv) = 0
  690. | VOr (op1, op2) ->
  691. (comparator_apply v op1) || (comparator_apply v op2)
  692. | VAnd (op1, op2) ->
  693. (comparator_apply v op1) && (comparator_apply v op2)
  694. let rec string_of_comparator =
  695. function
  696. | VGreater v -> "> "^(string_of_version v)
  697. | VEqual v -> "= "^(string_of_version v)
  698. | VLesser v -> "< "^(string_of_version v)
  699. | VGreaterEqual v -> ">= "^(string_of_version v)
  700. | VLesserEqual v -> "<= "^(string_of_version v)
  701. | VOr (c1, c2) ->
  702. (string_of_comparator c1)^" || "^(string_of_comparator c2)
  703. | VAnd (c1, c2) ->
  704. (string_of_comparator c1)^" && "^(string_of_comparator c2)
  705. let rec varname_of_comparator =
  706. let concat p v =
  707. OASISUtils.varname_concat
  708. p
  709. (OASISUtils.varname_of_string
  710. (string_of_version v))
  711. in
  712. function
  713. | VGreater v -> concat "gt" v
  714. | VLesser v -> concat "lt" v
  715. | VEqual v -> concat "eq" v
  716. | VGreaterEqual v -> concat "ge" v
  717. | VLesserEqual v -> concat "le" v
  718. | VOr (c1, c2) ->
  719. (varname_of_comparator c1)^"_or_"^(varname_of_comparator c2)
  720. | VAnd (c1, c2) ->
  721. (varname_of_comparator c1)^"_and_"^(varname_of_comparator c2)
  722. let rec comparator_ge v' =
  723. let cmp v = version_compare v v' >= 0 in
  724. function
  725. | VEqual v
  726. | VGreaterEqual v
  727. | VGreater v -> cmp v
  728. | VLesserEqual _
  729. | VLesser _ -> false
  730. | VOr (c1, c2) -> comparator_ge v' c1 || comparator_ge v' c2
  731. | VAnd (c1, c2) -> comparator_ge v' c1 && comparator_ge v' c2
  732. end
  733. module OASISLicense = struct
  734. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISLicense.ml" *)
  735. (** License for _oasis fields
  736. @author Sylvain Le Gall
  737. *)
  738. type license = string
  739. type license_exception = string
  740. type license_version =
  741. | Version of OASISVersion.t
  742. | VersionOrLater of OASISVersion.t
  743. | NoVersion
  744. type license_dep_5_unit =
  745. {
  746. license: license;
  747. excption: license_exception option;
  748. version: license_version;
  749. }
  750. type license_dep_5 =
  751. | DEP5Unit of license_dep_5_unit
  752. | DEP5Or of license_dep_5 list
  753. | DEP5And of license_dep_5 list
  754. type t =
  755. | DEP5License of license_dep_5
  756. | OtherLicense of string (* URL *)
  757. end
  758. module OASISExpr = struct
  759. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISExpr.ml" *)
  760. open OASISGettext
  761. type test = string
  762. type flag = string
  763. type t =
  764. | EBool of bool
  765. | ENot of t
  766. | EAnd of t * t
  767. | EOr of t * t
  768. | EFlag of flag
  769. | ETest of test * string
  770. type 'a choices = (t * 'a) list
  771. let eval var_get t =
  772. let rec eval' =
  773. function
  774. | EBool b ->
  775. b
  776. | ENot e ->
  777. not (eval' e)
  778. | EAnd (e1, e2) ->
  779. (eval' e1) && (eval' e2)
  780. | EOr (e1, e2) ->
  781. (eval' e1) || (eval' e2)
  782. | EFlag nm ->
  783. let v =
  784. var_get nm
  785. in
  786. assert(v = "true" || v = "false");
  787. (v = "true")
  788. | ETest (nm, vl) ->
  789. let v =
  790. var_get nm
  791. in
  792. (v = vl)
  793. in
  794. eval' t
  795. let choose ?printer ?name var_get lst =
  796. let rec choose_aux =
  797. function
  798. | (cond, vl) :: tl ->
  799. if eval var_get cond then
  800. vl
  801. else
  802. choose_aux tl
  803. | [] ->
  804. let str_lst =
  805. if lst = [] then
  806. s_ "<empty>"
  807. else
  808. String.concat
  809. (s_ ", ")
  810. (List.map
  811. (fun (cond, vl) ->
  812. match printer with
  813. | Some p -> p vl
  814. | None -> s_ "<no printer>")
  815. lst)
  816. in
  817. match name with
  818. | Some nm ->
  819. failwith
  820. (Printf.sprintf
  821. (f_ "No result for the choice list '%s': %s")
  822. nm str_lst)
  823. | None ->
  824. failwith
  825. (Printf.sprintf
  826. (f_ "No result for a choice list: %s")
  827. str_lst)
  828. in
  829. choose_aux (List.rev lst)
  830. end
  831. module OASISText = struct
  832. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISText.ml" *)
  833. type elt =
  834. | Para of string
  835. | Verbatim of string
  836. | BlankLine
  837. type t = elt list
  838. end
  839. module OASISTypes = struct
  840. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISTypes.ml" *)
  841. type name = string
  842. type package_name = string
  843. type url = string
  844. type unix_dirname = string
  845. type unix_filename = string
  846. type host_dirname = string
  847. type host_filename = string
  848. type prog = string
  849. type arg = string
  850. type args = string list
  851. type command_line = (prog * arg list)
  852. type findlib_name = string
  853. type findlib_full = string
  854. type compiled_object =
  855. | Byte
  856. | Native
  857. | Best
  858. type dependency =
  859. | FindlibPackage of findlib_full * OASISVersion.comparator option
  860. | InternalLibrary of name
  861. type tool =
  862. | ExternalTool of name
  863. | InternalExecutable of name
  864. type vcs =
  865. | Darcs
  866. | Git
  867. | Svn
  868. | Cvs
  869. | Hg
  870. | Bzr
  871. | Arch
  872. | Monotone
  873. | OtherVCS of url
  874. type plugin_kind =
  875. [ `Configure
  876. | `Build
  877. | `Doc
  878. | `Test
  879. | `Install
  880. | `Extra
  881. ]
  882. type plugin_data_purpose =
  883. [ `Configure
  884. | `Build
  885. | `Install
  886. | `Clean
  887. | `Distclean
  888. | `Install
  889. | `Uninstall
  890. | `Test
  891. | `Doc
  892. | `Extra
  893. | `Other of string
  894. ]
  895. type 'a plugin = 'a * name * OASISVersion.t option
  896. type all_plugin = plugin_kind plugin
  897. type plugin_data = (all_plugin * plugin_data_purpose * (unit -> unit)) list
  898. (* # 115 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISTypes.ml" *)
  899. type 'a conditional = 'a OASISExpr.choices
  900. type custom =
  901. {
  902. pre_command: (command_line option) conditional;
  903. post_command: (command_line option) conditional;
  904. }
  905. type common_section =
  906. {
  907. cs_name: name;
  908. cs_data: PropList.Data.t;
  909. cs_plugin_data: plugin_data;
  910. }
  911. type build_section =
  912. {
  913. bs_build: bool conditional;
  914. bs_install: bool conditional;
  915. bs_path: unix_dirname;
  916. bs_compiled_object: compiled_object;
  917. bs_build_depends: dependency list;
  918. bs_build_tools: tool list;
  919. bs_c_sources: unix_filename list;
  920. bs_data_files: (unix_filename * unix_filename option) list;
  921. bs_ccopt: args conditional;
  922. bs_cclib: args conditional;
  923. bs_dlllib: args conditional;
  924. bs_dllpath: args conditional;
  925. bs_byteopt: args conditional;
  926. bs_nativeopt: args conditional;
  927. }
  928. type library =
  929. {
  930. lib_modules: string list;
  931. lib_pack: bool;
  932. lib_internal_modules: string list;
  933. lib_findlib_parent: findlib_name option;
  934. lib_findlib_name: findlib_name option;
  935. lib_findlib_containers: findlib_name list;
  936. }
  937. type object_ =
  938. {
  939. obj_modules: string list;
  940. obj_findlib_fullname: findlib_name list option;
  941. }
  942. type executable =
  943. {
  944. exec_custom: bool;
  945. exec_main_is: unix_filename;
  946. }
  947. type flag =
  948. {
  949. flag_description: string option;
  950. flag_default: bool conditional;
  951. }
  952. type source_repository =
  953. {
  954. src_repo_type: vcs;
  955. src_repo_location: url;
  956. src_repo_browser: url option;
  957. src_repo_module: string option;
  958. src_repo_branch: string option;
  959. src_repo_tag: string option;
  960. src_repo_subdir: unix_filename option;
  961. }
  962. type test =
  963. {
  964. test_type: [`Test] plugin;
  965. test_command: command_line conditional;
  966. test_custom: custom;
  967. test_working_directory: unix_filename option;
  968. test_run: bool conditional;
  969. test_tools: tool list;
  970. }
  971. type doc_format =
  972. | HTML of unix_filename
  973. | DocText
  974. | PDF
  975. | PostScript
  976. | Info of unix_filename
  977. | DVI
  978. | OtherDoc
  979. type doc =
  980. {
  981. doc_type: [`Doc] plugin;
  982. doc_custom: custom;
  983. doc_build: bool conditional;
  984. doc_install: bool conditional;
  985. doc_install_dir: unix_filename;
  986. doc_title: string;
  987. doc_authors: string list;
  988. doc_abstract: string option;
  989. doc_format: doc_format;
  990. doc_data_files: (unix_filename * unix_filename option) list;
  991. doc_build_tools: tool list;
  992. }
  993. type section =
  994. | Library of common_section * build_section * library
  995. | Object of common_section * build_section * object_
  996. | Executable of common_section * build_section * executable
  997. | Flag of common_section * flag
  998. | SrcRepo of common_section * source_repository
  999. | Test of common_section * test
  1000. | Doc of common_section * doc
  1001. type section_kind =
  1002. [ `Library | `Object | `Executable | `Flag | `SrcRepo | `Test | `Doc ]
  1003. type package =
  1004. {
  1005. oasis_version: OASISVersion.t;
  1006. ocaml_version: OASISVersion.comparator option;
  1007. findlib_version: OASISVersion.comparator option;
  1008. alpha_features: string list;
  1009. beta_features: string list;
  1010. name: package_name;
  1011. version: OASISVersion.t;
  1012. license: OASISLicense.t;
  1013. license_file: unix_filename option;
  1014. copyrights: string list;
  1015. maintainers: string list;
  1016. authors: string list;
  1017. homepage: url option;
  1018. synopsis: string;
  1019. description: OASISText.t option;
  1020. categories: url list;
  1021. conf_type: [`Configure] plugin;
  1022. conf_custom: custom;
  1023. build_type: [`Build] plugin;
  1024. build_custom: custom;
  1025. install_type: [`Install] plugin;
  1026. install_custom: custom;
  1027. uninstall_custom: custom;
  1028. clean_custom: custom;
  1029. distclean_custom: custom;
  1030. files_ab: unix_filename list;
  1031. sections: section list;
  1032. plugins: [`Extra] plugin list;
  1033. disable_oasis_section: unix_filename list;
  1034. schema_data: PropList.Data.t;
  1035. plugin_data: plugin_data;
  1036. }
  1037. end
  1038. module OASISFeatures = struct
  1039. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISFeatures.ml" *)
  1040. open OASISTypes
  1041. open OASISUtils
  1042. open OASISGettext
  1043. open OASISVersion
  1044. module MapPlugin =
  1045. Map.Make
  1046. (struct
  1047. type t = plugin_kind * name
  1048. let compare = Pervasives.compare
  1049. end)
  1050. module Data =
  1051. struct
  1052. type t =
  1053. {
  1054. oasis_version: OASISVersion.t;
  1055. plugin_versions: OASISVersion.t option MapPlugin.t;
  1056. alpha_features: string list;
  1057. beta_features: string list;
  1058. }
  1059. let create oasis_version alpha_features beta_features =
  1060. {
  1061. oasis_version = oasis_version;
  1062. plugin_versions = MapPlugin.empty;
  1063. alpha_features = alpha_features;
  1064. beta_features = beta_features
  1065. }
  1066. let of_package pkg =
  1067. create
  1068. pkg.OASISTypes.oasis_version
  1069. pkg.OASISTypes.alpha_features
  1070. pkg.OASISTypes.beta_features
  1071. let add_plugin (plugin_kind, plugin_name, plugin_version) t =
  1072. {t with
  1073. plugin_versions = MapPlugin.add
  1074. (plugin_kind, plugin_name)
  1075. plugin_version
  1076. t.plugin_versions}
  1077. let plugin_version plugin_kind plugin_name t =
  1078. MapPlugin.find (plugin_kind, plugin_name) t.plugin_versions
  1079. let to_string t =
  1080. Printf.sprintf
  1081. "oasis_version: %s; alpha_features: %s; beta_features: %s; \
  1082. plugins_version: %s"
  1083. (OASISVersion.string_of_version t.oasis_version)
  1084. (String.concat ", " t.alpha_features)
  1085. (String.concat ", " t.beta_features)
  1086. (String.concat ", "
  1087. (MapPlugin.fold
  1088. (fun (_, plg) ver_opt acc ->
  1089. (plg^
  1090. (match ver_opt with
  1091. | Some v ->
  1092. " "^(OASISVersion.string_of_version v)
  1093. | None -> ""))
  1094. :: acc)
  1095. t.plugin_versions []))
  1096. end
  1097. type origin =
  1098. | Field of string * string
  1099. | Section of string
  1100. | NoOrigin
  1101. type stage = Alpha | Beta
  1102. let string_of_stage =
  1103. function
  1104. | Alpha -> "alpha"
  1105. | Beta -> "beta"
  1106. let field_of_stage =
  1107. function
  1108. | Alpha -> "AlphaFeatures"
  1109. | Beta -> "BetaFeatures"
  1110. type publication = InDev of stage | SinceVersion of OASISVersion.t
  1111. type t =
  1112. {
  1113. name: string;
  1114. plugin: all_plugin option;
  1115. publication: publication;
  1116. description: unit -> string;
  1117. }
  1118. (* TODO: mutex protect this. *)
  1119. let all_features = Hashtbl.create 13
  1120. let since_version ver_str = SinceVersion (version_of_string ver_str)
  1121. let alpha = InDev Alpha
  1122. let beta = InDev Beta
  1123. let to_string t =
  1124. Printf.sprintf
  1125. "feature: %s; plugin: %s; publication: %s"
  1126. t.name
  1127. (match t.plugin with
  1128. | None -> "<none>"
  1129. | Some (_, nm, _) -> nm)
  1130. (match t.publication with
  1131. | InDev stage -> string_of_stage stage
  1132. | SinceVersion ver -> ">= "^(OASISVersion.string_of_version ver))
  1133. let data_check t data origin =
  1134. let no_message = "no message" in
  1135. let check_feature features stage =
  1136. let has_feature = List.mem t.name features in
  1137. if not has_feature then
  1138. match origin with
  1139. | Field (fld, where) ->
  1140. Some
  1141. (Printf.sprintf
  1142. (f_ "Field %s in %s is only available when feature %s \
  1143. is in field %s.")
  1144. fld where t.name (field_of_stage stage))
  1145. | Section sct ->
  1146. Some
  1147. (Printf.sprintf
  1148. (f_ "Section %s is only available when features %s \
  1149. is in field %s.")
  1150. sct t.name (field_of_stage stage))
  1151. | NoOrigin ->
  1152. Some no_message
  1153. else
  1154. None
  1155. in
  1156. let version_is_good ~min_version version fmt =
  1157. let version_is_good =
  1158. OASISVersion.comparator_apply
  1159. version (OASISVersion.VGreaterEqual min_version)
  1160. in
  1161. Printf.ksprintf
  1162. (fun str ->
  1163. if version_is_good then
  1164. None
  1165. else
  1166. Some str)
  1167. fmt
  1168. in
  1169. match origin, t.plugin, t.publication with
  1170. | _, _, InDev Alpha -> check_feature data.Data.alpha_features Alpha
  1171. | _, _, InDev Beta -> check_feature data.Data.beta_features Beta
  1172. | Field(fld, where), None, SinceVersion min_version ->
  1173. version_is_good ~min_version data.Data.oasis_version
  1174. (f_ "Field %s in %s is only valid since OASIS v%s, update \
  1175. OASISFormat field from '%s' to '%s' after checking \
  1176. OASIS changelog.")
  1177. fld where (string_of_version min_version)
  1178. (string_of_version data.Data.oasis_version)
  1179. (string_of_version min_version)
  1180. | Field(fld, where), Some(plugin_knd, plugin_name, _),
  1181. SinceVersion min_version ->
  1182. begin
  1183. try
  1184. let plugin_version_current =
  1185. try
  1186. match Data.plugin_version plugin_knd plugin_name data with
  1187. | Some ver -> ver
  1188. | None ->
  1189. failwithf
  1190. (f_ "Field %s in %s is only valid for the OASIS \
  1191. plugin %s since v%s, but no plugin version is \
  1192. defined in the _oasis file, change '%s' to \
  1193. '%s (%s)' in your _oasis file.")
  1194. fld where plugin_name (string_of_version min_version)
  1195. plugin_name
  1196. plugin_name (string_of_version min_version)
  1197. with Not_found ->
  1198. failwithf
  1199. (f_ "Field %s in %s is only valid when the OASIS plugin %s \
  1200. is defined.")
  1201. fld where plugin_name
  1202. in
  1203. version_is_good ~min_version plugin_version_current
  1204. (f_ "Field %s in %s is only valid for the OASIS plugin %s \
  1205. since v%s, update your plugin from '%s (%s)' to \
  1206. '%s (%s)' after checking the plugin's changelog.")
  1207. fld where plugin_name (string_of_version min_version)
  1208. plugin_name (string_of_version plugin_version_current)
  1209. plugin_name (string_of_version min_version)
  1210. with Failure msg ->
  1211. Some msg
  1212. end
  1213. | Section sct, None, SinceVersion min_version ->
  1214. version_is_good ~min_version data.Data.oasis_version
  1215. (f_ "Section %s is only valid for since OASIS v%s, update \
  1216. OASISFormat field from '%s' to '%s' after checking OASIS \
  1217. changelog.")
  1218. sct (string_of_version min_version)
  1219. (string_of_version data.Data.oasis_version)
  1220. (string_of_version min_version)
  1221. | Section sct, Some(plugin_knd, plugin_name, _),
  1222. SinceVersion min_version ->
  1223. begin
  1224. try
  1225. let plugin_version_current =
  1226. try
  1227. match Data.plugin_version plugin_knd plugin_name data with
  1228. | Some ver -> ver
  1229. | None ->
  1230. failwithf
  1231. (f_ "Section %s is only valid for the OASIS \
  1232. plugin %s since v%s, but no plugin version is \
  1233. defined in the _oasis file, change '%s' to \
  1234. '%s (%s)' in your _oasis file.")
  1235. sct plugin_name (string_of_version min_version)
  1236. plugin_name
  1237. plugin_name (string_of_version min_version)
  1238. with Not_found ->
  1239. failwithf
  1240. (f_ "Section %s is only valid when the OASIS plugin %s \
  1241. is defined.")
  1242. sct plugin_name
  1243. in
  1244. version_is_good ~min_version plugin_version_current
  1245. (f_ "Section %s is only valid for the OASIS plugin %s \
  1246. since v%s, update your plugin from '%s (%s)' to \
  1247. '%s (%s)' after checking the plugin's changelog.")
  1248. sct plugin_name (string_of_version min_version)
  1249. plugin_name (string_of_version plugin_version_current)
  1250. plugin_name (string_of_version min_version)
  1251. with Failure msg ->
  1252. Some msg
  1253. end
  1254. | NoOrigin, None, SinceVersion min_version ->
  1255. version_is_good ~min_version data.Data.oasis_version "%s" no_message
  1256. | NoOrigin, Some(plugin_knd, plugin_name, _), SinceVersion min_version ->
  1257. begin
  1258. try
  1259. let plugin_version_current =
  1260. match Data.plugin_version plugin_knd plugin_name data with
  1261. | Some ver -> ver
  1262. | None -> raise Not_found
  1263. in
  1264. version_is_good ~min_version plugin_version_current
  1265. "%s" no_message
  1266. with Not_found ->
  1267. Some no_message
  1268. end
  1269. let data_assert t data origin =
  1270. match data_check t data origin with
  1271. | None -> ()
  1272. | Some str -> failwith str
  1273. let data_test t data =
  1274. match data_check t data NoOrigin with
  1275. | None -> true
  1276. | Some str -> false
  1277. let package_test t pkg =
  1278. data_test t (Data.of_package pkg)
  1279. let create ?plugin name publication description =
  1280. let () =
  1281. if Hashtbl.mem all_features name then
  1282. failwithf "Feature '%s' is already declared." name
  1283. in
  1284. let t =
  1285. {
  1286. name = name;
  1287. plugin = plugin;
  1288. publication = publication;
  1289. description = description;
  1290. }
  1291. in
  1292. Hashtbl.add all_features name t;
  1293. t
  1294. let get_stage name =
  1295. try
  1296. (Hashtbl.find all_features name).publication
  1297. with Not_found ->
  1298. failwithf (f_ "Feature %s doesn't exist.") name
  1299. let list () =
  1300. Hashtbl.fold (fun _ v acc -> v :: acc) all_features []
  1301. (*
  1302. * Real flags.
  1303. *)
  1304. let features =
  1305. create "features_fields"
  1306. (since_version "0.4")
  1307. (fun () ->
  1308. s_ "Enable to experiment not yet official features.")
  1309. let flag_docs =
  1310. create "flag_docs"
  1311. (since_version "0.3")
  1312. (fun () ->
  1313. s_ "Building docs require '-docs' flag at configure.")
  1314. let flag_tests =
  1315. create "flag_tests"
  1316. (since_version "0.3")
  1317. (fun () ->
  1318. s_ "Running tests require '-tests' flag at configure.")
  1319. let pack =
  1320. create "pack"
  1321. (since_version "0.3")
  1322. (fun () ->
  1323. s_ "Allow to create packed library.")
  1324. let section_object =
  1325. create "section_object" beta
  1326. (fun () ->
  1327. s_ "Implement an object section.")
  1328. let dynrun_for_release =
  1329. create "dynrun_for_release" alpha
  1330. (fun () ->
  1331. s_ "Make '-setup-update dynamic' suitable for releasing project.")
  1332. let compiled_setup_ml =
  1333. create "compiled_setup_ml" alpha
  1334. (fun () ->
  1335. s_ "It compiles the setup.ml and speed-up actions done with it.")
  1336. let disable_oasis_section =
  1337. create "disable_oasis_section" alpha
  1338. (fun () ->
  1339. s_ "Allows the OASIS section comments and digest to be omitted in \
  1340. generated files.")
  1341. end
  1342. module OASISUnixPath = struct
  1343. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISUnixPath.ml" *)
  1344. type unix_filename = string
  1345. type unix_dirname = string
  1346. type host_filename = string
  1347. type host_dirname = string
  1348. let current_dir_name = "."
  1349. let parent_dir_name = ".."
  1350. let is_current_dir fn =
  1351. fn = current_dir_name || fn = ""
  1352. let concat f1 f2 =
  1353. if is_current_dir f1 then
  1354. f2
  1355. else
  1356. let f1' =
  1357. try OASISString.strip_ends_with ~what:"/" f1 with Not_found -> f1
  1358. in
  1359. f1'^"/"^f2
  1360. let make =
  1361. function
  1362. | hd :: tl ->
  1363. List.fold_left
  1364. (fun f p -> concat f p)
  1365. hd
  1366. tl
  1367. | [] ->
  1368. invalid_arg "OASISUnixPath.make"
  1369. let dirname f =
  1370. try
  1371. String.sub f 0 (String.rindex f '/')
  1372. with Not_found ->
  1373. current_dir_name
  1374. let basename f =
  1375. try
  1376. let pos_start =
  1377. (String.rindex f '/') + 1
  1378. in
  1379. String.sub f pos_start ((String.length f) - pos_start)
  1380. with Not_found ->
  1381. f
  1382. let chop_extension f =
  1383. try
  1384. let last_dot =
  1385. String.rindex f '.'
  1386. in
  1387. let sub =
  1388. String.sub f 0 last_dot
  1389. in
  1390. try
  1391. let last_slash =
  1392. String.rindex f '/'
  1393. in
  1394. if last_slash < last_dot then
  1395. sub
  1396. else
  1397. f
  1398. with Not_found ->
  1399. sub
  1400. with Not_found ->
  1401. f
  1402. let capitalize_file f =
  1403. let dir = dirname f in
  1404. let base = basename f in
  1405. concat dir (String.capitalize base)
  1406. let uncapitalize_file f =
  1407. let dir = dirname f in
  1408. let base = basename f in
  1409. concat dir (String.uncapitalize base)
  1410. end
  1411. module OASISHostPath = struct
  1412. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISHostPath.ml" *)
  1413. open Filename
  1414. module Unix = OASISUnixPath
  1415. let make =
  1416. function
  1417. | [] ->
  1418. invalid_arg "OASISHostPath.make"
  1419. | hd :: tl ->
  1420. List.fold_left Filename.concat hd tl
  1421. let of_unix ufn =
  1422. if Sys.os_type = "Unix" then
  1423. ufn
  1424. else
  1425. make
  1426. (List.map
  1427. (fun p ->
  1428. if p = Unix.current_dir_name then
  1429. current_dir_name
  1430. else if p = Unix.parent_dir_name then
  1431. parent_dir_name
  1432. else
  1433. p)
  1434. (OASISString.nsplit ufn '/'))
  1435. end
  1436. module OASISSection = struct
  1437. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISSection.ml" *)
  1438. open OASISTypes
  1439. let section_kind_common =
  1440. function
  1441. | Library (cs, _, _) ->
  1442. `Library, cs
  1443. | Object (cs, _, _) ->
  1444. `Object, cs
  1445. | Executable (cs, _, _) ->
  1446. `Executable, cs
  1447. | Flag (cs, _) ->
  1448. `Flag, cs
  1449. | SrcRepo (cs, _) ->
  1450. `SrcRepo, cs
  1451. | Test (cs, _) ->
  1452. `Test, cs
  1453. | Doc (cs, _) ->
  1454. `Doc, cs
  1455. let section_common sct =
  1456. snd (section_kind_common sct)
  1457. let section_common_set cs =
  1458. function
  1459. | Library (_, bs, lib) -> Library (cs, bs, lib)
  1460. | Object (_, bs, obj) -> Object (cs, bs, obj)
  1461. | Executable (_, bs, exec) -> Executable (cs, bs, exec)
  1462. | Flag (_, flg) -> Flag (cs, flg)
  1463. | SrcRepo (_, src_repo) -> SrcRepo (cs, src_repo)
  1464. | Test (_, tst) -> Test (cs, tst)
  1465. | Doc (_, doc) -> Doc (cs, doc)
  1466. (** Key used to identify section
  1467. *)
  1468. let section_id sct =
  1469. let k, cs =
  1470. section_kind_common sct
  1471. in
  1472. k, cs.cs_name
  1473. let string_of_section sct =
  1474. let k, nm =
  1475. section_id sct
  1476. in
  1477. (match k with
  1478. | `Library -> "library"
  1479. | `Object -> "object"
  1480. | `Executable -> "executable"
  1481. | `Flag -> "flag"
  1482. | `SrcRepo -> "src repository"
  1483. | `Test -> "test"
  1484. | `Doc -> "doc")
  1485. ^" "^nm
  1486. let section_find id scts =
  1487. List.find
  1488. (fun sct -> id = section_id sct)
  1489. scts
  1490. module CSection =
  1491. struct
  1492. type t = section
  1493. let id = section_id
  1494. let compare t1 t2 =
  1495. compare (id t1) (id t2)
  1496. let equal t1 t2 =
  1497. (id t1) = (id t2)
  1498. let hash t =
  1499. Hashtbl.hash (id t)
  1500. end
  1501. module MapSection = Map.Make(CSection)
  1502. module SetSection = Set.Make(CSection)
  1503. end
  1504. module OASISBuildSection = struct
  1505. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISBuildSection.ml" *)
  1506. end
  1507. module OASISExecutable = struct
  1508. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISExecutable.ml" *)
  1509. open OASISTypes
  1510. let unix_exec_is (cs, bs, exec) is_native ext_dll suffix_program =
  1511. let dir =
  1512. OASISUnixPath.concat
  1513. bs.bs_path
  1514. (OASISUnixPath.dirname exec.exec_main_is)
  1515. in
  1516. let is_native_exec =
  1517. match bs.bs_compiled_object with
  1518. | Native -> true
  1519. | Best -> is_native ()
  1520. | Byte -> false
  1521. in
  1522. OASISUnixPath.concat
  1523. dir
  1524. (cs.cs_name^(suffix_program ())),
  1525. if not is_native_exec &&
  1526. not exec.exec_custom &&
  1527. bs.bs_c_sources <> [] then
  1528. Some (dir^"/dll"^cs.cs_name^"_stubs"^(ext_dll ()))
  1529. else
  1530. None
  1531. end
  1532. module OASISLibrary = struct
  1533. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISLibrary.ml" *)
  1534. open OASISTypes
  1535. open OASISUtils
  1536. open OASISGettext
  1537. open OASISSection
  1538. (* Look for a module file, considering capitalization or not. *)
  1539. let find_module source_file_exists bs modul =
  1540. let possible_base_fn =
  1541. List.map
  1542. (OASISUnixPath.concat bs.bs_path)
  1543. [modul;
  1544. OASISUnixPath.uncapitalize_file modul;
  1545. OASISUnixPath.capitalize_file modul]
  1546. in
  1547. (* TODO: we should be able to be able to determine the source for every
  1548. * files. Hence we should introduce a Module(source: fn) for the fields
  1549. * Modules and InternalModules
  1550. *)
  1551. List.fold_left
  1552. (fun acc base_fn ->
  1553. match acc with
  1554. | `No_sources _ ->
  1555. begin
  1556. let file_found =
  1557. List.fold_left
  1558. (fun acc ext ->
  1559. if source_file_exists (base_fn^ext) then
  1560. (base_fn^ext) :: acc
  1561. else
  1562. acc)
  1563. []
  1564. [".ml"; ".mli"; ".mll"; ".mly"]
  1565. in
  1566. match file_found with
  1567. | [] ->
  1568. acc
  1569. | lst ->
  1570. `Sources (base_fn, lst)
  1571. end
  1572. | `Sources _ ->
  1573. acc)
  1574. (`No_sources possible_base_fn)
  1575. possible_base_fn
  1576. let source_unix_files ~ctxt (cs, bs, lib) source_file_exists =
  1577. List.fold_left
  1578. (fun acc modul ->
  1579. match find_module source_file_exists bs modul with
  1580. | `Sources (base_fn, lst) ->
  1581. (base_fn, lst) :: acc
  1582. | `No_sources _ ->
  1583. OASISMessage.warning
  1584. ~ctxt
  1585. (f_ "Cannot find source file matching \
  1586. module '%s' in library %s")
  1587. modul cs.cs_name;
  1588. acc)
  1589. []
  1590. (lib.lib_modules @ lib.lib_internal_modules)
  1591. let generated_unix_files
  1592. ~ctxt
  1593. ~is_native
  1594. ~has_native_dynlink
  1595. ~ext_lib
  1596. ~ext_dll
  1597. ~source_file_exists
  1598. (cs, bs, lib) =
  1599. let find_modules lst ext =
  1600. let find_module modul =
  1601. match find_module source_file_exists bs modul with
  1602. | `Sources (base_fn, [fn]) when ext <> "cmi"
  1603. && Filename.check_suffix fn ".mli" ->
  1604. None (* No implementation files for pure interface. *)
  1605. | `Sources (base_fn, _) ->
  1606. Some [base_fn]
  1607. | `No_sources lst ->
  1608. OASISMessage.warning
  1609. ~ctxt
  1610. (f_ "Cannot find source file matching \
  1611. module '%s' in library %s")
  1612. modul cs.cs_name;
  1613. Some lst
  1614. in
  1615. List.fold_left
  1616. (fun acc nm ->
  1617. match find_module nm with
  1618. | None -> acc
  1619. | Some base_fns ->
  1620. List.map (fun base_fn -> base_fn ^"."^ext) base_fns :: acc)
  1621. []
  1622. lst
  1623. in
  1624. (* The headers that should be compiled along *)
  1625. let headers =
  1626. if lib.lib_pack then
  1627. []
  1628. else
  1629. find_modules
  1630. lib.lib_modules
  1631. "cmi"
  1632. in
  1633. (* The .cmx that be compiled along *)
  1634. let cmxs =
  1635. let should_be_built =
  1636. match bs.bs_compiled_object with
  1637. | Native -> true
  1638. | Best -> is_native
  1639. | Byte -> false
  1640. in
  1641. if should_be_built then
  1642. if lib.lib_pack then
  1643. find_modules
  1644. [cs.cs_name]
  1645. "cmx"
  1646. else
  1647. find_modules
  1648. (lib.lib_modules @ lib.lib_internal_modules)
  1649. "cmx"
  1650. else
  1651. []
  1652. in
  1653. let acc_nopath =
  1654. []
  1655. in
  1656. (* Compute what libraries should be built *)
  1657. let acc_nopath =
  1658. (* Add the packed header file if required *)
  1659. let add_pack_header acc =
  1660. if lib.lib_pack then
  1661. [cs.cs_name^".cmi"] :: acc
  1662. else
  1663. acc
  1664. in
  1665. let byte acc =
  1666. add_pack_header ([cs.cs_name^".cma"] :: acc)
  1667. in
  1668. let native acc =
  1669. let acc =
  1670. add_pack_header
  1671. (if has_native_dynlink then
  1672. [cs.cs_name^".cmxs"] :: acc
  1673. else acc)
  1674. in
  1675. [cs.cs_name^".cmxa"] :: [cs.cs_name^ext_lib] :: acc
  1676. in
  1677. match bs.bs_compiled_object with
  1678. | Native ->
  1679. byte (native acc_nopath)
  1680. | Best when is_native ->
  1681. byte (native acc_nopath)
  1682. | Byte | Best ->
  1683. byte acc_nopath
  1684. in
  1685. (* Add C library to be built *)
  1686. let acc_nopath =
  1687. if bs.bs_c_sources <> [] then
  1688. begin
  1689. ["lib"^cs.cs_name^"_stubs"^ext_lib]
  1690. ::
  1691. ["dll"^cs.cs_name^"_stubs"^ext_dll]
  1692. ::
  1693. acc_nopath
  1694. end
  1695. else
  1696. acc_nopath
  1697. in
  1698. (* All the files generated *)
  1699. List.rev_append
  1700. (List.rev_map
  1701. (List.rev_map
  1702. (OASISUnixPath.concat bs.bs_path))
  1703. acc_nopath)
  1704. (headers @ cmxs)
  1705. end
  1706. module OASISObject = struct
  1707. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISObject.ml" *)
  1708. open OASISTypes
  1709. open OASISGettext
  1710. let source_unix_files ~ctxt (cs, bs, obj) source_file_exists =
  1711. List.fold_left
  1712. (fun acc modul ->
  1713. match OASISLibrary.find_module source_file_exists bs modul with
  1714. | `Sources (base_fn, lst) ->
  1715. (base_fn, lst) :: acc
  1716. | `No_sources _ ->
  1717. OASISMessage.warning
  1718. ~ctxt
  1719. (f_ "Cannot find source file matching \
  1720. module '%s' in object %s")
  1721. modul cs.cs_name;
  1722. acc)
  1723. []
  1724. obj.obj_modules
  1725. let generated_unix_files
  1726. ~ctxt
  1727. ~is_native
  1728. ~source_file_exists
  1729. (cs, bs, obj) =
  1730. let find_module ext modul =
  1731. match OASISLibrary.find_module source_file_exists bs modul with
  1732. | `Sources (base_fn, _) -> [base_fn ^ ext]
  1733. | `No_sources lst ->
  1734. OASISMessage.warning
  1735. ~ctxt
  1736. (f_ "Cannot find source file matching \
  1737. module '%s' in object %s")
  1738. modul cs.cs_name ;
  1739. lst
  1740. in
  1741. let header, byte, native, c_object, f =
  1742. match obj.obj_modules with
  1743. | [ m ] -> (find_module ".cmi" m,
  1744. find_module ".cmo" m,
  1745. find_module ".cmx" m,
  1746. find_module ".o" m,
  1747. fun x -> x)
  1748. | _ -> ([cs.cs_name ^ ".cmi"],
  1749. [cs.cs_name ^ ".cmo"],
  1750. [cs.cs_name ^ ".cmx"],
  1751. [cs.cs_name ^ ".o"],
  1752. OASISUnixPath.concat bs.bs_path)
  1753. in
  1754. List.map (List.map f) (
  1755. match bs.bs_compiled_object with
  1756. | Native ->
  1757. native :: c_object :: byte :: header :: []
  1758. | Best when is_native ->
  1759. native :: c_object :: byte :: header :: []
  1760. | Byte | Best ->
  1761. byte :: header :: [])
  1762. end
  1763. module OASISFindlib = struct
  1764. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISFindlib.ml" *)
  1765. open OASISTypes
  1766. open OASISUtils
  1767. open OASISGettext
  1768. open OASISSection
  1769. type library_name = name
  1770. type findlib_part_name = name
  1771. type 'a map_of_findlib_part_name = 'a OASISUtils.MapString.t
  1772. exception InternalLibraryNotFound of library_name
  1773. exception FindlibPackageNotFound of findlib_name
  1774. type group_t =
  1775. | Container of findlib_name * group_t list
  1776. | Package of (findlib_name *
  1777. common_section *
  1778. build_section *
  1779. [`Library of library | `Object of object_] *
  1780. group_t list)
  1781. type data = common_section *
  1782. build_section *
  1783. [`Library of library | `Object of object_]
  1784. type tree =
  1785. | Node of (data option) * (tree MapString.t)
  1786. | Leaf of data
  1787. let findlib_mapping pkg =
  1788. (* Map from library name to either full findlib name or parts + parent. *)
  1789. let fndlb_parts_of_lib_name =
  1790. let fndlb_parts cs lib =
  1791. let name =
  1792. match lib.lib_findlib_name with
  1793. | Some nm -> nm
  1794. | None -> cs.cs_name
  1795. in
  1796. let name =
  1797. String.concat "." (lib.lib_findlib_containers @ [name])
  1798. in
  1799. name
  1800. in
  1801. List.fold_left
  1802. (fun mp ->
  1803. function
  1804. | Library (cs, _, lib) ->
  1805. begin
  1806. let lib_name = cs.cs_name in
  1807. let fndlb_parts = fndlb_parts cs lib in
  1808. if MapString.mem lib_name mp then
  1809. failwithf
  1810. (f_ "The library name '%s' is used more than once.")
  1811. lib_name;
  1812. match lib.lib_findlib_parent with
  1813. | Some lib_name_parent ->
  1814. MapString.add
  1815. lib_name
  1816. (`Unsolved (lib_name_parent, fndlb_parts))
  1817. mp
  1818. | None ->
  1819. MapString.add
  1820. lib_name
  1821. (`Solved fndlb_parts)
  1822. mp
  1823. end
  1824. | Object (cs, _, obj) ->
  1825. begin
  1826. let obj_name = cs.cs_name in
  1827. if MapString.mem obj_name mp then
  1828. failwithf
  1829. (f_ "The object name '%s' is used more than once.")
  1830. obj_name;
  1831. let findlib_full_name = match obj.obj_findlib_fullname with
  1832. | Some ns -> String.concat "." ns
  1833. | None -> obj_name
  1834. in
  1835. MapString.add
  1836. obj_name
  1837. (`Solved findlib_full_name)
  1838. mp
  1839. end
  1840. | Executable _ | Test _ | Flag _ | SrcRepo _ | Doc _ ->
  1841. mp)
  1842. MapString.empty
  1843. pkg.sections
  1844. in
  1845. (* Solve the above graph to be only library name to full findlib name. *)
  1846. let fndlb_name_of_lib_name =
  1847. let rec solve visited mp lib_name lib_name_child =
  1848. if SetString.mem lib_name visited then
  1849. failwithf
  1850. (f_ "Library '%s' is involved in a cycle \
  1851. with regard to findlib naming.")
  1852. lib_name;
  1853. let visited = SetString.add lib_name visited in
  1854. try
  1855. match MapString.find lib_name mp with
  1856. | `Solved fndlb_nm ->
  1857. fndlb_nm, mp
  1858. | `Unsolved (lib_nm_parent, post_fndlb_nm) ->
  1859. let pre_fndlb_nm, mp =
  1860. solve visited mp lib_nm_parent lib_name
  1861. in
  1862. let fndlb_nm = pre_fndlb_nm^"."^post_fndlb_nm in
  1863. fndlb_nm, MapString.add lib_name (`Solved fndlb_nm) mp
  1864. with Not_found ->
  1865. failwithf
  1866. (f_ "Library '%s', which is defined as the findlib parent of \
  1867. library '%s', doesn't exist.")
  1868. lib_name lib_name_child
  1869. in
  1870. let mp =
  1871. MapString.fold
  1872. (fun lib_name status mp ->
  1873. match status with
  1874. | `Solved _ ->
  1875. (* Solved initialy, no need to go further *)
  1876. mp
  1877. | `Unsolved _ ->
  1878. let _, mp = solve SetString.empty mp lib_name "<none>" in
  1879. mp)
  1880. fndlb_parts_of_lib_name
  1881. fndlb_parts_of_lib_name
  1882. in
  1883. MapString.map
  1884. (function
  1885. | `Solved fndlb_nm -> fndlb_nm
  1886. | `Unsolved _ -> assert false)
  1887. mp
  1888. in
  1889. (* Convert an internal library name to a findlib name. *)
  1890. let findlib_name_of_library_name lib_nm =
  1891. try
  1892. MapString.find lib_nm fndlb_name_of_lib_name
  1893. with Not_found ->
  1894. raise (InternalLibraryNotFound lib_nm)
  1895. in
  1896. (* Add a library to the tree.
  1897. *)
  1898. let add sct mp =
  1899. let fndlb_fullname =
  1900. let cs, _, _ = sct in
  1901. let lib_name = cs.cs_name in
  1902. findlib_name_of_library_name lib_name
  1903. in
  1904. let rec add_children nm_lst (children: tree MapString.t) =
  1905. match nm_lst with
  1906. | (hd :: tl) ->
  1907. begin
  1908. let node =
  1909. try
  1910. add_node tl (MapString.find hd children)
  1911. with Not_found ->
  1912. (* New node *)
  1913. new_node tl
  1914. in
  1915. MapString.add hd node children
  1916. end
  1917. | [] ->
  1918. (* Should not have a nameless library. *)
  1919. assert false
  1920. and add_node tl node =
  1921. if tl = [] then
  1922. begin
  1923. match node with
  1924. | Node (None, children) ->
  1925. Node (Some sct, children)
  1926. | Leaf (cs', _, _) | Node (Some (cs', _, _), _) ->
  1927. (* TODO: allow to merge Package, i.e.
  1928. * archive(byte) = "foo.cma foo_init.cmo"
  1929. *)
  1930. let cs, _, _ = sct in
  1931. failwithf
  1932. (f_ "Library '%s' and '%s' have the same findlib name '%s'")
  1933. cs.cs_name cs'.cs_name fndlb_fullname
  1934. end
  1935. else
  1936. begin
  1937. match node with
  1938. | Leaf data ->
  1939. Node (Some data, add_children tl MapString.empty)
  1940. | Node (data_opt, children) ->
  1941. Node (data_opt, add_children tl children)
  1942. end
  1943. and new_node =
  1944. function
  1945. | [] ->
  1946. Leaf sct
  1947. | hd :: tl ->
  1948. Node (None, MapString.add hd (new_node tl) MapString.empty)
  1949. in
  1950. add_children (OASISString.nsplit fndlb_fullname '.') mp
  1951. in
  1952. let rec group_of_tree mp =
  1953. MapString.fold
  1954. (fun nm node acc ->
  1955. let cur =
  1956. match node with
  1957. | Node (Some (cs, bs, lib), children) ->
  1958. Package (nm, cs, bs, lib, group_of_tree children)
  1959. | Node (None, children) ->
  1960. Container (nm, group_of_tree children)
  1961. | Leaf (cs, bs, lib) ->
  1962. Package (nm, cs, bs, lib, [])
  1963. in
  1964. cur :: acc)
  1965. mp []
  1966. in
  1967. let group_mp =
  1968. List.fold_left
  1969. (fun mp ->
  1970. function
  1971. | Library (cs, bs, lib) ->
  1972. add (cs, bs, `Library lib) mp
  1973. | Object (cs, bs, obj) ->
  1974. add (cs, bs, `Object obj) mp
  1975. | _ ->
  1976. mp)
  1977. MapString.empty
  1978. pkg.sections
  1979. in
  1980. let groups =
  1981. group_of_tree group_mp
  1982. in
  1983. let library_name_of_findlib_name =
  1984. Lazy.lazy_from_fun
  1985. (fun () ->
  1986. (* Revert findlib_name_of_library_name. *)
  1987. MapString.fold
  1988. (fun k v mp -> MapString.add v k mp)
  1989. fndlb_name_of_lib_name
  1990. MapString.empty)
  1991. in
  1992. let library_name_of_findlib_name fndlb_nm =
  1993. try
  1994. MapString.find fndlb_nm (Lazy.force library_name_of_findlib_name)
  1995. with Not_found ->
  1996. raise (FindlibPackageNotFound fndlb_nm)
  1997. in
  1998. groups,
  1999. findlib_name_of_library_name,
  2000. library_name_of_findlib_name
  2001. let findlib_of_group =
  2002. function
  2003. | Container (fndlb_nm, _)
  2004. | Package (fndlb_nm, _, _, _, _) -> fndlb_nm
  2005. let root_of_group grp =
  2006. let rec root_lib_aux =
  2007. (* We do a DFS in the group. *)
  2008. function
  2009. | Container (_, children) ->
  2010. List.fold_left
  2011. (fun res grp ->
  2012. if res = None then
  2013. root_lib_aux grp
  2014. else
  2015. res)
  2016. None
  2017. children
  2018. | Package (_, cs, bs, lib, _) ->
  2019. Some (cs, bs, lib)
  2020. in
  2021. match root_lib_aux grp with
  2022. | Some res ->
  2023. res
  2024. | None ->
  2025. failwithf
  2026. (f_ "Unable to determine root library of findlib library '%s'")
  2027. (findlib_of_group grp)
  2028. end
  2029. module OASISFlag = struct
  2030. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISFlag.ml" *)
  2031. end
  2032. module OASISPackage = struct
  2033. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISPackage.ml" *)
  2034. end
  2035. module OASISSourceRepository = struct
  2036. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISSourceRepository.ml" *)
  2037. end
  2038. module OASISTest = struct
  2039. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISTest.ml" *)
  2040. end
  2041. module OASISDocument = struct
  2042. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISDocument.ml" *)
  2043. end
  2044. module OASISExec = struct
  2045. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISExec.ml" *)
  2046. open OASISGettext
  2047. open OASISUtils
  2048. open OASISMessage
  2049. (* TODO: I don't like this quote, it is there because $(rm) foo expands to
  2050. * 'rm -f' foo...
  2051. *)
  2052. let run ~ctxt ?f_exit_code ?(quote=true) cmd args =
  2053. let cmd =
  2054. if quote then
  2055. if Sys.os_type = "Win32" then
  2056. if String.contains cmd ' ' then
  2057. (* Double the 1st double quote... win32... sigh *)
  2058. "\""^(Filename.quote cmd)
  2059. else
  2060. cmd
  2061. else
  2062. Filename.quote cmd
  2063. else
  2064. cmd
  2065. in
  2066. let cmdline =
  2067. String.concat " " (cmd :: args)
  2068. in
  2069. info ~ctxt (f_ "Running command '%s'") cmdline;
  2070. match f_exit_code, Sys.command cmdline with
  2071. | None, 0 -> ()
  2072. | None, i ->
  2073. failwithf
  2074. (f_ "Command '%s' terminated with error code %d")
  2075. cmdline i
  2076. | Some f, i ->
  2077. f i
  2078. let run_read_output ~ctxt ?f_exit_code cmd args =
  2079. let fn =
  2080. Filename.temp_file "oasis-" ".txt"
  2081. in
  2082. try
  2083. begin
  2084. let () =
  2085. run ~ctxt ?f_exit_code cmd (args @ [">"; Filename.quote fn])
  2086. in
  2087. let chn =
  2088. open_in fn
  2089. in
  2090. let routput =
  2091. ref []
  2092. in
  2093. begin
  2094. try
  2095. while true do
  2096. routput := (input_line chn) :: !routput
  2097. done
  2098. with End_of_file ->
  2099. ()
  2100. end;
  2101. close_in chn;
  2102. Sys.remove fn;
  2103. List.rev !routput
  2104. end
  2105. with e ->
  2106. (try Sys.remove fn with _ -> ());
  2107. raise e
  2108. let run_read_one_line ~ctxt ?f_exit_code cmd args =
  2109. match run_read_output ~ctxt ?f_exit_code cmd args with
  2110. | [fst] ->
  2111. fst
  2112. | lst ->
  2113. failwithf
  2114. (f_ "Command return unexpected output %S")
  2115. (String.concat "\n" lst)
  2116. end
  2117. module OASISFileUtil = struct
  2118. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISFileUtil.ml" *)
  2119. open OASISGettext
  2120. let file_exists_case fn =
  2121. let dirname = Filename.dirname fn in
  2122. let basename = Filename.basename fn in
  2123. if Sys.file_exists dirname then
  2124. if basename = Filename.current_dir_name then
  2125. true
  2126. else
  2127. List.mem
  2128. basename
  2129. (Array.to_list (Sys.readdir dirname))
  2130. else
  2131. false
  2132. let find_file ?(case_sensitive=true) paths exts =
  2133. (* Cardinal product of two list *)
  2134. let ( * ) lst1 lst2 =
  2135. List.flatten
  2136. (List.map
  2137. (fun a ->
  2138. List.map
  2139. (fun b -> a, b)
  2140. lst2)
  2141. lst1)
  2142. in
  2143. let rec combined_paths lst =
  2144. match lst with
  2145. | p1 :: p2 :: tl ->
  2146. let acc =
  2147. (List.map
  2148. (fun (a, b) -> Filename.concat a b)
  2149. (p1 * p2))
  2150. in
  2151. combined_paths (acc :: tl)
  2152. | [e] ->
  2153. e
  2154. | [] ->
  2155. []
  2156. in
  2157. let alternatives =
  2158. List.map
  2159. (fun (p, e) ->
  2160. if String.length e > 0 && e.[0] <> '.' then
  2161. p ^ "." ^ e
  2162. else
  2163. p ^ e)
  2164. ((combined_paths paths) * exts)
  2165. in
  2166. List.find (fun file ->
  2167. (if case_sensitive then
  2168. file_exists_case file
  2169. else
  2170. Sys.file_exists file)
  2171. && not (Sys.is_directory file)
  2172. ) alternatives
  2173. let which ~ctxt prg =
  2174. let path_sep =
  2175. match Sys.os_type with
  2176. | "Win32" ->
  2177. ';'
  2178. | _ ->
  2179. ':'
  2180. in
  2181. let path_lst = OASISString.nsplit (Sys.getenv "PATH") path_sep in
  2182. let exec_ext =
  2183. match Sys.os_type with
  2184. | "Win32" ->
  2185. "" :: (OASISString.nsplit (Sys.getenv "PATHEXT") path_sep)
  2186. | _ ->
  2187. [""]
  2188. in
  2189. find_file ~case_sensitive:false [path_lst; [prg]] exec_ext
  2190. (**/**)
  2191. let rec fix_dir dn =
  2192. (* Windows hack because Sys.file_exists "src\\" = false when
  2193. * Sys.file_exists "src" = true
  2194. *)
  2195. let ln =
  2196. String.length dn
  2197. in
  2198. if Sys.os_type = "Win32" && ln > 0 && dn.[ln - 1] = '\\' then
  2199. fix_dir (String.sub dn 0 (ln - 1))
  2200. else
  2201. dn
  2202. let q = Filename.quote
  2203. (**/**)
  2204. let cp ~ctxt ?(recurse=false) src tgt =
  2205. if recurse then
  2206. match Sys.os_type with
  2207. | "Win32" ->
  2208. OASISExec.run ~ctxt
  2209. "xcopy" [q src; q tgt; "/E"]
  2210. | _ ->
  2211. OASISExec.run ~ctxt
  2212. "cp" ["-r"; q src; q tgt]
  2213. else
  2214. OASISExec.run ~ctxt
  2215. (match Sys.os_type with
  2216. | "Win32" -> "copy"
  2217. | _ -> "cp")
  2218. [q src; q tgt]
  2219. let mkdir ~ctxt tgt =
  2220. OASISExec.run ~ctxt
  2221. (match Sys.os_type with
  2222. | "Win32" -> "md"
  2223. | _ -> "mkdir")
  2224. [q tgt]
  2225. let rec mkdir_parent ~ctxt f tgt =
  2226. let tgt =
  2227. fix_dir tgt
  2228. in
  2229. if Sys.file_exists tgt then
  2230. begin
  2231. if not (Sys.is_directory tgt) then
  2232. OASISUtils.failwithf
  2233. (f_ "Cannot create directory '%s', a file of the same name already \
  2234. exists")
  2235. tgt
  2236. end
  2237. else
  2238. begin
  2239. mkdir_parent ~ctxt f (Filename.dirname tgt);
  2240. if not (Sys.file_exists tgt) then
  2241. begin
  2242. f tgt;
  2243. mkdir ~ctxt tgt
  2244. end
  2245. end
  2246. let rmdir ~ctxt tgt =
  2247. if Sys.readdir tgt = [||] then begin
  2248. match Sys.os_type with
  2249. | "Win32" ->
  2250. OASISExec.run ~ctxt "rd" [q tgt]
  2251. | _ ->
  2252. OASISExec.run ~ctxt "rm" ["-r"; q tgt]
  2253. end else begin
  2254. OASISMessage.error ~ctxt
  2255. (f_ "Cannot remove directory '%s': not empty.")
  2256. tgt
  2257. end
  2258. let glob ~ctxt fn =
  2259. let basename =
  2260. Filename.basename fn
  2261. in
  2262. if String.length basename >= 2 &&
  2263. basename.[0] = '*' &&
  2264. basename.[1] = '.' then
  2265. begin
  2266. let ext_len =
  2267. (String.length basename) - 2
  2268. in
  2269. let ext =
  2270. String.sub basename 2 ext_len
  2271. in
  2272. let dirname =
  2273. Filename.dirname fn
  2274. in
  2275. Array.fold_left
  2276. (fun acc fn ->
  2277. try
  2278. let fn_ext =
  2279. String.sub
  2280. fn
  2281. ((String.length fn) - ext_len)
  2282. ext_len
  2283. in
  2284. if fn_ext = ext then
  2285. (Filename.concat dirname fn) :: acc
  2286. else
  2287. acc
  2288. with Invalid_argument _ ->
  2289. acc)
  2290. []
  2291. (Sys.readdir dirname)
  2292. end
  2293. else
  2294. begin
  2295. if file_exists_case fn then
  2296. [fn]
  2297. else
  2298. []
  2299. end
  2300. end
  2301. # 2878 "setup.ml"
  2302. module BaseEnvLight = struct
  2303. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/base/BaseEnvLight.ml" *)
  2304. module MapString = Map.Make(String)
  2305. type t = string MapString.t
  2306. let default_filename =
  2307. Filename.concat
  2308. (Sys.getcwd ())
  2309. "setup.data"
  2310. let load ?(allow_empty=false) ?(filename=default_filename) () =
  2311. if Sys.file_exists filename then
  2312. begin
  2313. let chn =
  2314. open_in_bin filename
  2315. in
  2316. let st =
  2317. Stream.of_channel chn
  2318. in
  2319. let line =
  2320. ref 1
  2321. in
  2322. let st_line =
  2323. Stream.from
  2324. (fun _ ->
  2325. try
  2326. match Stream.next st with
  2327. | '\n' -> incr line; Some '\n'
  2328. | c -> Some c
  2329. with Stream.Failure -> None)
  2330. in
  2331. let lexer =
  2332. Genlex.make_lexer ["="] st_line
  2333. in
  2334. let rec read_file mp =
  2335. match Stream.npeek 3 lexer with
  2336. | [Genlex.Ident nm; Genlex.Kwd "="; Genlex.String value] ->
  2337. Stream.junk lexer;
  2338. Stream.junk lexer;
  2339. Stream.junk lexer;
  2340. read_file (MapString.add nm value mp)
  2341. | [] ->
  2342. mp
  2343. | _ ->
  2344. failwith
  2345. (Printf.sprintf
  2346. "Malformed data file '%s' line %d"
  2347. filename !line)
  2348. in
  2349. let mp =
  2350. read_file MapString.empty
  2351. in
  2352. close_in chn;
  2353. mp
  2354. end
  2355. else if allow_empty then
  2356. begin
  2357. MapString.empty
  2358. end
  2359. else
  2360. begin
  2361. failwith
  2362. (Printf.sprintf
  2363. "Unable to load environment, the file '%s' doesn't exist."
  2364. filename)
  2365. end
  2366. let rec var_expand str env =
  2367. let buff =
  2368. Buffer.create ((String.length str) * 2)
  2369. in
  2370. Buffer.add_substitute
  2371. buff
  2372. (fun var ->
  2373. try
  2374. var_expand (MapString.find var env) env
  2375. with Not_found ->
  2376. failwith
  2377. (Printf.sprintf
  2378. "No variable %s defined when trying to expand %S."
  2379. var
  2380. str))
  2381. str;
  2382. Buffer.contents buff
  2383. let var_get name env =
  2384. var_expand (MapString.find name env) env
  2385. let var_choose lst env =
  2386. OASISExpr.choose
  2387. (fun nm -> var_get nm env)
  2388. lst
  2389. end
  2390. # 2983 "setup.ml"
  2391. module BaseContext = struct
  2392. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/base/BaseContext.ml" *)
  2393. (* TODO: get rid of this module. *)
  2394. open OASISContext
  2395. let args () = fst (fspecs ())
  2396. let default = default
  2397. end
  2398. module BaseMessage = struct
  2399. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/base/BaseMessage.ml" *)
  2400. (** Message to user, overrid for Base
  2401. @author Sylvain Le Gall
  2402. *)
  2403. open OASISMessage
  2404. open BaseContext
  2405. let debug fmt = debug ~ctxt:!default fmt
  2406. let info fmt = info ~ctxt:!default fmt
  2407. let warning fmt = warning ~ctxt:!default fmt
  2408. let error fmt = error ~ctxt:!default fmt
  2409. end
  2410. module BaseEnv = struct
  2411. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/base/BaseEnv.ml" *)
  2412. open OASISGettext
  2413. open OASISUtils
  2414. open PropList
  2415. module MapString = BaseEnvLight.MapString
  2416. type origin_t =
  2417. | ODefault
  2418. | OGetEnv
  2419. | OFileLoad
  2420. | OCommandLine
  2421. type cli_handle_t =
  2422. | CLINone
  2423. | CLIAuto
  2424. | CLIWith
  2425. | CLIEnable
  2426. | CLIUser of (Arg.key * Arg.spec * Arg.doc) list
  2427. type definition_t =
  2428. {
  2429. hide: bool;
  2430. dump: bool;
  2431. cli: cli_handle_t;
  2432. arg_help: string option;
  2433. group: string option;
  2434. }
  2435. let schema =
  2436. Schema.create "environment"
  2437. (* Environment data *)
  2438. let env =
  2439. Data.create ()
  2440. (* Environment data from file *)
  2441. let env_from_file =
  2442. ref MapString.empty
  2443. (* Lexer for var *)
  2444. let var_lxr =
  2445. Genlex.make_lexer []
  2446. let rec var_expand str =
  2447. let buff =
  2448. Buffer.create ((String.length str) * 2)
  2449. in
  2450. Buffer.add_substitute
  2451. buff
  2452. (fun var ->
  2453. try
  2454. (* TODO: this is a quick hack to allow calling Test.Command
  2455. * without defining executable name really. I.e. if there is
  2456. * an exec Executable toto, then $(toto) should be replace
  2457. * by its real name. It is however useful to have this function
  2458. * for other variable that depend on the host and should be
  2459. * written better than that.
  2460. *)
  2461. let st =
  2462. var_lxr (Stream.of_string var)
  2463. in
  2464. match Stream.npeek 3 st with
  2465. | [Genlex.Ident "utoh"; Genlex.Ident nm] ->
  2466. OASISHostPath.of_unix (var_get nm)
  2467. | [Genlex.Ident "utoh"; Genlex.String s] ->
  2468. OASISHostPath.of_unix s
  2469. | [Genlex.Ident "ocaml_escaped"; Genlex.Ident nm] ->
  2470. String.escaped (var_get nm)
  2471. | [Genlex.Ident "ocaml_escaped"; Genlex.String s] ->
  2472. String.escaped s
  2473. | [Genlex.Ident nm] ->
  2474. var_get nm
  2475. | _ ->
  2476. failwithf
  2477. (f_ "Unknown expression '%s' in variable expansion of %s.")
  2478. var
  2479. str
  2480. with
  2481. | Unknown_field (_, _) ->
  2482. failwithf
  2483. (f_ "No variable %s defined when trying to expand %S.")
  2484. var
  2485. str
  2486. | Stream.Error e ->
  2487. failwithf
  2488. (f_ "Syntax error when parsing '%s' when trying to \
  2489. expand %S: %s")
  2490. var
  2491. str
  2492. e)
  2493. str;
  2494. Buffer.contents buff
  2495. and var_get name =
  2496. let vl =
  2497. try
  2498. Schema.get schema env name
  2499. with Unknown_field _ as e ->
  2500. begin
  2501. try
  2502. MapString.find name !env_from_file
  2503. with Not_found ->
  2504. raise e
  2505. end
  2506. in
  2507. var_expand vl
  2508. let var_choose ?printer ?name lst =
  2509. OASISExpr.choose
  2510. ?printer
  2511. ?name
  2512. var_get
  2513. lst
  2514. let var_protect vl =
  2515. let buff =
  2516. Buffer.create (String.length vl)
  2517. in
  2518. String.iter
  2519. (function
  2520. | '$' -> Buffer.add_string buff "\\$"
  2521. | c -> Buffer.add_char buff c)
  2522. vl;
  2523. Buffer.contents buff
  2524. let var_define
  2525. ?(hide=false)
  2526. ?(dump=true)
  2527. ?short_desc
  2528. ?(cli=CLINone)
  2529. ?arg_help
  2530. ?group
  2531. name (* TODO: type constraint on the fact that name must be a valid OCaml
  2532. id *)
  2533. dflt =
  2534. let default =
  2535. [
  2536. OFileLoad, (fun () -> MapString.find name !env_from_file);
  2537. ODefault, dflt;
  2538. OGetEnv, (fun () -> Sys.getenv name);
  2539. ]
  2540. in
  2541. let extra =
  2542. {
  2543. hide = hide;
  2544. dump = dump;
  2545. cli = cli;
  2546. arg_help = arg_help;
  2547. group = group;
  2548. }
  2549. in
  2550. (* Try to find a value that can be defined
  2551. *)
  2552. let var_get_low lst =
  2553. let errors, res =
  2554. List.fold_left
  2555. (fun (errors, res) (o, v) ->
  2556. if res = None then
  2557. begin
  2558. try
  2559. errors, Some (v ())
  2560. with
  2561. | Not_found ->
  2562. errors, res
  2563. | Failure rsn ->
  2564. (rsn :: errors), res
  2565. | e ->
  2566. (Printexc.to_string e) :: errors, res
  2567. end
  2568. else
  2569. errors, res)
  2570. ([], None)
  2571. (List.sort
  2572. (fun (o1, _) (o2, _) ->
  2573. Pervasives.compare o2 o1)
  2574. lst)
  2575. in
  2576. match res, errors with
  2577. | Some v, _ ->
  2578. v
  2579. | None, [] ->
  2580. raise (Not_set (name, None))
  2581. | None, lst ->
  2582. raise (Not_set (name, Some (String.concat (s_ ", ") lst)))
  2583. in
  2584. let help =
  2585. match short_desc with
  2586. | Some fs -> Some fs
  2587. | None -> None
  2588. in
  2589. let var_get_lst =
  2590. FieldRO.create
  2591. ~schema
  2592. ~name
  2593. ~parse:(fun ?(context=ODefault) s -> [context, fun () -> s])
  2594. ~print:var_get_low
  2595. ~default
  2596. ~update:(fun ?context x old_x -> x @ old_x)
  2597. ?help
  2598. extra
  2599. in
  2600. fun () ->
  2601. var_expand (var_get_low (var_get_lst env))
  2602. let var_redefine
  2603. ?hide
  2604. ?dump
  2605. ?short_desc
  2606. ?cli
  2607. ?arg_help
  2608. ?group
  2609. name
  2610. dflt =
  2611. if Schema.mem schema name then
  2612. begin
  2613. (* TODO: look suspsicious, we want to memorize dflt not dflt () *)
  2614. Schema.set schema env ~context:ODefault name (dflt ());
  2615. fun () -> var_get name
  2616. end
  2617. else
  2618. begin
  2619. var_define
  2620. ?hide
  2621. ?dump
  2622. ?short_desc
  2623. ?cli
  2624. ?arg_help
  2625. ?group
  2626. name
  2627. dflt
  2628. end
  2629. let var_ignore (e: unit -> string) = ()
  2630. let print_hidden =
  2631. var_define
  2632. ~hide:true
  2633. ~dump:false
  2634. ~cli:CLIAuto
  2635. ~arg_help:"Print even non-printable variable. (debug)"
  2636. "print_hidden"
  2637. (fun () -> "false")
  2638. let var_all () =
  2639. List.rev
  2640. (Schema.fold
  2641. (fun acc nm def _ ->
  2642. if not def.hide || bool_of_string (print_hidden ()) then
  2643. nm :: acc
  2644. else
  2645. acc)
  2646. []
  2647. schema)
  2648. let default_filename =
  2649. BaseEnvLight.default_filename
  2650. let load ?allow_empty ?filename () =
  2651. env_from_file := BaseEnvLight.load ?allow_empty ?filename ()
  2652. let unload () =
  2653. env_from_file := MapString.empty;
  2654. Data.clear env
  2655. let dump ?(filename=default_filename) () =
  2656. let chn =
  2657. open_out_bin filename
  2658. in
  2659. let output nm value =
  2660. Printf.fprintf chn "%s=%S\n" nm value
  2661. in
  2662. let mp_todo =
  2663. (* Dump data from schema *)
  2664. Schema.fold
  2665. (fun mp_todo nm def _ ->
  2666. if def.dump then
  2667. begin
  2668. try
  2669. let value =
  2670. Schema.get
  2671. schema
  2672. env
  2673. nm
  2674. in
  2675. output nm value
  2676. with Not_set _ ->
  2677. ()
  2678. end;
  2679. MapString.remove nm mp_todo)
  2680. !env_from_file
  2681. schema
  2682. in
  2683. (* Dump data defined outside of schema *)
  2684. MapString.iter output mp_todo;
  2685. (* End of the dump *)
  2686. close_out chn
  2687. let print () =
  2688. let printable_vars =
  2689. Schema.fold
  2690. (fun acc nm def short_descr_opt ->
  2691. if not def.hide || bool_of_string (print_hidden ()) then
  2692. begin
  2693. try
  2694. let value =
  2695. Schema.get
  2696. schema
  2697. env
  2698. nm
  2699. in
  2700. let txt =
  2701. match short_descr_opt with
  2702. | Some s -> s ()
  2703. | None -> nm
  2704. in
  2705. (txt, value) :: acc
  2706. with Not_set _ ->
  2707. acc
  2708. end
  2709. else
  2710. acc)
  2711. []
  2712. schema
  2713. in
  2714. let max_length =
  2715. List.fold_left max 0
  2716. (List.rev_map String.length
  2717. (List.rev_map fst printable_vars))
  2718. in
  2719. let dot_pad str =
  2720. String.make ((max_length - (String.length str)) + 3) '.'
  2721. in
  2722. Printf.printf "\nConfiguration: \n";
  2723. List.iter
  2724. (fun (name, value) ->
  2725. Printf.printf "%s: %s %s\n" name (dot_pad name) value)
  2726. (List.rev printable_vars);
  2727. Printf.printf "\n%!"
  2728. let args () =
  2729. let arg_concat =
  2730. OASISUtils.varname_concat ~hyphen:'-'
  2731. in
  2732. [
  2733. "--override",
  2734. Arg.Tuple
  2735. (
  2736. let rvr = ref ""
  2737. in
  2738. let rvl = ref ""
  2739. in
  2740. [
  2741. Arg.Set_string rvr;
  2742. Arg.Set_string rvl;
  2743. Arg.Unit
  2744. (fun () ->
  2745. Schema.set
  2746. schema
  2747. env
  2748. ~context:OCommandLine
  2749. !rvr
  2750. !rvl)
  2751. ]
  2752. ),
  2753. "var+val Override any configuration variable.";
  2754. ]
  2755. @
  2756. List.flatten
  2757. (Schema.fold
  2758. (fun acc name def short_descr_opt ->
  2759. let var_set s =
  2760. Schema.set
  2761. schema
  2762. env
  2763. ~context:OCommandLine
  2764. name
  2765. s
  2766. in
  2767. let arg_name =
  2768. OASISUtils.varname_of_string ~hyphen:'-' name
  2769. in
  2770. let hlp =
  2771. match short_descr_opt with
  2772. | Some txt -> txt ()
  2773. | None -> ""
  2774. in
  2775. let arg_hlp =
  2776. match def.arg_help with
  2777. | Some s -> s
  2778. | None -> "str"
  2779. in
  2780. let default_value =
  2781. try
  2782. Printf.sprintf
  2783. (f_ " [%s]")
  2784. (Schema.get
  2785. schema
  2786. env
  2787. name)
  2788. with Not_set _ ->
  2789. ""
  2790. in
  2791. let args =
  2792. match def.cli with
  2793. | CLINone ->
  2794. []
  2795. | CLIAuto ->
  2796. [
  2797. arg_concat "--" arg_name,
  2798. Arg.String var_set,
  2799. Printf.sprintf (f_ "%s %s%s") arg_hlp hlp default_value
  2800. ]
  2801. | CLIWith ->
  2802. [
  2803. arg_concat "--with-" arg_name,
  2804. Arg.String var_set,
  2805. Printf.sprintf (f_ "%s %s%s") arg_hlp hlp default_value
  2806. ]
  2807. | CLIEnable ->
  2808. let dflt =
  2809. if default_value = " [true]" then
  2810. s_ " [default: enabled]"
  2811. else
  2812. s_ " [default: disabled]"
  2813. in
  2814. [
  2815. arg_concat "--enable-" arg_name,
  2816. Arg.Unit (fun () -> var_set "true"),
  2817. Printf.sprintf (f_ " %s%s") hlp dflt;
  2818. arg_concat "--disable-" arg_name,
  2819. Arg.Unit (fun () -> var_set "false"),
  2820. Printf.sprintf (f_ " %s%s") hlp dflt
  2821. ]
  2822. | CLIUser lst ->
  2823. lst
  2824. in
  2825. args :: acc)
  2826. []
  2827. schema)
  2828. end
  2829. module BaseArgExt = struct
  2830. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/base/BaseArgExt.ml" *)
  2831. open OASISUtils
  2832. open OASISGettext
  2833. let parse argv args =
  2834. (* Simulate command line for Arg *)
  2835. let current =
  2836. ref 0
  2837. in
  2838. try
  2839. Arg.parse_argv
  2840. ~current:current
  2841. (Array.concat [[|"none"|]; argv])
  2842. (Arg.align args)
  2843. (failwithf (f_ "Don't know what to do with arguments: '%s'"))
  2844. (s_ "configure options:")
  2845. with
  2846. | Arg.Help txt ->
  2847. print_endline txt;
  2848. exit 0
  2849. | Arg.Bad txt ->
  2850. prerr_endline txt;
  2851. exit 1
  2852. end
  2853. module BaseCheck = struct
  2854. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/base/BaseCheck.ml" *)
  2855. open BaseEnv
  2856. open BaseMessage
  2857. open OASISUtils
  2858. open OASISGettext
  2859. let prog_best prg prg_lst =
  2860. var_redefine
  2861. prg
  2862. (fun () ->
  2863. let alternate =
  2864. List.fold_left
  2865. (fun res e ->
  2866. match res with
  2867. | Some _ ->
  2868. res
  2869. | None ->
  2870. try
  2871. Some (OASISFileUtil.which ~ctxt:!BaseContext.default e)
  2872. with Not_found ->
  2873. None)
  2874. None
  2875. prg_lst
  2876. in
  2877. match alternate with
  2878. | Some prg -> prg
  2879. | None -> raise Not_found)
  2880. let prog prg =
  2881. prog_best prg [prg]
  2882. let prog_opt prg =
  2883. prog_best prg [prg^".opt"; prg]
  2884. let ocamlfind =
  2885. prog "ocamlfind"
  2886. let version
  2887. var_prefix
  2888. cmp
  2889. fversion
  2890. () =
  2891. (* Really compare version provided *)
  2892. let var =
  2893. var_prefix^"_version_"^(OASISVersion.varname_of_comparator cmp)
  2894. in
  2895. var_redefine
  2896. ~hide:true
  2897. var
  2898. (fun () ->
  2899. let version_str =
  2900. match fversion () with
  2901. | "[Distributed with OCaml]" ->
  2902. begin
  2903. try
  2904. (var_get "ocaml_version")
  2905. with Not_found ->
  2906. warning
  2907. (f_ "Variable ocaml_version not defined, fallback \
  2908. to default");
  2909. Sys.ocaml_version
  2910. end
  2911. | res ->
  2912. res
  2913. in
  2914. let version =
  2915. OASISVersion.version_of_string version_str
  2916. in
  2917. if OASISVersion.comparator_apply version cmp then
  2918. version_str
  2919. else
  2920. failwithf
  2921. (f_ "Cannot satisfy version constraint on %s: %s (version: %s)")
  2922. var_prefix
  2923. (OASISVersion.string_of_comparator cmp)
  2924. version_str)
  2925. ()
  2926. let package_version pkg =
  2927. OASISExec.run_read_one_line ~ctxt:!BaseContext.default
  2928. (ocamlfind ())
  2929. ["query"; "-format"; "%v"; pkg]
  2930. let package ?version_comparator pkg () =
  2931. let var =
  2932. OASISUtils.varname_concat
  2933. "pkg_"
  2934. (OASISUtils.varname_of_string pkg)
  2935. in
  2936. let findlib_dir pkg =
  2937. let dir =
  2938. OASISExec.run_read_one_line ~ctxt:!BaseContext.default
  2939. (ocamlfind ())
  2940. ["query"; "-format"; "%d"; pkg]
  2941. in
  2942. if Sys.file_exists dir && Sys.is_directory dir then
  2943. dir
  2944. else
  2945. failwithf
  2946. (f_ "When looking for findlib package %s, \
  2947. directory %s return doesn't exist")
  2948. pkg dir
  2949. in
  2950. let vl =
  2951. var_redefine
  2952. var
  2953. (fun () -> findlib_dir pkg)
  2954. ()
  2955. in
  2956. (
  2957. match version_comparator with
  2958. | Some ver_cmp ->
  2959. ignore
  2960. (version
  2961. var
  2962. ver_cmp
  2963. (fun _ -> package_version pkg)
  2964. ())
  2965. | None ->
  2966. ()
  2967. );
  2968. vl
  2969. end
  2970. module BaseOCamlcConfig = struct
  2971. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/base/BaseOCamlcConfig.ml" *)
  2972. open BaseEnv
  2973. open OASISUtils
  2974. open OASISGettext
  2975. module SMap = Map.Make(String)
  2976. let ocamlc =
  2977. BaseCheck.prog_opt "ocamlc"
  2978. let ocamlc_config_map =
  2979. (* Map name to value for ocamlc -config output
  2980. (name ^": "^value)
  2981. *)
  2982. let rec split_field mp lst =
  2983. match lst with
  2984. | line :: tl ->
  2985. let mp =
  2986. try
  2987. let pos_semicolon =
  2988. String.index line ':'
  2989. in
  2990. if pos_semicolon > 1 then
  2991. (
  2992. let name =
  2993. String.sub line 0 pos_semicolon
  2994. in
  2995. let linelen =
  2996. String.length line
  2997. in
  2998. let value =
  2999. if linelen > pos_semicolon + 2 then
  3000. String.sub
  3001. line
  3002. (pos_semicolon + 2)
  3003. (linelen - pos_semicolon - 2)
  3004. else
  3005. ""
  3006. in
  3007. SMap.add name value mp
  3008. )
  3009. else
  3010. (
  3011. mp
  3012. )
  3013. with Not_found ->
  3014. (
  3015. mp
  3016. )
  3017. in
  3018. split_field mp tl
  3019. | [] ->
  3020. mp
  3021. in
  3022. let cache =
  3023. lazy
  3024. (var_protect
  3025. (Marshal.to_string
  3026. (split_field
  3027. SMap.empty
  3028. (OASISExec.run_read_output
  3029. ~ctxt:!BaseContext.default
  3030. (ocamlc ()) ["-config"]))
  3031. []))
  3032. in
  3033. var_redefine
  3034. "ocamlc_config_map"
  3035. ~hide:true
  3036. ~dump:false
  3037. (fun () ->
  3038. (* TODO: update if ocamlc change !!! *)
  3039. Lazy.force cache)
  3040. let var_define nm =
  3041. (* Extract data from ocamlc -config *)
  3042. let avlbl_config_get () =
  3043. Marshal.from_string
  3044. (ocamlc_config_map ())
  3045. 0
  3046. in
  3047. let chop_version_suffix s =
  3048. try
  3049. String.sub s 0 (String.index s '+')
  3050. with _ ->
  3051. s
  3052. in
  3053. let nm_config, value_config =
  3054. match nm with
  3055. | "ocaml_version" ->
  3056. "version", chop_version_suffix
  3057. | _ -> nm, (fun x -> x)
  3058. in
  3059. var_redefine
  3060. nm
  3061. (fun () ->
  3062. try
  3063. let map =
  3064. avlbl_config_get ()
  3065. in
  3066. let value =
  3067. SMap.find nm_config map
  3068. in
  3069. value_config value
  3070. with Not_found ->
  3071. failwithf
  3072. (f_ "Cannot find field '%s' in '%s -config' output")
  3073. nm
  3074. (ocamlc ()))
  3075. end
  3076. module BaseStandardVar = struct
  3077. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/base/BaseStandardVar.ml" *)
  3078. open OASISGettext
  3079. open OASISTypes
  3080. open OASISExpr
  3081. open BaseCheck
  3082. open BaseEnv
  3083. let ocamlfind = BaseCheck.ocamlfind
  3084. let ocamlc = BaseOCamlcConfig.ocamlc
  3085. let ocamlopt = prog_opt "ocamlopt"
  3086. let ocamlbuild = prog "ocamlbuild"
  3087. (**/**)
  3088. let rpkg =
  3089. ref None
  3090. let pkg_get () =
  3091. match !rpkg with
  3092. | Some pkg -> pkg
  3093. | None -> failwith (s_ "OASIS Package is not set")
  3094. let var_cond = ref []
  3095. let var_define_cond ~since_version f dflt =
  3096. let holder = ref (fun () -> dflt) in
  3097. let since_version =
  3098. OASISVersion.VGreaterEqual (OASISVersion.version_of_string since_version)
  3099. in
  3100. var_cond :=
  3101. (fun ver ->
  3102. if OASISVersion.comparator_apply ver since_version then
  3103. holder := f ()) :: !var_cond;
  3104. fun () -> !holder ()
  3105. (**/**)
  3106. let pkg_name =
  3107. var_define
  3108. ~short_desc:(fun () -> s_ "Package name")
  3109. "pkg_name"
  3110. (fun () -> (pkg_get ()).name)
  3111. let pkg_version =
  3112. var_define
  3113. ~short_desc:(fun () -> s_ "Package version")
  3114. "pkg_version"
  3115. (fun () ->
  3116. (OASISVersion.string_of_version (pkg_get ()).version))
  3117. let c = BaseOCamlcConfig.var_define
  3118. let os_type = c "os_type"
  3119. let system = c "system"
  3120. let architecture = c "architecture"
  3121. let ccomp_type = c "ccomp_type"
  3122. let ocaml_version = c "ocaml_version"
  3123. (* TODO: Check standard variable presence at runtime *)
  3124. let standard_library_default = c "standard_library_default"
  3125. let standard_library = c "standard_library"
  3126. let standard_runtime = c "standard_runtime"
  3127. let bytecomp_c_compiler = c "bytecomp_c_compiler"
  3128. let native_c_compiler = c "native_c_compiler"
  3129. let model = c "model"
  3130. let ext_obj = c "ext_obj"
  3131. let ext_asm = c "ext_asm"
  3132. let ext_lib = c "ext_lib"
  3133. let ext_dll = c "ext_dll"
  3134. let default_executable_name = c "default_executable_name"
  3135. let systhread_supported = c "systhread_supported"
  3136. let flexlink =
  3137. BaseCheck.prog "flexlink"
  3138. let flexdll_version =
  3139. var_define
  3140. ~short_desc:(fun () -> "FlexDLL version (Win32)")
  3141. "flexdll_version"
  3142. (fun () ->
  3143. let lst =
  3144. OASISExec.run_read_output ~ctxt:!BaseContext.default
  3145. (flexlink ()) ["-help"]
  3146. in
  3147. match lst with
  3148. | line :: _ ->
  3149. Scanf.sscanf line "FlexDLL version %s" (fun ver -> ver)
  3150. | [] ->
  3151. raise Not_found)
  3152. (**/**)
  3153. let p name hlp dflt =
  3154. var_define
  3155. ~short_desc:hlp
  3156. ~cli:CLIAuto
  3157. ~arg_help:"dir"
  3158. name
  3159. dflt
  3160. let (/) a b =
  3161. if os_type () = Sys.os_type then
  3162. Filename.concat a b
  3163. else if os_type () = "Unix" then
  3164. OASISUnixPath.concat a b
  3165. else
  3166. OASISUtils.failwithf (f_ "Cannot handle os_type %s filename concat")
  3167. (os_type ())
  3168. (**/**)
  3169. let prefix =
  3170. p "prefix"
  3171. (fun () -> s_ "Install architecture-independent files dir")
  3172. (fun () ->
  3173. match os_type () with
  3174. | "Win32" ->
  3175. let program_files =
  3176. Sys.getenv "PROGRAMFILES"
  3177. in
  3178. program_files/(pkg_name ())
  3179. | _ ->
  3180. "/usr/local")
  3181. let exec_prefix =
  3182. p "exec_prefix"
  3183. (fun () -> s_ "Install architecture-dependent files in dir")
  3184. (fun () -> "$prefix")
  3185. let bindir =
  3186. p "bindir"
  3187. (fun () -> s_ "User executables")
  3188. (fun () -> "$exec_prefix"/"bin")
  3189. let sbindir =
  3190. p "sbindir"
  3191. (fun () -> s_ "System admin executables")
  3192. (fun () -> "$exec_prefix"/"sbin")
  3193. let libexecdir =
  3194. p "libexecdir"
  3195. (fun () -> s_ "Program executables")
  3196. (fun () -> "$exec_prefix"/"libexec")
  3197. let sysconfdir =
  3198. p "sysconfdir"
  3199. (fun () -> s_ "Read-only single-machine data")
  3200. (fun () -> "$prefix"/"etc")
  3201. let sharedstatedir =
  3202. p "sharedstatedir"
  3203. (fun () -> s_ "Modifiable architecture-independent data")
  3204. (fun () -> "$prefix"/"com")
  3205. let localstatedir =
  3206. p "localstatedir"
  3207. (fun () -> s_ "Modifiable single-machine data")
  3208. (fun () -> "$prefix"/"var")
  3209. let libdir =
  3210. p "libdir"
  3211. (fun () -> s_ "Object code libraries")
  3212. (fun () -> "$exec_prefix"/"lib")
  3213. let datarootdir =
  3214. p "datarootdir"
  3215. (fun () -> s_ "Read-only arch-independent data root")
  3216. (fun () -> "$prefix"/"share")
  3217. let datadir =
  3218. p "datadir"
  3219. (fun () -> s_ "Read-only architecture-independent data")
  3220. (fun () -> "$datarootdir")
  3221. let infodir =
  3222. p "infodir"
  3223. (fun () -> s_ "Info documentation")
  3224. (fun () -> "$datarootdir"/"info")
  3225. let localedir =
  3226. p "localedir"
  3227. (fun () -> s_ "Locale-dependent data")
  3228. (fun () -> "$datarootdir"/"locale")
  3229. let mandir =
  3230. p "mandir"
  3231. (fun () -> s_ "Man documentation")
  3232. (fun () -> "$datarootdir"/"man")
  3233. let docdir =
  3234. p "docdir"
  3235. (fun () -> s_ "Documentation root")
  3236. (fun () -> "$datarootdir"/"doc"/"$pkg_name")
  3237. let htmldir =
  3238. p "htmldir"
  3239. (fun () -> s_ "HTML documentation")
  3240. (fun () -> "$docdir")
  3241. let dvidir =
  3242. p "dvidir"
  3243. (fun () -> s_ "DVI documentation")
  3244. (fun () -> "$docdir")
  3245. let pdfdir =
  3246. p "pdfdir"
  3247. (fun () -> s_ "PDF documentation")
  3248. (fun () -> "$docdir")
  3249. let psdir =
  3250. p "psdir"
  3251. (fun () -> s_ "PS documentation")
  3252. (fun () -> "$docdir")
  3253. let destdir =
  3254. p "destdir"
  3255. (fun () -> s_ "Prepend a path when installing package")
  3256. (fun () ->
  3257. raise
  3258. (PropList.Not_set
  3259. ("destdir",
  3260. Some (s_ "undefined by construct"))))
  3261. let findlib_version =
  3262. var_define
  3263. "findlib_version"
  3264. (fun () ->
  3265. BaseCheck.package_version "findlib")
  3266. let is_native =
  3267. var_define
  3268. "is_native"
  3269. (fun () ->
  3270. try
  3271. let _s: string =
  3272. ocamlopt ()
  3273. in
  3274. "true"
  3275. with PropList.Not_set _ ->
  3276. let _s: string =
  3277. ocamlc ()
  3278. in
  3279. "false")
  3280. let ext_program =
  3281. var_define
  3282. "suffix_program"
  3283. (fun () ->
  3284. match os_type () with
  3285. | "Win32" | "Cygwin" -> ".exe"
  3286. | _ -> "")
  3287. let rm =
  3288. var_define
  3289. ~short_desc:(fun () -> s_ "Remove a file.")
  3290. "rm"
  3291. (fun () ->
  3292. match os_type () with
  3293. | "Win32" -> "del"
  3294. | _ -> "rm -f")
  3295. let rmdir =
  3296. var_define
  3297. ~short_desc:(fun () -> s_ "Remove a directory.")
  3298. "rmdir"
  3299. (fun () ->
  3300. match os_type () with
  3301. | "Win32" -> "rd"
  3302. | _ -> "rm -rf")
  3303. let debug =
  3304. var_define
  3305. ~short_desc:(fun () -> s_ "Turn ocaml debug flag on")
  3306. ~cli:CLIEnable
  3307. "debug"
  3308. (fun () -> "true")
  3309. let profile =
  3310. var_define
  3311. ~short_desc:(fun () -> s_ "Turn ocaml profile flag on")
  3312. ~cli:CLIEnable
  3313. "profile"
  3314. (fun () -> "false")
  3315. let tests =
  3316. var_define_cond ~since_version:"0.3"
  3317. (fun () ->
  3318. var_define
  3319. ~short_desc:(fun () ->
  3320. s_ "Compile tests executable and library and run them")
  3321. ~cli:CLIEnable
  3322. "tests"
  3323. (fun () -> "false"))
  3324. "true"
  3325. let docs =
  3326. var_define_cond ~since_version:"0.3"
  3327. (fun () ->
  3328. var_define
  3329. ~short_desc:(fun () -> s_ "Create documentations")
  3330. ~cli:CLIEnable
  3331. "docs"
  3332. (fun () -> "true"))
  3333. "true"
  3334. let native_dynlink =
  3335. var_define
  3336. ~short_desc:(fun () -> s_ "Compiler support generation of .cmxs.")
  3337. ~cli:CLINone
  3338. "native_dynlink"
  3339. (fun () ->
  3340. let res =
  3341. let ocaml_lt_312 () =
  3342. OASISVersion.comparator_apply
  3343. (OASISVersion.version_of_string (ocaml_version ()))
  3344. (OASISVersion.VLesser
  3345. (OASISVersion.version_of_string "3.12.0"))
  3346. in
  3347. let flexdll_lt_030 () =
  3348. OASISVersion.comparator_apply
  3349. (OASISVersion.version_of_string (flexdll_version ()))
  3350. (OASISVersion.VLesser
  3351. (OASISVersion.version_of_string "0.30"))
  3352. in
  3353. let has_native_dynlink =
  3354. let ocamlfind = ocamlfind () in
  3355. try
  3356. let fn =
  3357. OASISExec.run_read_one_line
  3358. ~ctxt:!BaseContext.default
  3359. ocamlfind
  3360. ["query"; "-predicates"; "native"; "dynlink";
  3361. "-format"; "%d/%a"]
  3362. in
  3363. Sys.file_exists fn
  3364. with _ ->
  3365. false
  3366. in
  3367. if not has_native_dynlink then
  3368. false
  3369. else if ocaml_lt_312 () then
  3370. false
  3371. else if (os_type () = "Win32" || os_type () = "Cygwin")
  3372. && flexdll_lt_030 () then
  3373. begin
  3374. BaseMessage.warning
  3375. (f_ ".cmxs generation disabled because FlexDLL needs to be \
  3376. at least 0.30. Please upgrade FlexDLL from %s to 0.30.")
  3377. (flexdll_version ());
  3378. false
  3379. end
  3380. else
  3381. true
  3382. in
  3383. string_of_bool res)
  3384. let init pkg =
  3385. rpkg := Some pkg;
  3386. List.iter (fun f -> f pkg.oasis_version) !var_cond
  3387. end
  3388. module BaseFileAB = struct
  3389. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/base/BaseFileAB.ml" *)
  3390. open BaseEnv
  3391. open OASISGettext
  3392. open BaseMessage
  3393. let to_filename fn =
  3394. let fn =
  3395. OASISHostPath.of_unix fn
  3396. in
  3397. if not (Filename.check_suffix fn ".ab") then
  3398. warning
  3399. (f_ "File '%s' doesn't have '.ab' extension")
  3400. fn;
  3401. Filename.chop_extension fn
  3402. let replace fn_lst =
  3403. let buff =
  3404. Buffer.create 13
  3405. in
  3406. List.iter
  3407. (fun fn ->
  3408. let fn =
  3409. OASISHostPath.of_unix fn
  3410. in
  3411. let chn_in =
  3412. open_in fn
  3413. in
  3414. let chn_out =
  3415. open_out (to_filename fn)
  3416. in
  3417. (
  3418. try
  3419. while true do
  3420. Buffer.add_string buff (var_expand (input_line chn_in));
  3421. Buffer.add_char buff '\n'
  3422. done
  3423. with End_of_file ->
  3424. ()
  3425. );
  3426. Buffer.output_buffer chn_out buff;
  3427. Buffer.clear buff;
  3428. close_in chn_in;
  3429. close_out chn_out)
  3430. fn_lst
  3431. end
  3432. module BaseLog = struct
  3433. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/base/BaseLog.ml" *)
  3434. open OASISUtils
  3435. let default_filename =
  3436. Filename.concat
  3437. (Filename.dirname BaseEnv.default_filename)
  3438. "setup.log"
  3439. module SetTupleString =
  3440. Set.Make
  3441. (struct
  3442. type t = string * string
  3443. let compare (s11, s12) (s21, s22) =
  3444. match String.compare s11 s21 with
  3445. | 0 -> String.compare s12 s22
  3446. | n -> n
  3447. end)
  3448. let load () =
  3449. if Sys.file_exists default_filename then
  3450. begin
  3451. let chn =
  3452. open_in default_filename
  3453. in
  3454. let scbuf =
  3455. Scanf.Scanning.from_file default_filename
  3456. in
  3457. let rec read_aux (st, lst) =
  3458. if not (Scanf.Scanning.end_of_input scbuf) then
  3459. begin
  3460. let acc =
  3461. try
  3462. Scanf.bscanf scbuf "%S %S\n"
  3463. (fun e d ->
  3464. let t =
  3465. e, d
  3466. in
  3467. if SetTupleString.mem t st then
  3468. st, lst
  3469. else
  3470. SetTupleString.add t st,
  3471. t :: lst)
  3472. with Scanf.Scan_failure _ ->
  3473. failwith
  3474. (Scanf.bscanf scbuf
  3475. "%l"
  3476. (fun line ->
  3477. Printf.sprintf
  3478. "Malformed log file '%s' at line %d"
  3479. default_filename
  3480. line))
  3481. in
  3482. read_aux acc
  3483. end
  3484. else
  3485. begin
  3486. close_in chn;
  3487. List.rev lst
  3488. end
  3489. in
  3490. read_aux (SetTupleString.empty, [])
  3491. end
  3492. else
  3493. begin
  3494. []
  3495. end
  3496. let register event data =
  3497. let chn_out =
  3498. open_out_gen [Open_append; Open_creat; Open_text] 0o644 default_filename
  3499. in
  3500. Printf.fprintf chn_out "%S %S\n" event data;
  3501. close_out chn_out
  3502. let unregister event data =
  3503. if Sys.file_exists default_filename then
  3504. begin
  3505. let lst =
  3506. load ()
  3507. in
  3508. let chn_out =
  3509. open_out default_filename
  3510. in
  3511. let write_something =
  3512. ref false
  3513. in
  3514. List.iter
  3515. (fun (e, d) ->
  3516. if e <> event || d <> data then
  3517. begin
  3518. write_something := true;
  3519. Printf.fprintf chn_out "%S %S\n" e d
  3520. end)
  3521. lst;
  3522. close_out chn_out;
  3523. if not !write_something then
  3524. Sys.remove default_filename
  3525. end
  3526. let filter events =
  3527. let st_events =
  3528. List.fold_left
  3529. (fun st e ->
  3530. SetString.add e st)
  3531. SetString.empty
  3532. events
  3533. in
  3534. List.filter
  3535. (fun (e, _) -> SetString.mem e st_events)
  3536. (load ())
  3537. let exists event data =
  3538. List.exists
  3539. (fun v -> (event, data) = v)
  3540. (load ())
  3541. end
  3542. module BaseBuilt = struct
  3543. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/base/BaseBuilt.ml" *)
  3544. open OASISTypes
  3545. open OASISGettext
  3546. open BaseStandardVar
  3547. open BaseMessage
  3548. type t =
  3549. | BExec (* Executable *)
  3550. | BExecLib (* Library coming with executable *)
  3551. | BLib (* Library *)
  3552. | BObj (* Library *)
  3553. | BDoc (* Document *)
  3554. let to_log_event_file t nm =
  3555. "built_"^
  3556. (match t with
  3557. | BExec -> "exec"
  3558. | BExecLib -> "exec_lib"
  3559. | BLib -> "lib"
  3560. | BObj -> "obj"
  3561. | BDoc -> "doc")^
  3562. "_"^nm
  3563. let to_log_event_done t nm =
  3564. "is_"^(to_log_event_file t nm)
  3565. let register t nm lst =
  3566. BaseLog.register
  3567. (to_log_event_done t nm)
  3568. "true";
  3569. List.iter
  3570. (fun alt ->
  3571. let registered =
  3572. List.fold_left
  3573. (fun registered fn ->
  3574. if OASISFileUtil.file_exists_case fn then
  3575. begin
  3576. BaseLog.register
  3577. (to_log_event_file t nm)
  3578. (if Filename.is_relative fn then
  3579. Filename.concat (Sys.getcwd ()) fn
  3580. else
  3581. fn);
  3582. true
  3583. end
  3584. else
  3585. registered)
  3586. false
  3587. alt
  3588. in
  3589. if not registered then
  3590. warning
  3591. (f_ "Cannot find an existing alternative files among: %s")
  3592. (String.concat (s_ ", ") alt))
  3593. lst
  3594. let unregister t nm =
  3595. List.iter
  3596. (fun (e, d) ->
  3597. BaseLog.unregister e d)
  3598. (BaseLog.filter
  3599. [to_log_event_file t nm;
  3600. to_log_event_done t nm])
  3601. let fold t nm f acc =
  3602. List.fold_left
  3603. (fun acc (_, fn) ->
  3604. if OASISFileUtil.file_exists_case fn then
  3605. begin
  3606. f acc fn
  3607. end
  3608. else
  3609. begin
  3610. warning
  3611. (f_ "File '%s' has been marked as built \
  3612. for %s but doesn't exist")
  3613. fn
  3614. (Printf.sprintf
  3615. (match t with
  3616. | BExec | BExecLib ->
  3617. (f_ "executable %s")
  3618. | BLib ->
  3619. (f_ "library %s")
  3620. | BObj ->
  3621. (f_ "object %s")
  3622. | BDoc ->
  3623. (f_ "documentation %s"))
  3624. nm);
  3625. acc
  3626. end)
  3627. acc
  3628. (BaseLog.filter
  3629. [to_log_event_file t nm])
  3630. let is_built t nm =
  3631. List.fold_left
  3632. (fun is_built (_, d) ->
  3633. (try
  3634. bool_of_string d
  3635. with _ ->
  3636. false))
  3637. false
  3638. (BaseLog.filter
  3639. [to_log_event_done t nm])
  3640. let of_executable ffn (cs, bs, exec) =
  3641. let unix_exec_is, unix_dll_opt =
  3642. OASISExecutable.unix_exec_is
  3643. (cs, bs, exec)
  3644. (fun () ->
  3645. bool_of_string
  3646. (is_native ()))
  3647. ext_dll
  3648. ext_program
  3649. in
  3650. let evs =
  3651. (BExec, cs.cs_name, [[ffn unix_exec_is]])
  3652. ::
  3653. (match unix_dll_opt with
  3654. | Some fn ->
  3655. [BExecLib, cs.cs_name, [[ffn fn]]]
  3656. | None ->
  3657. [])
  3658. in
  3659. evs,
  3660. unix_exec_is,
  3661. unix_dll_opt
  3662. let of_library ffn (cs, bs, lib) =
  3663. let unix_lst =
  3664. OASISLibrary.generated_unix_files
  3665. ~ctxt:!BaseContext.default
  3666. ~source_file_exists:(fun fn ->
  3667. OASISFileUtil.file_exists_case (OASISHostPath.of_unix fn))
  3668. ~is_native:(bool_of_string (is_native ()))
  3669. ~has_native_dynlink:(bool_of_string (native_dynlink ()))
  3670. ~ext_lib:(ext_lib ())
  3671. ~ext_dll:(ext_dll ())
  3672. (cs, bs, lib)
  3673. in
  3674. let evs =
  3675. [BLib,
  3676. cs.cs_name,
  3677. List.map (List.map ffn) unix_lst]
  3678. in
  3679. evs, unix_lst
  3680. let of_object ffn (cs, bs, obj) =
  3681. let unix_lst =
  3682. OASISObject.generated_unix_files
  3683. ~ctxt:!BaseContext.default
  3684. ~source_file_exists:(fun fn ->
  3685. OASISFileUtil.file_exists_case (OASISHostPath.of_unix fn))
  3686. ~is_native:(bool_of_string (is_native ()))
  3687. (cs, bs, obj)
  3688. in
  3689. let evs =
  3690. [BObj,
  3691. cs.cs_name,
  3692. List.map (List.map ffn) unix_lst]
  3693. in
  3694. evs, unix_lst
  3695. end
  3696. module BaseCustom = struct
  3697. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/base/BaseCustom.ml" *)
  3698. open BaseEnv
  3699. open BaseMessage
  3700. open OASISTypes
  3701. open OASISGettext
  3702. let run cmd args extra_args =
  3703. OASISExec.run ~ctxt:!BaseContext.default ~quote:false
  3704. (var_expand cmd)
  3705. (List.map
  3706. var_expand
  3707. (args @ (Array.to_list extra_args)))
  3708. let hook ?(failsafe=false) cstm f e =
  3709. let optional_command lst =
  3710. let printer =
  3711. function
  3712. | Some (cmd, args) -> String.concat " " (cmd :: args)
  3713. | None -> s_ "No command"
  3714. in
  3715. match
  3716. var_choose
  3717. ~name:(s_ "Pre/Post Command")
  3718. ~printer
  3719. lst with
  3720. | Some (cmd, args) ->
  3721. begin
  3722. try
  3723. run cmd args [||]
  3724. with e when failsafe ->
  3725. warning
  3726. (f_ "Command '%s' fail with error: %s")
  3727. (String.concat " " (cmd :: args))
  3728. (match e with
  3729. | Failure msg -> msg
  3730. | e -> Printexc.to_string e)
  3731. end
  3732. | None ->
  3733. ()
  3734. in
  3735. let res =
  3736. optional_command cstm.pre_command;
  3737. f e
  3738. in
  3739. optional_command cstm.post_command;
  3740. res
  3741. end
  3742. module BaseDynVar = struct
  3743. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/base/BaseDynVar.ml" *)
  3744. open OASISTypes
  3745. open OASISGettext
  3746. open BaseEnv
  3747. open BaseBuilt
  3748. let init pkg =
  3749. (* TODO: disambiguate exec vs other variable by adding exec_VARNAME. *)
  3750. (* TODO: provide compile option for library libary_byte_args_VARNAME... *)
  3751. List.iter
  3752. (function
  3753. | Executable (cs, bs, exec) ->
  3754. if var_choose bs.bs_build then
  3755. var_ignore
  3756. (var_redefine
  3757. (* We don't save this variable *)
  3758. ~dump:false
  3759. ~short_desc:(fun () ->
  3760. Printf.sprintf
  3761. (f_ "Filename of executable '%s'")
  3762. cs.cs_name)
  3763. (OASISUtils.varname_of_string cs.cs_name)
  3764. (fun () ->
  3765. let fn_opt =
  3766. fold
  3767. BExec cs.cs_name
  3768. (fun _ fn -> Some fn)
  3769. None
  3770. in
  3771. match fn_opt with
  3772. | Some fn -> fn
  3773. | None ->
  3774. raise
  3775. (PropList.Not_set
  3776. (cs.cs_name,
  3777. Some (Printf.sprintf
  3778. (f_ "Executable '%s' not yet built.")
  3779. cs.cs_name)))))
  3780. | Library _ | Object _ | Flag _ | Test _ | SrcRepo _ | Doc _ ->
  3781. ())
  3782. pkg.sections
  3783. end
  3784. module BaseTest = struct
  3785. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/base/BaseTest.ml" *)
  3786. open BaseEnv
  3787. open BaseMessage
  3788. open OASISTypes
  3789. open OASISExpr
  3790. open OASISGettext
  3791. let test lst pkg extra_args =
  3792. let one_test (failure, n) (test_plugin, cs, test) =
  3793. if var_choose
  3794. ~name:(Printf.sprintf
  3795. (f_ "test %s run")
  3796. cs.cs_name)
  3797. ~printer:string_of_bool
  3798. test.test_run then
  3799. begin
  3800. let () =
  3801. info (f_ "Running test '%s'") cs.cs_name
  3802. in
  3803. let back_cwd =
  3804. match test.test_working_directory with
  3805. | Some dir ->
  3806. let cwd =
  3807. Sys.getcwd ()
  3808. in
  3809. let chdir d =
  3810. info (f_ "Changing directory to '%s'") d;
  3811. Sys.chdir d
  3812. in
  3813. chdir dir;
  3814. fun () -> chdir cwd
  3815. | None ->
  3816. fun () -> ()
  3817. in
  3818. try
  3819. let failure_percent =
  3820. BaseCustom.hook
  3821. test.test_custom
  3822. (test_plugin pkg (cs, test))
  3823. extra_args
  3824. in
  3825. back_cwd ();
  3826. (failure_percent +. failure, n + 1)
  3827. with e ->
  3828. begin
  3829. back_cwd ();
  3830. raise e
  3831. end
  3832. end
  3833. else
  3834. begin
  3835. info (f_ "Skipping test '%s'") cs.cs_name;
  3836. (failure, n)
  3837. end
  3838. in
  3839. let failed, n =
  3840. List.fold_left
  3841. one_test
  3842. (0.0, 0)
  3843. lst
  3844. in
  3845. let failure_percent =
  3846. if n = 0 then
  3847. 0.0
  3848. else
  3849. failed /. (float_of_int n)
  3850. in
  3851. let msg =
  3852. Printf.sprintf
  3853. (f_ "Tests had a %.2f%% failure rate")
  3854. (100. *. failure_percent)
  3855. in
  3856. if failure_percent > 0.0 then
  3857. failwith msg
  3858. else
  3859. info "%s" msg;
  3860. (* Possible explanation why the tests where not run. *)
  3861. if OASISFeatures.package_test OASISFeatures.flag_tests pkg &&
  3862. not (bool_of_string (BaseStandardVar.tests ())) &&
  3863. lst <> [] then
  3864. BaseMessage.warning
  3865. "Tests are turned off, consider enabling with \
  3866. 'ocaml setup.ml -configure --enable-tests'"
  3867. end
  3868. module BaseDoc = struct
  3869. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/base/BaseDoc.ml" *)
  3870. open BaseEnv
  3871. open BaseMessage
  3872. open OASISTypes
  3873. open OASISGettext
  3874. let doc lst pkg extra_args =
  3875. let one_doc (doc_plugin, cs, doc) =
  3876. if var_choose
  3877. ~name:(Printf.sprintf
  3878. (f_ "documentation %s build")
  3879. cs.cs_name)
  3880. ~printer:string_of_bool
  3881. doc.doc_build then
  3882. begin
  3883. info (f_ "Building documentation '%s'") cs.cs_name;
  3884. BaseCustom.hook
  3885. doc.doc_custom
  3886. (doc_plugin pkg (cs, doc))
  3887. extra_args
  3888. end
  3889. in
  3890. List.iter one_doc lst;
  3891. if OASISFeatures.package_test OASISFeatures.flag_docs pkg &&
  3892. not (bool_of_string (BaseStandardVar.docs ())) &&
  3893. lst <> [] then
  3894. BaseMessage.warning
  3895. "Docs are turned off, consider enabling with \
  3896. 'ocaml setup.ml -configure --enable-docs'"
  3897. end
  3898. module BaseSetup = struct
  3899. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/base/BaseSetup.ml" *)
  3900. open BaseEnv
  3901. open BaseMessage
  3902. open OASISTypes
  3903. open OASISSection
  3904. open OASISGettext
  3905. open OASISUtils
  3906. type std_args_fun =
  3907. package -> string array -> unit
  3908. type ('a, 'b) section_args_fun =
  3909. name * (package -> (common_section * 'a) -> string array -> 'b)
  3910. type t =
  3911. {
  3912. configure: std_args_fun;
  3913. build: std_args_fun;
  3914. doc: ((doc, unit) section_args_fun) list;
  3915. test: ((test, float) section_args_fun) list;
  3916. install: std_args_fun;
  3917. uninstall: std_args_fun;
  3918. clean: std_args_fun list;
  3919. clean_doc: (doc, unit) section_args_fun list;
  3920. clean_test: (test, unit) section_args_fun list;
  3921. distclean: std_args_fun list;
  3922. distclean_doc: (doc, unit) section_args_fun list;
  3923. distclean_test: (test, unit) section_args_fun list;
  3924. package: package;
  3925. oasis_fn: string option;
  3926. oasis_version: string;
  3927. oasis_digest: Digest.t option;
  3928. oasis_exec: string option;
  3929. oasis_setup_args: string list;
  3930. setup_update: bool;
  3931. }
  3932. (* Associate a plugin function with data from package *)
  3933. let join_plugin_sections filter_map lst =
  3934. List.rev
  3935. (List.fold_left
  3936. (fun acc sct ->
  3937. match filter_map sct with
  3938. | Some e ->
  3939. e :: acc
  3940. | None ->
  3941. acc)
  3942. []
  3943. lst)
  3944. (* Search for plugin data associated with a section name *)
  3945. let lookup_plugin_section plugin action nm lst =
  3946. try
  3947. List.assoc nm lst
  3948. with Not_found ->
  3949. failwithf
  3950. (f_ "Cannot find plugin %s matching section %s for %s action")
  3951. plugin
  3952. nm
  3953. action
  3954. let configure t args =
  3955. (* Run configure *)
  3956. BaseCustom.hook
  3957. t.package.conf_custom
  3958. (fun () ->
  3959. (* Reload if preconf has changed it *)
  3960. begin
  3961. try
  3962. unload ();
  3963. load ();
  3964. with _ ->
  3965. ()
  3966. end;
  3967. (* Run plugin's configure *)
  3968. t.configure t.package args;
  3969. (* Dump to allow postconf to change it *)
  3970. dump ())
  3971. ();
  3972. (* Reload environment *)
  3973. unload ();
  3974. load ();
  3975. (* Save environment *)
  3976. print ();
  3977. (* Replace data in file *)
  3978. BaseFileAB.replace t.package.files_ab
  3979. let build t args =
  3980. BaseCustom.hook
  3981. t.package.build_custom
  3982. (t.build t.package)
  3983. args
  3984. let doc t args =
  3985. BaseDoc.doc
  3986. (join_plugin_sections
  3987. (function
  3988. | Doc (cs, e) ->
  3989. Some
  3990. (lookup_plugin_section
  3991. "documentation"
  3992. (s_ "build")
  3993. cs.cs_name
  3994. t.doc,
  3995. cs,
  3996. e)
  3997. | _ ->
  3998. None)
  3999. t.package.sections)
  4000. t.package
  4001. args
  4002. let test t args =
  4003. BaseTest.test
  4004. (join_plugin_sections
  4005. (function
  4006. | Test (cs, e) ->
  4007. Some
  4008. (lookup_plugin_section
  4009. "test"
  4010. (s_ "run")
  4011. cs.cs_name
  4012. t.test,
  4013. cs,
  4014. e)
  4015. | _ ->
  4016. None)
  4017. t.package.sections)
  4018. t.package
  4019. args
  4020. let all t args =
  4021. let rno_doc =
  4022. ref false
  4023. in
  4024. let rno_test =
  4025. ref false
  4026. in
  4027. let arg_rest =
  4028. ref []
  4029. in
  4030. Arg.parse_argv
  4031. ~current:(ref 0)
  4032. (Array.of_list
  4033. ((Sys.executable_name^" all") ::
  4034. (Array.to_list args)))
  4035. [
  4036. "-no-doc",
  4037. Arg.Set rno_doc,
  4038. s_ "Don't run doc target";
  4039. "-no-test",
  4040. Arg.Set rno_test,
  4041. s_ "Don't run test target";
  4042. "--",
  4043. Arg.Rest (fun arg -> arg_rest := arg :: !arg_rest),
  4044. s_ "All arguments for configure.";
  4045. ]
  4046. (failwithf (f_ "Don't know what to do with '%s'"))
  4047. "";
  4048. info "Running configure step";
  4049. configure t (Array.of_list (List.rev !arg_rest));
  4050. info "Running build step";
  4051. build t [||];
  4052. (* Load setup.log dynamic variables *)
  4053. BaseDynVar.init t.package;
  4054. if not !rno_doc then
  4055. begin
  4056. info "Running doc step";
  4057. doc t [||];
  4058. end
  4059. else
  4060. begin
  4061. info "Skipping doc step"
  4062. end;
  4063. if not !rno_test then
  4064. begin
  4065. info "Running test step";
  4066. test t [||]
  4067. end
  4068. else
  4069. begin
  4070. info "Skipping test step"
  4071. end
  4072. let install t args =
  4073. BaseCustom.hook
  4074. t.package.install_custom
  4075. (t.install t.package)
  4076. args
  4077. let uninstall t args =
  4078. BaseCustom.hook
  4079. t.package.uninstall_custom
  4080. (t.uninstall t.package)
  4081. args
  4082. let reinstall t args =
  4083. uninstall t args;
  4084. install t args
  4085. let clean, distclean =
  4086. let failsafe f a =
  4087. try
  4088. f a
  4089. with e ->
  4090. warning
  4091. (f_ "Action fail with error: %s")
  4092. (match e with
  4093. | Failure msg -> msg
  4094. | e -> Printexc.to_string e)
  4095. in
  4096. let generic_clean t cstm mains docs tests args =
  4097. BaseCustom.hook
  4098. ~failsafe:true
  4099. cstm
  4100. (fun () ->
  4101. (* Clean section *)
  4102. List.iter
  4103. (function
  4104. | Test (cs, test) ->
  4105. let f =
  4106. try
  4107. List.assoc cs.cs_name tests
  4108. with Not_found ->
  4109. fun _ _ _ -> ()
  4110. in
  4111. failsafe
  4112. (f t.package (cs, test))
  4113. args
  4114. | Doc (cs, doc) ->
  4115. let f =
  4116. try
  4117. List.assoc cs.cs_name docs
  4118. with Not_found ->
  4119. fun _ _ _ -> ()
  4120. in
  4121. failsafe
  4122. (f t.package (cs, doc))
  4123. args
  4124. | Library _
  4125. | Object _
  4126. | Executable _
  4127. | Flag _
  4128. | SrcRepo _ ->
  4129. ())
  4130. t.package.sections;
  4131. (* Clean whole package *)
  4132. List.iter
  4133. (fun f ->
  4134. failsafe
  4135. (f t.package)
  4136. args)
  4137. mains)
  4138. ()
  4139. in
  4140. let clean t args =
  4141. generic_clean
  4142. t
  4143. t.package.clean_custom
  4144. t.clean
  4145. t.clean_doc
  4146. t.clean_test
  4147. args
  4148. in
  4149. let distclean t args =
  4150. (* Call clean *)
  4151. clean t args;
  4152. (* Call distclean code *)
  4153. generic_clean
  4154. t
  4155. t.package.distclean_custom
  4156. t.distclean
  4157. t.distclean_doc
  4158. t.distclean_test
  4159. args;
  4160. (* Remove generated file *)
  4161. List.iter
  4162. (fun fn ->
  4163. if Sys.file_exists fn then
  4164. begin
  4165. info (f_ "Remove '%s'") fn;
  4166. Sys.remove fn
  4167. end)
  4168. (BaseEnv.default_filename
  4169. ::
  4170. BaseLog.default_filename
  4171. ::
  4172. (List.rev_map BaseFileAB.to_filename t.package.files_ab))
  4173. in
  4174. clean, distclean
  4175. let version t _ =
  4176. print_endline t.oasis_version
  4177. let update_setup_ml, no_update_setup_ml_cli =
  4178. let b = ref true in
  4179. b,
  4180. ("-no-update-setup-ml",
  4181. Arg.Clear b,
  4182. s_ " Don't try to update setup.ml, even if _oasis has changed.")
  4183. let default_oasis_fn = "_oasis"
  4184. let update_setup_ml t =
  4185. let oasis_fn =
  4186. match t.oasis_fn with
  4187. | Some fn -> fn
  4188. | None -> default_oasis_fn
  4189. in
  4190. let oasis_exec =
  4191. match t.oasis_exec with
  4192. | Some fn -> fn
  4193. | None -> "oasis"
  4194. in
  4195. let ocaml =
  4196. Sys.executable_name
  4197. in
  4198. let setup_ml, args =
  4199. match Array.to_list Sys.argv with
  4200. | setup_ml :: args ->
  4201. setup_ml, args
  4202. | [] ->
  4203. failwith
  4204. (s_ "Expecting non-empty command line arguments.")
  4205. in
  4206. let ocaml, setup_ml =
  4207. if Sys.executable_name = Sys.argv.(0) then
  4208. (* We are not running in standard mode, probably the script
  4209. * is precompiled.
  4210. *)
  4211. "ocaml", "setup.ml"
  4212. else
  4213. ocaml, setup_ml
  4214. in
  4215. let no_update_setup_ml_cli, _, _ = no_update_setup_ml_cli in
  4216. let do_update () =
  4217. let oasis_exec_version =
  4218. OASISExec.run_read_one_line
  4219. ~ctxt:!BaseContext.default
  4220. ~f_exit_code:
  4221. (function
  4222. | 0 ->
  4223. ()
  4224. | 1 ->
  4225. failwithf
  4226. (f_ "Executable '%s' is probably an old version \
  4227. of oasis (< 0.3.0), please update to version \
  4228. v%s.")
  4229. oasis_exec t.oasis_version
  4230. | 127 ->
  4231. failwithf
  4232. (f_ "Cannot find executable '%s', please install \
  4233. oasis v%s.")
  4234. oasis_exec t.oasis_version
  4235. | n ->
  4236. failwithf
  4237. (f_ "Command '%s version' exited with code %d.")
  4238. oasis_exec n)
  4239. oasis_exec ["version"]
  4240. in
  4241. if OASISVersion.comparator_apply
  4242. (OASISVersion.version_of_string oasis_exec_version)
  4243. (OASISVersion.VGreaterEqual
  4244. (OASISVersion.version_of_string t.oasis_version)) then
  4245. begin
  4246. (* We have a version >= for the executable oasis, proceed with
  4247. * update.
  4248. *)
  4249. (* TODO: delegate this check to 'oasis setup'. *)
  4250. if Sys.os_type = "Win32" then
  4251. failwithf
  4252. (f_ "It is not possible to update the running script \
  4253. setup.ml on Windows. Please update setup.ml by \
  4254. running '%s'.")
  4255. (String.concat " " (oasis_exec :: "setup" :: t.oasis_setup_args))
  4256. else
  4257. begin
  4258. OASISExec.run
  4259. ~ctxt:!BaseContext.default
  4260. ~f_exit_code:
  4261. (function
  4262. | 0 ->
  4263. ()
  4264. | n ->
  4265. failwithf
  4266. (f_ "Unable to update setup.ml using '%s', \
  4267. please fix the problem and retry.")
  4268. oasis_exec)
  4269. oasis_exec ("setup" :: t.oasis_setup_args);
  4270. OASISExec.run ~ctxt:!BaseContext.default ocaml (setup_ml :: args)
  4271. end
  4272. end
  4273. else
  4274. failwithf
  4275. (f_ "The version of '%s' (v%s) doesn't match the version of \
  4276. oasis used to generate the %s file. Please install at \
  4277. least oasis v%s.")
  4278. oasis_exec oasis_exec_version setup_ml t.oasis_version
  4279. in
  4280. if !update_setup_ml then
  4281. begin
  4282. try
  4283. match t.oasis_digest with
  4284. | Some dgst ->
  4285. if Sys.file_exists oasis_fn &&
  4286. dgst <> Digest.file default_oasis_fn then
  4287. begin
  4288. do_update ();
  4289. true
  4290. end
  4291. else
  4292. false
  4293. | None ->
  4294. false
  4295. with e ->
  4296. error
  4297. (f_ "Error when updating setup.ml. If you want to avoid this error, \
  4298. you can bypass the update of %s by running '%s %s %s %s'")
  4299. setup_ml ocaml setup_ml no_update_setup_ml_cli
  4300. (String.concat " " args);
  4301. raise e
  4302. end
  4303. else
  4304. false
  4305. let setup t =
  4306. let catch_exn =
  4307. ref true
  4308. in
  4309. try
  4310. let act_ref =
  4311. ref (fun _ ->
  4312. failwithf
  4313. (f_ "No action defined, run '%s %s -help'")
  4314. Sys.executable_name
  4315. Sys.argv.(0))
  4316. in
  4317. let extra_args_ref =
  4318. ref []
  4319. in
  4320. let allow_empty_env_ref =
  4321. ref false
  4322. in
  4323. let arg_handle ?(allow_empty_env=false) act =
  4324. Arg.Tuple
  4325. [
  4326. Arg.Rest (fun str -> extra_args_ref := str :: !extra_args_ref);
  4327. Arg.Unit
  4328. (fun () ->
  4329. allow_empty_env_ref := allow_empty_env;
  4330. act_ref := act);
  4331. ]
  4332. in
  4333. Arg.parse
  4334. (Arg.align
  4335. ([
  4336. "-configure",
  4337. arg_handle ~allow_empty_env:true configure,
  4338. s_ "[options*] Configure the whole build process.";
  4339. "-build",
  4340. arg_handle build,
  4341. s_ "[options*] Build executables and libraries.";
  4342. "-doc",
  4343. arg_handle doc,
  4344. s_ "[options*] Build documents.";
  4345. "-test",
  4346. arg_handle test,
  4347. s_ "[options*] Run tests.";
  4348. "-all",
  4349. arg_handle ~allow_empty_env:true all,
  4350. s_ "[options*] Run configure, build, doc and test targets.";
  4351. "-install",
  4352. arg_handle install,
  4353. s_ "[options*] Install libraries, data, executables \
  4354. and documents.";
  4355. "-uninstall",
  4356. arg_handle uninstall,
  4357. s_ "[options*] Uninstall libraries, data, executables \
  4358. and documents.";
  4359. "-reinstall",
  4360. arg_handle reinstall,
  4361. s_ "[options*] Uninstall and install libraries, data, \
  4362. executables and documents.";
  4363. "-clean",
  4364. arg_handle ~allow_empty_env:true clean,
  4365. s_ "[options*] Clean files generated by a build.";
  4366. "-distclean",
  4367. arg_handle ~allow_empty_env:true distclean,
  4368. s_ "[options*] Clean files generated by a build and configure.";
  4369. "-version",
  4370. arg_handle ~allow_empty_env:true version,
  4371. s_ " Display version of OASIS used to generate this setup.ml.";
  4372. "-no-catch-exn",
  4373. Arg.Clear catch_exn,
  4374. s_ " Don't catch exception, useful for debugging.";
  4375. ]
  4376. @
  4377. (if t.setup_update then
  4378. [no_update_setup_ml_cli]
  4379. else
  4380. [])
  4381. @ (BaseContext.args ())))
  4382. (failwithf (f_ "Don't know what to do with '%s'"))
  4383. (s_ "Setup and run build process current package\n");
  4384. (* Build initial environment *)
  4385. load ~allow_empty:!allow_empty_env_ref ();
  4386. (** Initialize flags *)
  4387. List.iter
  4388. (function
  4389. | Flag (cs, {flag_description = hlp;
  4390. flag_default = choices}) ->
  4391. begin
  4392. let apply ?short_desc () =
  4393. var_ignore
  4394. (var_define
  4395. ~cli:CLIEnable
  4396. ?short_desc
  4397. (OASISUtils.varname_of_string cs.cs_name)
  4398. (fun () ->
  4399. string_of_bool
  4400. (var_choose
  4401. ~name:(Printf.sprintf
  4402. (f_ "default value of flag %s")
  4403. cs.cs_name)
  4404. ~printer:string_of_bool
  4405. choices)))
  4406. in
  4407. match hlp with
  4408. | Some hlp ->
  4409. apply ~short_desc:(fun () -> hlp) ()
  4410. | None ->
  4411. apply ()
  4412. end
  4413. | _ ->
  4414. ())
  4415. t.package.sections;
  4416. BaseStandardVar.init t.package;
  4417. BaseDynVar.init t.package;
  4418. if t.setup_update && update_setup_ml t then
  4419. ()
  4420. else
  4421. !act_ref t (Array.of_list (List.rev !extra_args_ref))
  4422. with e when !catch_exn ->
  4423. error "%s" (Printexc.to_string e);
  4424. exit 1
  4425. end
  4426. # 5394 "setup.ml"
  4427. module InternalConfigurePlugin = struct
  4428. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/plugins/internal/InternalConfigurePlugin.ml" *)
  4429. (** Configure using internal scheme
  4430. @author Sylvain Le Gall
  4431. *)
  4432. open BaseEnv
  4433. open OASISTypes
  4434. open OASISUtils
  4435. open OASISGettext
  4436. open BaseMessage
  4437. (** Configure build using provided series of check to be done
  4438. * and then output corresponding file.
  4439. *)
  4440. let configure pkg argv =
  4441. let var_ignore_eval var = let _s: string = var () in () in
  4442. let errors = ref SetString.empty in
  4443. let buff = Buffer.create 13 in
  4444. let add_errors fmt =
  4445. Printf.kbprintf
  4446. (fun b ->
  4447. errors := SetString.add (Buffer.contents b) !errors;
  4448. Buffer.clear b)
  4449. buff
  4450. fmt
  4451. in
  4452. let warn_exception e =
  4453. warning "%s" (Printexc.to_string e)
  4454. in
  4455. (* Check tools *)
  4456. let check_tools lst =
  4457. List.iter
  4458. (function
  4459. | ExternalTool tool ->
  4460. begin
  4461. try
  4462. var_ignore_eval (BaseCheck.prog tool)
  4463. with e ->
  4464. warn_exception e;
  4465. add_errors (f_ "Cannot find external tool '%s'") tool
  4466. end
  4467. | InternalExecutable nm1 ->
  4468. (* Check that matching tool is built *)
  4469. List.iter
  4470. (function
  4471. | Executable ({cs_name = nm2},
  4472. {bs_build = build},
  4473. _) when nm1 = nm2 ->
  4474. if not (var_choose build) then
  4475. add_errors
  4476. (f_ "Cannot find buildable internal executable \
  4477. '%s' when checking build depends")
  4478. nm1
  4479. | _ ->
  4480. ())
  4481. pkg.sections)
  4482. lst
  4483. in
  4484. let build_checks sct bs =
  4485. if var_choose bs.bs_build then
  4486. begin
  4487. if bs.bs_compiled_object = Native then
  4488. begin
  4489. try
  4490. var_ignore_eval BaseStandardVar.ocamlopt
  4491. with e ->
  4492. warn_exception e;
  4493. add_errors
  4494. (f_ "Section %s requires native compilation")
  4495. (OASISSection.string_of_section sct)
  4496. end;
  4497. (* Check tools *)
  4498. check_tools bs.bs_build_tools;
  4499. (* Check depends *)
  4500. List.iter
  4501. (function
  4502. | FindlibPackage (findlib_pkg, version_comparator) ->
  4503. begin
  4504. try
  4505. var_ignore_eval
  4506. (BaseCheck.package ?version_comparator findlib_pkg)
  4507. with e ->
  4508. warn_exception e;
  4509. match version_comparator with
  4510. | None ->
  4511. add_errors
  4512. (f_ "Cannot find findlib package %s")
  4513. findlib_pkg
  4514. | Some ver_cmp ->
  4515. add_errors
  4516. (f_ "Cannot find findlib package %s (%s)")
  4517. findlib_pkg
  4518. (OASISVersion.string_of_comparator ver_cmp)
  4519. end
  4520. | InternalLibrary nm1 ->
  4521. (* Check that matching library is built *)
  4522. List.iter
  4523. (function
  4524. | Library ({cs_name = nm2},
  4525. {bs_build = build},
  4526. _) when nm1 = nm2 ->
  4527. if not (var_choose build) then
  4528. add_errors
  4529. (f_ "Cannot find buildable internal library \
  4530. '%s' when checking build depends")
  4531. nm1
  4532. | _ ->
  4533. ())
  4534. pkg.sections)
  4535. bs.bs_build_depends
  4536. end
  4537. in
  4538. (* Parse command line *)
  4539. BaseArgExt.parse argv (BaseEnv.args ());
  4540. (* OCaml version *)
  4541. begin
  4542. match pkg.ocaml_version with
  4543. | Some ver_cmp ->
  4544. begin
  4545. try
  4546. var_ignore_eval
  4547. (BaseCheck.version
  4548. "ocaml"
  4549. ver_cmp
  4550. BaseStandardVar.ocaml_version)
  4551. with e ->
  4552. warn_exception e;
  4553. add_errors
  4554. (f_ "OCaml version %s doesn't match version constraint %s")
  4555. (BaseStandardVar.ocaml_version ())
  4556. (OASISVersion.string_of_comparator ver_cmp)
  4557. end
  4558. | None ->
  4559. ()
  4560. end;
  4561. (* Findlib version *)
  4562. begin
  4563. match pkg.findlib_version with
  4564. | Some ver_cmp ->
  4565. begin
  4566. try
  4567. var_ignore_eval
  4568. (BaseCheck.version
  4569. "findlib"
  4570. ver_cmp
  4571. BaseStandardVar.findlib_version)
  4572. with e ->
  4573. warn_exception e;
  4574. add_errors
  4575. (f_ "Findlib version %s doesn't match version constraint %s")
  4576. (BaseStandardVar.findlib_version ())
  4577. (OASISVersion.string_of_comparator ver_cmp)
  4578. end
  4579. | None ->
  4580. ()
  4581. end;
  4582. (* Make sure the findlib version is fine for the OCaml compiler. *)
  4583. begin
  4584. let ocaml_ge4 =
  4585. OASISVersion.version_compare
  4586. (OASISVersion.version_of_string (BaseStandardVar.ocaml_version()))
  4587. (OASISVersion.version_of_string "4.0.0") >= 0 in
  4588. if ocaml_ge4 then
  4589. let findlib_lt132 =
  4590. OASISVersion.version_compare
  4591. (OASISVersion.version_of_string (BaseStandardVar.findlib_version()))
  4592. (OASISVersion.version_of_string "1.3.2") < 0 in
  4593. if findlib_lt132 then
  4594. add_errors "OCaml >= 4.0.0 requires Findlib version >= 1.3.2"
  4595. end;
  4596. (* FlexDLL *)
  4597. if BaseStandardVar.os_type () = "Win32" ||
  4598. BaseStandardVar.os_type () = "Cygwin" then
  4599. begin
  4600. try
  4601. var_ignore_eval BaseStandardVar.flexlink
  4602. with e ->
  4603. warn_exception e;
  4604. add_errors (f_ "Cannot find 'flexlink'")
  4605. end;
  4606. (* Check build depends *)
  4607. List.iter
  4608. (function
  4609. | Executable (_, bs, _)
  4610. | Library (_, bs, _) as sct ->
  4611. build_checks sct bs
  4612. | Doc (_, doc) ->
  4613. if var_choose doc.doc_build then
  4614. check_tools doc.doc_build_tools
  4615. | Test (_, test) ->
  4616. if var_choose test.test_run then
  4617. check_tools test.test_tools
  4618. | _ ->
  4619. ())
  4620. pkg.sections;
  4621. (* Check if we need native dynlink (presence of libraries that compile to
  4622. * native)
  4623. *)
  4624. begin
  4625. let has_cmxa =
  4626. List.exists
  4627. (function
  4628. | Library (_, bs, _) ->
  4629. var_choose bs.bs_build &&
  4630. (bs.bs_compiled_object = Native ||
  4631. (bs.bs_compiled_object = Best &&
  4632. bool_of_string (BaseStandardVar.is_native ())))
  4633. | _ ->
  4634. false)
  4635. pkg.sections
  4636. in
  4637. if has_cmxa then
  4638. var_ignore_eval BaseStandardVar.native_dynlink
  4639. end;
  4640. (* Check errors *)
  4641. if SetString.empty != !errors then
  4642. begin
  4643. List.iter
  4644. (fun e -> error "%s" e)
  4645. (SetString.elements !errors);
  4646. failwithf
  4647. (fn_
  4648. "%d configuration error"
  4649. "%d configuration errors"
  4650. (SetString.cardinal !errors))
  4651. (SetString.cardinal !errors)
  4652. end
  4653. end
  4654. module InternalInstallPlugin = struct
  4655. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/plugins/internal/InternalInstallPlugin.ml" *)
  4656. (** Install using internal scheme
  4657. @author Sylvain Le Gall
  4658. *)
  4659. open BaseEnv
  4660. open BaseStandardVar
  4661. open BaseMessage
  4662. open OASISTypes
  4663. open OASISFindlib
  4664. open OASISGettext
  4665. open OASISUtils
  4666. let exec_hook =
  4667. ref (fun (cs, bs, exec) -> cs, bs, exec)
  4668. let lib_hook =
  4669. ref (fun (cs, bs, lib) -> cs, bs, lib, [])
  4670. let obj_hook =
  4671. ref (fun (cs, bs, obj) -> cs, bs, obj, [])
  4672. let doc_hook =
  4673. ref (fun (cs, doc) -> cs, doc)
  4674. let install_file_ev =
  4675. "install-file"
  4676. let install_dir_ev =
  4677. "install-dir"
  4678. let install_findlib_ev =
  4679. "install-findlib"
  4680. let win32_max_command_line_length = 8000
  4681. let split_install_command ocamlfind findlib_name meta files =
  4682. if Sys.os_type = "Win32" then
  4683. (* Arguments for the first command: *)
  4684. let first_args = ["install"; findlib_name; meta] in
  4685. (* Arguments for remaining commands: *)
  4686. let other_args = ["install"; findlib_name; "-add"] in
  4687. (* Extract as much files as possible from [files], [len] is
  4688. the current command line length: *)
  4689. let rec get_files len acc files =
  4690. match files with
  4691. | [] ->
  4692. (List.rev acc, [])
  4693. | file :: rest ->
  4694. let len = len + 1 + String.length file in
  4695. if len > win32_max_command_line_length then
  4696. (List.rev acc, files)
  4697. else
  4698. get_files len (file :: acc) rest
  4699. in
  4700. (* Split the command into several commands. *)
  4701. let rec split args files =
  4702. match files with
  4703. | [] ->
  4704. []
  4705. | _ ->
  4706. (* Length of "ocamlfind install <lib> [META|-add]" *)
  4707. let len =
  4708. List.fold_left
  4709. (fun len arg ->
  4710. len + 1 (* for the space *) + String.length arg)
  4711. (String.length ocamlfind)
  4712. args
  4713. in
  4714. match get_files len [] files with
  4715. | ([], _) ->
  4716. failwith (s_ "Command line too long.")
  4717. | (firsts, others) ->
  4718. let cmd = args @ firsts in
  4719. (* Use -add for remaining commands: *)
  4720. let () =
  4721. let findlib_ge_132 =
  4722. OASISVersion.comparator_apply
  4723. (OASISVersion.version_of_string
  4724. (BaseStandardVar.findlib_version ()))
  4725. (OASISVersion.VGreaterEqual
  4726. (OASISVersion.version_of_string "1.3.2"))
  4727. in
  4728. if not findlib_ge_132 then
  4729. failwithf
  4730. (f_ "Installing the library %s require to use the \
  4731. flag '-add' of ocamlfind because the command \
  4732. line is too long. This flag is only available \
  4733. for findlib 1.3.2. Please upgrade findlib from \
  4734. %s to 1.3.2")
  4735. findlib_name (BaseStandardVar.findlib_version ())
  4736. in
  4737. let cmds = split other_args others in
  4738. cmd :: cmds
  4739. in
  4740. (* The first command does not use -add: *)
  4741. split first_args files
  4742. else
  4743. ["install" :: findlib_name :: meta :: files]
  4744. let install pkg argv =
  4745. let in_destdir =
  4746. try
  4747. let destdir =
  4748. destdir ()
  4749. in
  4750. (* Practically speaking destdir is prepended
  4751. * at the beginning of the target filename
  4752. *)
  4753. fun fn -> destdir^fn
  4754. with PropList.Not_set _ ->
  4755. fun fn -> fn
  4756. in
  4757. let install_file ?tgt_fn src_file envdir =
  4758. let tgt_dir =
  4759. in_destdir (envdir ())
  4760. in
  4761. let tgt_file =
  4762. Filename.concat
  4763. tgt_dir
  4764. (match tgt_fn with
  4765. | Some fn ->
  4766. fn
  4767. | None ->
  4768. Filename.basename src_file)
  4769. in
  4770. (* Create target directory if needed *)
  4771. OASISFileUtil.mkdir_parent
  4772. ~ctxt:!BaseContext.default
  4773. (fun dn ->
  4774. info (f_ "Creating directory '%s'") dn;
  4775. BaseLog.register install_dir_ev dn)
  4776. tgt_dir;
  4777. (* Really install files *)
  4778. info (f_ "Copying file '%s' to '%s'") src_file tgt_file;
  4779. OASISFileUtil.cp ~ctxt:!BaseContext.default src_file tgt_file;
  4780. BaseLog.register install_file_ev tgt_file
  4781. in
  4782. (* Install data into defined directory *)
  4783. let install_data srcdir lst tgtdir =
  4784. let tgtdir =
  4785. OASISHostPath.of_unix (var_expand tgtdir)
  4786. in
  4787. List.iter
  4788. (fun (src, tgt_opt) ->
  4789. let real_srcs =
  4790. OASISFileUtil.glob
  4791. ~ctxt:!BaseContext.default
  4792. (Filename.concat srcdir src)
  4793. in
  4794. if real_srcs = [] then
  4795. failwithf
  4796. (f_ "Wildcard '%s' doesn't match any files")
  4797. src;
  4798. List.iter
  4799. (fun fn ->
  4800. install_file
  4801. fn
  4802. (fun () ->
  4803. match tgt_opt with
  4804. | Some s ->
  4805. OASISHostPath.of_unix (var_expand s)
  4806. | None ->
  4807. tgtdir))
  4808. real_srcs)
  4809. lst
  4810. in
  4811. (** Install all libraries *)
  4812. let install_libs pkg =
  4813. let files_of_library (f_data, acc) data_lib =
  4814. let cs, bs, lib, lib_extra =
  4815. !lib_hook data_lib
  4816. in
  4817. if var_choose bs.bs_install &&
  4818. BaseBuilt.is_built BaseBuilt.BLib cs.cs_name then
  4819. begin
  4820. let acc =
  4821. (* Start with acc + lib_extra *)
  4822. List.rev_append lib_extra acc
  4823. in
  4824. let acc =
  4825. (* Add uncompiled header from the source tree *)
  4826. let path =
  4827. OASISHostPath.of_unix bs.bs_path
  4828. in
  4829. List.fold_left
  4830. (fun acc modul ->
  4831. try
  4832. List.find
  4833. OASISFileUtil.file_exists_case
  4834. (List.map
  4835. (Filename.concat path)
  4836. [modul^".mli";
  4837. modul^".ml";
  4838. String.uncapitalize modul^".mli";
  4839. String.capitalize modul^".mli";
  4840. String.uncapitalize modul^".ml";
  4841. String.capitalize modul^".ml"])
  4842. :: acc
  4843. with Not_found ->
  4844. begin
  4845. warning
  4846. (f_ "Cannot find source header for module %s \
  4847. in library %s")
  4848. modul cs.cs_name;
  4849. acc
  4850. end)
  4851. acc
  4852. lib.lib_modules
  4853. in
  4854. let acc =
  4855. (* Get generated files *)
  4856. BaseBuilt.fold
  4857. BaseBuilt.BLib
  4858. cs.cs_name
  4859. (fun acc fn -> fn :: acc)
  4860. acc
  4861. in
  4862. let f_data () =
  4863. (* Install data associated with the library *)
  4864. install_data
  4865. bs.bs_path
  4866. bs.bs_data_files
  4867. (Filename.concat
  4868. (datarootdir ())
  4869. pkg.name);
  4870. f_data ()
  4871. in
  4872. (f_data, acc)
  4873. end
  4874. else
  4875. begin
  4876. (f_data, acc)
  4877. end
  4878. and files_of_object (f_data, acc) data_obj =
  4879. let cs, bs, obj, obj_extra =
  4880. !obj_hook data_obj
  4881. in
  4882. if var_choose bs.bs_install &&
  4883. BaseBuilt.is_built BaseBuilt.BObj cs.cs_name then
  4884. begin
  4885. let acc =
  4886. (* Start with acc + obj_extra *)
  4887. List.rev_append obj_extra acc
  4888. in
  4889. let acc =
  4890. (* Add uncompiled header from the source tree *)
  4891. let path =
  4892. OASISHostPath.of_unix bs.bs_path
  4893. in
  4894. List.fold_left
  4895. (fun acc modul ->
  4896. try
  4897. List.find
  4898. OASISFileUtil.file_exists_case
  4899. (List.map
  4900. (Filename.concat path)
  4901. [modul^".mli";
  4902. modul^".ml";
  4903. String.uncapitalize modul^".mli";
  4904. String.capitalize modul^".mli";
  4905. String.uncapitalize modul^".ml";
  4906. String.capitalize modul^".ml"])
  4907. :: acc
  4908. with Not_found ->
  4909. begin
  4910. warning
  4911. (f_ "Cannot find source header for module %s \
  4912. in object %s")
  4913. modul cs.cs_name;
  4914. acc
  4915. end)
  4916. acc
  4917. obj.obj_modules
  4918. in
  4919. let acc =
  4920. (* Get generated files *)
  4921. BaseBuilt.fold
  4922. BaseBuilt.BObj
  4923. cs.cs_name
  4924. (fun acc fn -> fn :: acc)
  4925. acc
  4926. in
  4927. let f_data () =
  4928. (* Install data associated with the object *)
  4929. install_data
  4930. bs.bs_path
  4931. bs.bs_data_files
  4932. (Filename.concat
  4933. (datarootdir ())
  4934. pkg.name);
  4935. f_data ()
  4936. in
  4937. (f_data, acc)
  4938. end
  4939. else
  4940. begin
  4941. (f_data, acc)
  4942. end
  4943. in
  4944. (* Install one group of library *)
  4945. let install_group_lib grp =
  4946. (* Iterate through all group nodes *)
  4947. let rec install_group_lib_aux data_and_files grp =
  4948. let data_and_files, children =
  4949. match grp with
  4950. | Container (_, children) ->
  4951. data_and_files, children
  4952. | Package (_, cs, bs, `Library lib, children) ->
  4953. files_of_library data_and_files (cs, bs, lib), children
  4954. | Package (_, cs, bs, `Object obj, children) ->
  4955. files_of_object data_and_files (cs, bs, obj), children
  4956. in
  4957. List.fold_left
  4958. install_group_lib_aux
  4959. data_and_files
  4960. children
  4961. in
  4962. (* Findlib name of the root library *)
  4963. let findlib_name =
  4964. findlib_of_group grp
  4965. in
  4966. (* Determine root library *)
  4967. let root_lib =
  4968. root_of_group grp
  4969. in
  4970. (* All files to install for this library *)
  4971. let f_data, files =
  4972. install_group_lib_aux (ignore, []) grp
  4973. in
  4974. (* Really install, if there is something to install *)
  4975. if files = [] then
  4976. begin
  4977. warning
  4978. (f_ "Nothing to install for findlib library '%s'")
  4979. findlib_name
  4980. end
  4981. else
  4982. begin
  4983. let meta =
  4984. (* Search META file *)
  4985. let _, bs, _ =
  4986. root_lib
  4987. in
  4988. let res =
  4989. Filename.concat bs.bs_path "META"
  4990. in
  4991. if not (OASISFileUtil.file_exists_case res) then
  4992. failwithf
  4993. (f_ "Cannot find file '%s' for findlib library %s")
  4994. res
  4995. findlib_name;
  4996. res
  4997. in
  4998. let files =
  4999. (* Make filename shorter to avoid hitting command max line length
  5000. * too early, esp. on Windows.
  5001. *)
  5002. let remove_prefix p n =
  5003. let plen = String.length p in
  5004. let nlen = String.length n in
  5005. if plen <= nlen && String.sub n 0 plen = p then
  5006. begin
  5007. let fn_sep =
  5008. if Sys.os_type = "Win32" then
  5009. '\\'
  5010. else
  5011. '/'
  5012. in
  5013. let cutpoint = plen +
  5014. (if plen < nlen && n.[plen] = fn_sep then
  5015. 1
  5016. else
  5017. 0)
  5018. in
  5019. String.sub n cutpoint (nlen - cutpoint)
  5020. end
  5021. else
  5022. n
  5023. in
  5024. List.map (remove_prefix (Sys.getcwd ())) files
  5025. in
  5026. info
  5027. (f_ "Installing findlib library '%s'")
  5028. findlib_name;
  5029. let ocamlfind = ocamlfind () in
  5030. let commands =
  5031. split_install_command
  5032. ocamlfind
  5033. findlib_name
  5034. meta
  5035. files
  5036. in
  5037. List.iter
  5038. (OASISExec.run ~ctxt:!BaseContext.default ocamlfind)
  5039. commands;
  5040. BaseLog.register install_findlib_ev findlib_name
  5041. end;
  5042. (* Install data files *)
  5043. f_data ();
  5044. in
  5045. let group_libs, _, _ =
  5046. findlib_mapping pkg
  5047. in
  5048. (* We install libraries in groups *)
  5049. List.iter install_group_lib group_libs
  5050. in
  5051. let install_execs pkg =
  5052. let install_exec data_exec =
  5053. let cs, bs, exec =
  5054. !exec_hook data_exec
  5055. in
  5056. if var_choose bs.bs_install &&
  5057. BaseBuilt.is_built BaseBuilt.BExec cs.cs_name then
  5058. begin
  5059. let exec_libdir () =
  5060. Filename.concat
  5061. (libdir ())
  5062. pkg.name
  5063. in
  5064. BaseBuilt.fold
  5065. BaseBuilt.BExec
  5066. cs.cs_name
  5067. (fun () fn ->
  5068. install_file
  5069. ~tgt_fn:(cs.cs_name ^ ext_program ())
  5070. fn
  5071. bindir)
  5072. ();
  5073. BaseBuilt.fold
  5074. BaseBuilt.BExecLib
  5075. cs.cs_name
  5076. (fun () fn ->
  5077. install_file
  5078. fn
  5079. exec_libdir)
  5080. ();
  5081. install_data
  5082. bs.bs_path
  5083. bs.bs_data_files
  5084. (Filename.concat
  5085. (datarootdir ())
  5086. pkg.name)
  5087. end
  5088. in
  5089. List.iter
  5090. (function
  5091. | Executable (cs, bs, exec)->
  5092. install_exec (cs, bs, exec)
  5093. | _ ->
  5094. ())
  5095. pkg.sections
  5096. in
  5097. let install_docs pkg =
  5098. let install_doc data =
  5099. let cs, doc =
  5100. !doc_hook data
  5101. in
  5102. if var_choose doc.doc_install &&
  5103. BaseBuilt.is_built BaseBuilt.BDoc cs.cs_name then
  5104. begin
  5105. let tgt_dir =
  5106. OASISHostPath.of_unix (var_expand doc.doc_install_dir)
  5107. in
  5108. BaseBuilt.fold
  5109. BaseBuilt.BDoc
  5110. cs.cs_name
  5111. (fun () fn ->
  5112. install_file
  5113. fn
  5114. (fun () -> tgt_dir))
  5115. ();
  5116. install_data
  5117. Filename.current_dir_name
  5118. doc.doc_data_files
  5119. doc.doc_install_dir
  5120. end
  5121. in
  5122. List.iter
  5123. (function
  5124. | Doc (cs, doc) ->
  5125. install_doc (cs, doc)
  5126. | _ ->
  5127. ())
  5128. pkg.sections
  5129. in
  5130. install_libs pkg;
  5131. install_execs pkg;
  5132. install_docs pkg
  5133. (* Uninstall already installed data *)
  5134. let uninstall _ argv =
  5135. List.iter
  5136. (fun (ev, data) ->
  5137. if ev = install_file_ev then
  5138. begin
  5139. if OASISFileUtil.file_exists_case data then
  5140. begin
  5141. info
  5142. (f_ "Removing file '%s'")
  5143. data;
  5144. Sys.remove data
  5145. end
  5146. else
  5147. begin
  5148. warning
  5149. (f_ "File '%s' doesn't exist anymore")
  5150. data
  5151. end
  5152. end
  5153. else if ev = install_dir_ev then
  5154. begin
  5155. if Sys.file_exists data && Sys.is_directory data then
  5156. begin
  5157. if Sys.readdir data = [||] then
  5158. begin
  5159. info
  5160. (f_ "Removing directory '%s'")
  5161. data;
  5162. OASISFileUtil.rmdir ~ctxt:!BaseContext.default data
  5163. end
  5164. else
  5165. begin
  5166. warning
  5167. (f_ "Directory '%s' is not empty (%s)")
  5168. data
  5169. (String.concat
  5170. ", "
  5171. (Array.to_list
  5172. (Sys.readdir data)))
  5173. end
  5174. end
  5175. else
  5176. begin
  5177. warning
  5178. (f_ "Directory '%s' doesn't exist anymore")
  5179. data
  5180. end
  5181. end
  5182. else if ev = install_findlib_ev then
  5183. begin
  5184. info (f_ "Removing findlib library '%s'") data;
  5185. OASISExec.run ~ctxt:!BaseContext.default
  5186. (ocamlfind ()) ["remove"; data]
  5187. end
  5188. else
  5189. failwithf (f_ "Unknown log event '%s'") ev;
  5190. BaseLog.unregister ev data)
  5191. (* We process event in reverse order *)
  5192. (List.rev
  5193. (BaseLog.filter
  5194. [install_file_ev;
  5195. install_dir_ev;
  5196. install_findlib_ev]))
  5197. end
  5198. # 6243 "setup.ml"
  5199. module OCamlbuildCommon = struct
  5200. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/plugins/ocamlbuild/OCamlbuildCommon.ml" *)
  5201. (** Functions common to OCamlbuild build and doc plugin
  5202. *)
  5203. open OASISGettext
  5204. open BaseEnv
  5205. open BaseStandardVar
  5206. open OASISTypes
  5207. type extra_args = string list
  5208. let ocamlbuild_clean_ev = "ocamlbuild-clean"
  5209. let ocamlbuildflags =
  5210. var_define
  5211. ~short_desc:(fun () -> "OCamlbuild additional flags")
  5212. "ocamlbuildflags"
  5213. (fun () -> "")
  5214. (** Fix special arguments depending on environment *)
  5215. let fix_args args extra_argv =
  5216. List.flatten
  5217. [
  5218. if (os_type ()) = "Win32" then
  5219. [
  5220. "-classic-display";
  5221. "-no-log";
  5222. "-no-links";
  5223. "-install-lib-dir";
  5224. (Filename.concat (standard_library ()) "ocamlbuild")
  5225. ]
  5226. else
  5227. [];
  5228. if not (bool_of_string (is_native ())) || (os_type ()) = "Win32" then
  5229. [
  5230. "-byte-plugin"
  5231. ]
  5232. else
  5233. [];
  5234. args;
  5235. if bool_of_string (debug ()) then
  5236. ["-tag"; "debug"]
  5237. else
  5238. [];
  5239. if bool_of_string (profile ()) then
  5240. ["-tag"; "profile"]
  5241. else
  5242. [];
  5243. OASISString.nsplit (ocamlbuildflags ()) ' ';
  5244. Array.to_list extra_argv;
  5245. ]
  5246. (** Run 'ocamlbuild -clean' if not already done *)
  5247. let run_clean extra_argv =
  5248. let extra_cli =
  5249. String.concat " " (Array.to_list extra_argv)
  5250. in
  5251. (* Run if never called with these args *)
  5252. if not (BaseLog.exists ocamlbuild_clean_ev extra_cli) then
  5253. begin
  5254. OASISExec.run ~ctxt:!BaseContext.default
  5255. (ocamlbuild ()) (fix_args ["-clean"] extra_argv);
  5256. BaseLog.register ocamlbuild_clean_ev extra_cli;
  5257. at_exit
  5258. (fun () ->
  5259. try
  5260. BaseLog.unregister ocamlbuild_clean_ev extra_cli
  5261. with _ ->
  5262. ())
  5263. end
  5264. (** Run ocamlbuild, unregister all clean events *)
  5265. let run_ocamlbuild args extra_argv =
  5266. (* TODO: enforce that target in args must be UNIX encoded i.e. toto/index.html
  5267. *)
  5268. OASISExec.run ~ctxt:!BaseContext.default
  5269. (ocamlbuild ()) (fix_args args extra_argv);
  5270. (* Remove any clean event, we must run it again *)
  5271. List.iter
  5272. (fun (e, d) -> BaseLog.unregister e d)
  5273. (BaseLog.filter [ocamlbuild_clean_ev])
  5274. (** Determine real build directory *)
  5275. let build_dir extra_argv =
  5276. let rec search_args dir =
  5277. function
  5278. | "-build-dir" :: dir :: tl ->
  5279. search_args dir tl
  5280. | _ :: tl ->
  5281. search_args dir tl
  5282. | [] ->
  5283. dir
  5284. in
  5285. search_args "_build" (fix_args [] extra_argv)
  5286. end
  5287. module OCamlbuildPlugin = struct
  5288. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/plugins/ocamlbuild/OCamlbuildPlugin.ml" *)
  5289. (** Build using ocamlbuild
  5290. @author Sylvain Le Gall
  5291. *)
  5292. open OASISTypes
  5293. open OASISGettext
  5294. open OASISUtils
  5295. open OASISString
  5296. open BaseEnv
  5297. open OCamlbuildCommon
  5298. open BaseStandardVar
  5299. open BaseMessage
  5300. let cond_targets_hook =
  5301. ref (fun lst -> lst)
  5302. let build extra_args pkg argv =
  5303. (* Return the filename in build directory *)
  5304. let in_build_dir fn =
  5305. Filename.concat
  5306. (build_dir argv)
  5307. fn
  5308. in
  5309. (* Return the unix filename in host build directory *)
  5310. let in_build_dir_of_unix fn =
  5311. in_build_dir (OASISHostPath.of_unix fn)
  5312. in
  5313. let cond_targets =
  5314. List.fold_left
  5315. (fun acc ->
  5316. function
  5317. | Library (cs, bs, lib) when var_choose bs.bs_build ->
  5318. begin
  5319. let evs, unix_files =
  5320. BaseBuilt.of_library
  5321. in_build_dir_of_unix
  5322. (cs, bs, lib)
  5323. in
  5324. let tgts =
  5325. List.flatten
  5326. (List.filter
  5327. (fun l -> l <> [])
  5328. (List.map
  5329. (List.filter
  5330. (fun fn ->
  5331. ends_with ~what:".cma" fn
  5332. || ends_with ~what:".cmxs" fn
  5333. || ends_with ~what:".cmxa" fn
  5334. || ends_with ~what:(ext_lib ()) fn
  5335. || ends_with ~what:(ext_dll ()) fn))
  5336. unix_files))
  5337. in
  5338. match tgts with
  5339. | _ :: _ ->
  5340. (evs, tgts) :: acc
  5341. | [] ->
  5342. failwithf
  5343. (f_ "No possible ocamlbuild targets for library %s")
  5344. cs.cs_name
  5345. end
  5346. | Object (cs, bs, obj) when var_choose bs.bs_build ->
  5347. begin
  5348. let evs, unix_files =
  5349. BaseBuilt.of_object
  5350. in_build_dir_of_unix
  5351. (cs, bs, obj)
  5352. in
  5353. let tgts =
  5354. List.flatten
  5355. (List.filter
  5356. (fun l -> l <> [])
  5357. (List.map
  5358. (List.filter
  5359. (fun fn ->
  5360. ends_with ".cmo" fn
  5361. || ends_with ".cmx" fn))
  5362. unix_files))
  5363. in
  5364. match tgts with
  5365. | _ :: _ ->
  5366. (evs, tgts) :: acc
  5367. | [] ->
  5368. failwithf
  5369. (f_ "No possible ocamlbuild targets for object %s")
  5370. cs.cs_name
  5371. end
  5372. | Executable (cs, bs, exec) when var_choose bs.bs_build ->
  5373. begin
  5374. let evs, unix_exec_is, unix_dll_opt =
  5375. BaseBuilt.of_executable
  5376. in_build_dir_of_unix
  5377. (cs, bs, exec)
  5378. in
  5379. let target ext =
  5380. let unix_tgt =
  5381. (OASISUnixPath.concat
  5382. bs.bs_path
  5383. (OASISUnixPath.chop_extension
  5384. exec.exec_main_is))^ext
  5385. in
  5386. let evs =
  5387. (* Fix evs, we want to use the unix_tgt, without copying *)
  5388. List.map
  5389. (function
  5390. | BaseBuilt.BExec, nm, lst when nm = cs.cs_name ->
  5391. BaseBuilt.BExec, nm,
  5392. [[in_build_dir_of_unix unix_tgt]]
  5393. | ev ->
  5394. ev)
  5395. evs
  5396. in
  5397. evs, [unix_tgt]
  5398. in
  5399. (* Add executable *)
  5400. let acc =
  5401. match bs.bs_compiled_object with
  5402. | Native ->
  5403. (target ".native") :: acc
  5404. | Best when bool_of_string (is_native ()) ->
  5405. (target ".native") :: acc
  5406. | Byte
  5407. | Best ->
  5408. (target ".byte") :: acc
  5409. in
  5410. acc
  5411. end
  5412. | Library _ | Object _ | Executable _ | Test _
  5413. | SrcRepo _ | Flag _ | Doc _ ->
  5414. acc)
  5415. []
  5416. (* Keep the pkg.sections ordered *)
  5417. (List.rev pkg.sections);
  5418. in
  5419. (* Check and register built files *)
  5420. let check_and_register (bt, bnm, lst) =
  5421. List.iter
  5422. (fun fns ->
  5423. if not (List.exists OASISFileUtil.file_exists_case fns) then
  5424. failwithf
  5425. (fn_
  5426. "Expected built file %s doesn't exist."
  5427. "None of expected built files %s exists."
  5428. (List.length fns))
  5429. (String.concat (s_ " or ") (List.map (Printf.sprintf "'%s'") fns)))
  5430. lst;
  5431. (BaseBuilt.register bt bnm lst)
  5432. in
  5433. (* Run the hook *)
  5434. let cond_targets = !cond_targets_hook cond_targets in
  5435. (* Run a list of target... *)
  5436. run_ocamlbuild (List.flatten (List.map snd cond_targets) @ extra_args) argv;
  5437. (* ... and register events *)
  5438. List.iter check_and_register (List.flatten (List.map fst cond_targets))
  5439. let clean pkg extra_args =
  5440. run_clean extra_args;
  5441. List.iter
  5442. (function
  5443. | Library (cs, _, _) ->
  5444. BaseBuilt.unregister BaseBuilt.BLib cs.cs_name
  5445. | Executable (cs, _, _) ->
  5446. BaseBuilt.unregister BaseBuilt.BExec cs.cs_name;
  5447. BaseBuilt.unregister BaseBuilt.BExecLib cs.cs_name
  5448. | _ ->
  5449. ())
  5450. pkg.sections
  5451. end
  5452. module OCamlbuildDocPlugin = struct
  5453. (* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/plugins/ocamlbuild/OCamlbuildDocPlugin.ml" *)
  5454. (* Create documentation using ocamlbuild .odocl files
  5455. @author Sylvain Le Gall
  5456. *)
  5457. open OASISTypes
  5458. open OASISGettext
  5459. open OASISMessage
  5460. open OCamlbuildCommon
  5461. open BaseStandardVar
  5462. type run_t =
  5463. {
  5464. extra_args: string list;
  5465. run_path: unix_filename;
  5466. }
  5467. let doc_build run pkg (cs, doc) argv =
  5468. let index_html =
  5469. OASISUnixPath.make
  5470. [
  5471. run.run_path;
  5472. cs.cs_name^".docdir";
  5473. "index.html";
  5474. ]
  5475. in
  5476. let tgt_dir =
  5477. OASISHostPath.make
  5478. [
  5479. build_dir argv;
  5480. OASISHostPath.of_unix run.run_path;
  5481. cs.cs_name^".docdir";
  5482. ]
  5483. in
  5484. run_ocamlbuild (index_html :: run.extra_args) argv;
  5485. List.iter
  5486. (fun glb ->
  5487. BaseBuilt.register
  5488. BaseBuilt.BDoc
  5489. cs.cs_name
  5490. [OASISFileUtil.glob ~ctxt:!BaseContext.default
  5491. (Filename.concat tgt_dir glb)])
  5492. ["*.html"; "*.css"]
  5493. let doc_clean run pkg (cs, doc) argv =
  5494. run_clean argv;
  5495. BaseBuilt.unregister BaseBuilt.BDoc cs.cs_name
  5496. end
  5497. # 6616 "setup.ml"
  5498. open OASISTypes;;
  5499. let setup_t =
  5500. {
  5501. BaseSetup.configure = InternalConfigurePlugin.configure;
  5502. build = OCamlbuildPlugin.build [];
  5503. test = [];
  5504. doc = [];
  5505. install = InternalInstallPlugin.install;
  5506. uninstall = InternalInstallPlugin.uninstall;
  5507. clean = [OCamlbuildPlugin.clean];
  5508. clean_test = [];
  5509. clean_doc = [];
  5510. distclean = [];
  5511. distclean_test = [];
  5512. distclean_doc = [];
  5513. package =
  5514. {
  5515. oasis_version = "0.4";
  5516. ocaml_version = None;
  5517. findlib_version = None;
  5518. alpha_features = ["stdfiles_markdown"; "compiled_setup_ml"];
  5519. beta_features = [];
  5520. name = "OcLaunch";
  5521. version = "0.2.1-dev";
  5522. license =
  5523. OASISLicense.DEP5License
  5524. (OASISLicense.DEP5Unit
  5525. {
  5526. OASISLicense.license = "CeCILL";
  5527. excption = None;
  5528. version = OASISLicense.NoVersion
  5529. });
  5530. license_file = Some "LICENSE";
  5531. copyrights = ["(C) 2014-2015 Joly Cl\195\169ment"];
  5532. maintainers = ["Joly Cl\195\169ment <leowzukw@vmail.me>"];
  5533. authors = ["Joly Cl\195\169ment <leowzukw@vmail.me>"];
  5534. homepage = Some "http://www.oclaunch.tuxfamily.org";
  5535. synopsis = "Launch commands automatically";
  5536. description =
  5537. Some
  5538. [
  5539. OASISText.Para
  5540. "OcLaunch is a command-line tool to launch successively (each time the program is called) commands. It is designed to be used with any program, interactive or not. Feedback is welcomed at leowzukw@vmail.me. Help at https://gitlab.com/WzukW/oclaunch/wikis/home."
  5541. ];
  5542. categories = [];
  5543. conf_type = (`Configure, "internal", Some "0.4");
  5544. conf_custom =
  5545. {
  5546. pre_command = [(OASISExpr.EBool true, None)];
  5547. post_command = [(OASISExpr.EBool true, None)]
  5548. };
  5549. build_type = (`Build, "ocamlbuild", Some "0.4");
  5550. build_custom =
  5551. {
  5552. pre_command =
  5553. [
  5554. (OASISExpr.EBool true,
  5555. Some (("echo", ["\"Atdgen"; "executed\""])))
  5556. ];
  5557. post_command = [(OASISExpr.EBool true, None)]
  5558. };
  5559. install_type = (`Install, "internal", Some "0.4");
  5560. install_custom =
  5561. {
  5562. pre_command = [(OASISExpr.EBool true, None)];
  5563. post_command = [(OASISExpr.EBool true, None)]
  5564. };
  5565. uninstall_custom =
  5566. {
  5567. pre_command = [(OASISExpr.EBool true, None)];
  5568. post_command = [(OASISExpr.EBool true, None)]
  5569. };
  5570. clean_custom =
  5571. {
  5572. pre_command = [(OASISExpr.EBool true, None)];
  5573. post_command = [(OASISExpr.EBool true, None)]
  5574. };
  5575. distclean_custom =
  5576. {
  5577. pre_command = [(OASISExpr.EBool true, None)];
  5578. post_command = [(OASISExpr.EBool true, None)]
  5579. };
  5580. files_ab = [];
  5581. sections =
  5582. [
  5583. Executable
  5584. ({
  5585. cs_name = "oclaunch";
  5586. cs_data = PropList.Data.create ();
  5587. cs_plugin_data = []
  5588. },
  5589. {
  5590. bs_build = [(OASISExpr.EBool true, true)];
  5591. bs_install = [(OASISExpr.EBool true, true)];
  5592. bs_path = "src";
  5593. bs_compiled_object = Best;
  5594. bs_build_depends =
  5595. [
  5596. FindlibPackage ("core", None);
  5597. FindlibPackage ("atdgen", None);
  5598. FindlibPackage ("threads", None)
  5599. ];
  5600. bs_build_tools =
  5601. [ExternalTool "ocamlbuild"; ExternalTool "camlp4o"];
  5602. bs_c_sources = [];
  5603. bs_data_files = [];
  5604. bs_ccopt = [(OASISExpr.EBool true, [])];
  5605. bs_cclib = [(OASISExpr.EBool true, [])];
  5606. bs_dlllib = [(OASISExpr.EBool true, [])];
  5607. bs_dllpath = [(OASISExpr.EBool true, [])];
  5608. bs_byteopt = [(OASISExpr.EBool true, [])];
  5609. bs_nativeopt = [(OASISExpr.EBool true, [])]
  5610. },
  5611. {exec_custom = false; exec_main_is = "oclaunch.ml"})
  5612. ];
  5613. plugins =
  5614. [
  5615. (`Extra, "StdFiles", Some "0.4");
  5616. (`Extra, "DevFiles", Some "0.4")
  5617. ];
  5618. disable_oasis_section = [];
  5619. schema_data = PropList.Data.create ();
  5620. plugin_data = []
  5621. };
  5622. oasis_fn = Some "_oasis";
  5623. oasis_version = "0.4.4";
  5624. oasis_digest = Some "\024l\178~\130\221\217\247\tA^\152\147!\030\005";
  5625. oasis_exec = None;
  5626. oasis_setup_args = [];
  5627. setup_update = false
  5628. };;
  5629. let setup () = BaseSetup.setup setup_t;;
  5630. # 6753 "setup.ml"
  5631. (* OASIS_STOP *)
  5632. let () = setup ();;