A little project

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Feb 3 19:01:41 PST 2010


I'd like to propose a small project suggested by Walter. If anyone could 
take this up, it would be great. The project is a small utility program 
that could be a good complement to the likes of rdmd.

The program allows you to play with entire D projects as zip files. It 
takes a zip file, extracts the files if needed, and builds it. Many 
improvements can be easily imagined. I paste below a rudimentary 
prototype that I wrote for Linux. It has many shortcomings; don't hold 
them against me, I wrote that script in less time than it takes "retard" 
to switch from smug to sarcastic.

If anyone would like to take this over, that would be great. Thanks!


Andrei




#!/usr/bin/env rdmd

// Accepted extensions
auto extensions = [ "d", "di", "a", "o" ];

int main(string[] args) {
     // The one and only parameter is the zip file
     auto zip = args[1];
     if (!exists(zip)) {
         stderr.writeln("Zip file missing: `", zip, "'");
         stderr.writeln("Usage: dmdz file.zip");
         return 1;
     }
     // Target directory
     auto tgt = "/tmp/" ~ zip;
     // Binary result is the name of the zip without the .zip
     auto bin = replace(zip, ".zip", "");

     // Was the zip file already extracted? If not, extract it
     if (lastModified(zip) >= lastModified(tgt, d_time.min)) {
         system("mkdir --parents " ~ tgt);
         system("unzip " ~ zip " -d " tgt ~ " >/dev/null");
     }

     // Compile all files with accepted extensions
     auto find = "find . -type f -false ";
     foreach (ext; extensions) {
         find ~= " -or -iname '*." ~ ext ~ "'";
     }
     return system("cd " ~ tgt ~ " && dmd -of" ~ bin ~ " `eval " ~ find 
~ "`");
}



More information about the Digitalmars-d mailing list