checkPackages

Utility for checking libsheepy version used when compiling the packages in local shpPackages
git clone https://noulin.net/git/checkPackages.git
Log | Files | Refs

checkPackages.c (2610B)


      1 #! /usr/bin/env sheepy
      2 #include "libsheepyObject.h"
      3 
      4 #define shpPDir "shpPackages"
      5 
      6 #define header "\
      7 #! /usr/bin/env sheepy\n\
      8 #include \"libsheepyObject.h\"\n\
      9 "
     10 // add includes
     11 #define mainc "\
     12 \n\
     13 int main(int ARGC, char** ARGV) {\n\
     14 \n\
     15   char *cwd;\n\
     16 \n\
     17 "
     18 #define recompileTemplate "\
     19   if (!isClassTemplateCompiledWithCurrentLisheepyVersion) {\n\
     20     cwd = getCwd();\n\
     21     pError0(chDir(\"shpPackages/classTemplate\"));\n\
     22     pErrorNot0(system(\"sheepy -d ; sheepy -l\"));\n\
     23     pError0(chDir(cwd));\n\
     24   }\n\
     25 "
     26 #define footer "\
     27 \n\
     28 }\
     29 "
     30 
     31 #define recompileC "recompilePackages.c"
     32 
     33 int main(int ARGC, char** ARGV) {
     34 
     35   initLibsheepy(ARGV[0]);
     36   setLogMode(LOG_PROGNDATE);
     37   disableLibsheepyErrorLogs;
     38 
     39   bool atLeastOnePackage = false;
     40   char **recompile  = NULL;
     41   char **incs       = NULL;
     42   char **recomp     = NULL;
     43 
     44   var dirs          = walkDirDir(shpPDir);
     45 
     46   if (!dirs) {
     47     logC("Directory not found.");
     48     XFAILURE;
     49   }
     50 
     51   forEachS(dirs, P) {
     52     if (not endsWithG(P, shpPDir)) {
     53       var s = catS(P,"/package.yml");
     54       createSmallJson(j);
     55       pErrorNULL(readFileG(&j, s));
     56 
     57       var b = getG(&j, rtChar, "bin");
     58 
     59       if (b) {
     60         var c = catS(P,"/", b);
     61         pError0(normalizePathG(&c));
     62 
     63         //logVarG(c);
     64 
     65         var ld = readDir(P);
     66 
     67         bool foundAOrSo = false;
     68         forEachS(ld, fl) {
     69           if (endsWithG(fl, ".a") or endsWithG(fl, ".so")) {
     70             foundAOrSo = true;
     71             break;
     72           }
     73         }
     74 
     75         if (foundAOrSo) {
     76           if (!atLeastOnePackage) {
     77             pErrorNULL(pushG(&recompile, header));
     78             atLeastOnePackage = true;
     79           }
     80           pErrorNULL(setG(c, -1, 'h'));
     81           var ic = catS("#include \"",c,"\"");
     82           pErrorNULL(pushNFreeG(&incs, ic));
     83 
     84           var base = basename(P);
     85           var rec  = replaceS(recompileTemplate, "classTemplate", base, 1);
     86           toUpper(base[0]);
     87           pErrorNULL(iReplaceS(&rec, "ClassTemplate", base, 1));
     88           pErrorNULL(pushNFreeG(&recomp, rec));
     89         }
     90 
     91         freeG(ld);
     92         free(c);
     93       }
     94 
     95       freeG(&j);
     96       free(s);
     97     }
     98   }
     99 
    100   freeG(dirs);
    101 
    102   if (not isEmptyG(recompile)) {
    103     pErrorNULL(appendG(&recompile, incs));
    104     pErrorNULL(pushG(&recompile, mainc));
    105     pErrorNULL(appendG(&recompile, recomp));
    106     pErrorNULL(pushG(&recompile, footer));
    107     pError0(writeFileG(recompile, recompileC));
    108     pError0(fileChmod(recompileC, 0711));
    109     freeG(recompile);
    110     free(incs);
    111     free(recomp);
    112     pErrorNot0(logSystemf("./%s", recompileC));
    113     pError0(rmAll(recompileC));
    114   }
    115 }
    116 // vim: set expandtab ts=2 sw=2: