Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] encap and build.r

From: atruter:hih:au at: 30-Aug-2002 12:21

The following script tries to take the hassle out of building an optimised encap program. I had several goals / constraints in mind: 1. My applications typically have a master script that issues a "do %xxx.r" for each required "module". 2. I don't want to have to edit out these statements when running encap (otherwise the generated executable will fail trying to find the underlying source files). 3. I want to encap source that has all non-esential text (eg. comments, redundant whitespace, etc) removed. 4. While the build script and encap reside in the same directory, the file (and its modules, if any) probably reside in another directory. The following script was largely inspired / based on the work Carl did in build-pack.r <build.r> REBOL [] ; Obtain files to build if none? attempt [build-file: request-file/only/title/filter "Select file to build" "Open" ["*.r"]] [ alert "Build file not specified." quit ] path: first split-path build-file header: first load/header build-file if none? header/Needs [header/Needs: copy []] insert tail header/Needs second split-path build-file ; Merge source code code: make string! 128000 foreach file header/Needs [ script: load/all path/:file insert tail code mold/only skip script 2 ; skip REBOL header ] src-size: length? code ; Generate compressed copy system/options/binary-base: 64 code: compress trim/lines code src-file: replace copy build-file %.r %.src save/header src-file compose [do decompress (code)] compose/deep [Encap: [no-network secure none title (header/Title)]] ; Encap compressed file exe-file: replace copy build-file %.r %.exe call reform ["rebolve1003.exe" src-file exe-file] alert reform ["Compressed" src-size "bytes to" length? code "bytes."] </build .r> The following scripts outline the practical implementation of this: <build-test.r> REBOL [ Title: "Build Test" Needs: [%a.r %b.r %c.r] ] if not none? attempt [system/script/header/Needs] [ foreach script system/script/header/Needs [do script] ] wait 2 </build-test.r> <a.r> REBOL [] print "A" </a.r> <b.r> REBOL [] print "B" </b.r> <c.r> REBOL [] print "C" </c.r> Running build-test.r and build-test.exe should yield the exact same results. I have successfully used this on a fairly complex 148K app with no issues to date (all of two days that is ;) ). A good approach or not? (I was toying with the idea of further reducing the source size by tokensing user-defined words, but the cost / benefit didn't seem justified). Regards, Ashley *****************Privacy, Confidentiality & Liability Notice ************ This email is intended for the named recipient only. The information contained in this message may be confidential, or commercially sensitive. If you are not the intended recipient you must not reproduce or distribute any part of this email, disclose its contents to any other party, or take any action in reliance on it. If you have received this email in error, please contact the sender immediately. Please delete this message from your computer. You must scan this email and any attached files for viruses. The company accepts no liability for any loss, damage or consequence, whether caused by our own negligence or not, resulting directly or indirectly from the use of any attached files. Any views expressed in this Communication are those of the individual sender, except where the sender specifically states them to be the views of the Company. **************************************************************************