Changeset 7449

Show
Ignore:
Timestamp:
02/25/07 14:03:31 (21 months ago)
Author:
jburke
Message:

(merge from 0.4 branch) References #2366. Added a compress option to the web build.

Location:
trunk/buildscripts
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/buildscripts/buildUtil.js

    r7415 r7449  
    405405        fileContents = String(fileContents); 
    406406         
    407         var modifiedContents = null; 
     407        var modifiedContents = fileContents; 
    408408         
    409409        if(fileContents.match(buildUtil.globalRequireLocalizationRegExp)){ 
     
    858858} 
    859859 
     860buildUtil.optimizeJs = function(/*String fileName*/fileName, /*String*/fileContents, /*String*/copyright, /*boolean*/doCompression){ 
     861        //summary: either strips comments from string or compresses it. 
     862 
     863        //Look for copyright. If so, maintain it. 
     864        //If no copyright text passed in, assume want a really stripped 
     865        //version. 
     866        copyright = copyright || ""; 
     867        var copyrightText = ""; 
     868        if(copyright){ 
     869                var singleLineMatches = fileContents.match(/\/\/.*copyright.*$/gi); 
     870                 
     871                //Get rid of cr, lf, since it messes up matching. 
     872                var copyrightFileContents = fileContents.replace(/\r/g, "__DOJOCARRIAGERETURN__").replace(/\n/g, "__DOJONEWLINE__"); 
     873                var multiLineMatches = copyrightFileContents.match(/\/\*.*?copyright.*?\*\//gi); 
     874         
     875                //Finalize copyright notice. 
     876                if((multiLineMatches && multiLineMatches.length > 0) || (singleLineMatches && singleLineMatches.length > 0)){ 
     877                        if(multiLineMatches && multiLineMatches.length > 0){ 
     878                                copyrightText += multiLineMatches.join("\r\n").replace(/__DOJOCARRIAGERETURN__/g, "\r").replace(/__DOJONEWLINE__/g, "\n"); 
     879                        }                                        
     880                        if(singleLineMatches && singleLineMatches.length > 0){ 
     881                                copyrightText += singleLineMatches.join("\r\n"); 
     882                        } 
     883                        copyrightText += buildUtil.getLineSeparator(); 
     884                }else{ 
     885                        copyrightText = copyright; 
     886                } 
     887        } 
     888 
     889        //Use rhino to help do minifying/compressing. 
     890        var context = Packages.org.mozilla.javascript.Context.enter(); 
     891        try{ 
     892                // Use the interpreter for interactive input (copied this from Main rhino class). 
     893                context.setOptimizationLevel(-1); 
     894                 
     895                var script = context.compileString(fileContents, fileName, 1, null); 
     896                if(doCompression){ 
     897                        //Apply compression using custom compression call in Dojo-modified rhino. 
     898                        fileContents = new String(context.compressScript(script, 0, fileContents, 1)); 
     899                }else{ 
     900                        //Strip comments 
     901                        fileContents = new String(context.decompileScript(script, 0)); 
     902                        //Replace the spaces with tabs. 
     903                        //Ideally do this in the pretty printer rhino code. 
     904                        fileContents = fileContents.replace(/    /g, "\t"); 
     905                } 
     906        }finally{ 
     907                Packages.org.mozilla.javascript.Context.exit(); 
     908        } 
     909 
     910        return copyrightText + fileContents; 
     911} 
     912 
    860913buildUtil.stripComments = function(/*String*/startDir, /*boolean*/suppressDojoCopyright){ 
    861914        //summary: strips the JS comments from all the files in "startDir", and all subdirectories. 
     
    875928                                var fileContents = new String(buildUtil.readFile(fileList[i])); 
    876929 
    877                                 //Look for copyright. If so, maintain it. 
    878                                 var singleLineMatches = fileContents.match(/\/\/.*copyright.*$/gi); 
    879                                  
    880                                 //Get rid of cr, lf, since it messes up matching. 
    881                                 copyrightFileContents = fileContents.replace(/\r/g, "__DOJOCARRIAGERETURN__").replace(/\n/g, "__DOJONEWLINE__"); 
    882                                 var multiLineMatches = copyrightFileContents.match(/\/\*.*?copyright.*?\*\//gi); 
    883  
    884                                 //Finalize copyright notice. 
    885                                 var copyrightText = ""; 
    886                                 if((multiLineMatches && multiLineMatches.length > 0) || (singleLineMatches && singleLineMatches.length > 0)){ 
    887                                         if(multiLineMatches && multiLineMatches.length > 0){ 
    888                                                 copyrightText += multiLineMatches.join("\r\n").replace(/__DOJOCARRIAGERETURN__/g, "\r").replace(/__DOJONEWLINE__/g, "\n"); 
    889                                         }                                        
    890                                         if(singleLineMatches && singleLineMatches.length > 0){ 
    891                                                 copyrightText += singleLineMatches.join("\r\n"); 
    892                                         } 
    893                                         copyrightText += buildUtil.getLineSeparator(); 
    894                                 }else{ 
    895                                         copyrightText = copyright; 
     930                                //Do comment removal. 
     931                                try{ 
     932                                        fileContents = buildUtil.optimizeJs(fileList[i], fileContents, copyright, false); 
     933                                }catch(e){ 
     934                                        print("Could not strip comments for file: " + fileList[i] + ", error: " + e); 
    896935                                } 
    897936 
    898                                 //Remove whitespace. 
    899                                 var context = Packages.org.mozilla.javascript.Context.enter(); 
    900                                 try{ 
    901                                         // Use the interpreter for interactive input (copied this from Main rhino class). 
    902                                         context.setOptimizationLevel(-1); 
    903                                          
    904                                         var script = context.compileString(fileContents, fileList[i], 1, null); 
    905                                         fileContents = new String(context.decompileScript(script, 0)); 
    906                                 }catch(e){ 
    907                                         print("Could not strip comments for file: " + fileList[i]); 
    908                                 }finally{ 
    909                                         Packages.org.mozilla.javascript.Context.exit(); 
    910                                 } 
    911                                  
    912                                 //Replace the spaces with tabs. 
    913                                 //Ideally do this in the pretty printer rhino code. 
    914                                 fileContents = fileContents.replace(/    /g, "\t"); 
    915  
    916937                                //Write out the file with appropriate copyright. 
    917                                 buildUtil.saveUtf8File(fileList[i], copyrightText + fileContents); 
    918                         } 
    919                 } 
    920         } 
    921 } 
    922  
     938                                buildUtil.saveUtf8File(fileList[i], fileContents); 
     939                        } 
     940                } 
     941        } 
     942} 
     943 
     944 
  • trunk/buildscripts/makeDojoJsWeb.js

    r7427 r7449  
    88var version = new String(arguments[2]); 
    99var xdDojoUrl = new String(arguments[3]); 
     10var doCompression = new String(arguments[4]); 
     11 
     12if(typeof(doCompression) != "undefined" && doCompression == "true"){ 
     13        doCompression = true; 
     14}else{ 
     15        doCompression = false; 
     16} 
    1017 
    1118depList = depList.split(","); 
     
    4653        dojo.require("dojo.string.extras"); 
    4754         
    48         var contents = buildUtil.makeDojoJs(dependencyResult, version).dojoContents; 
    49         var prefixes = [["dojo", "src"]]; 
     55        var contents = ""; 
     56        try{ 
     57                contents = buildUtil.makeDojoJs(dependencyResult, version).dojoContents; 
     58                var prefixes = [["dojo", "src"]]; 
     59         
     60                //Make sure any dojo.requireLocalization calls are modified 
     61                //so that they inform the loader of valid locales that can be loaded. 
     62                contents = buildUtil.modifyRequireLocalization(contents, djConfig.baseRelativePath, prefixes); 
     63                 
     64                //Convert requireLocalization calls into xdRequireLocalization calls. 
     65                contents = contents.replace(/dojo\.requireLocalization\s*\(/g, "dojo.xdRequireLocalization("); 
     66                 
     67                //Intern strings. 
     68                contents = buildUtil.interningRegexpMagic("xdomain", contents, djConfig.baseRelativePath, prefixes, [], true); 
     69                 
     70                //Set the xdomain dojo url 
     71                if(xdDojoUrl){ 
     72                        contents = buildUtilXd.setXdDojoConfig(contents, xdDojoUrl); 
     73                } 
    5074 
    51         //Make sure any dojo.requireLocalization calls are modified 
    52         //so that they inform the loader of valid locales that can be loaded. 
    53         contents = buildUtil.modifyRequireLocalization(contents, djConfig.baseRelativePath, prefixes); 
    54          
    55         //Convert requireLocalization calls into xdRequireLocalization calls. 
    56         contents = contents.replace(/dojo\.requireLocalization\s*\(/g, "dojo.xdRequireLocalization("); 
    57          
    58         //Add copyright, and intern strings. 
    59         contents = new String(buildUtil.readFile("copyright.txt")) + buildUtil.interningRegexpMagic("xdomain", contents, djConfig.baseRelativePath, prefixes, [], true); 
    60          
    61         if(xdDojoUrl){ 
    62                 contents = buildUtilXd.setXdDojoConfig(contents, xdDojoUrl); 
     75                //Compress code, if desired. 
     76                if(doCompression){ 
     77                        contents = buildUtil.optimizeJs("dojo.js", contents, "", doCompression); 
     78                } 
     79 
     80                //Add copyright 
     81                contents = new String(buildUtil.readFile("copyright.txt")) 
     82                        + new String(buildUtil.readFile("build_notice.txt")) 
     83                        + contents; 
     84        }catch(e){ 
     85                contents = "dojo.js build error: " + e;  
    6386        } 
    64          
     87 
    6588        print(contents); 
    6689} 
  • trunk/buildscripts/webbuild.php

    r7279 r7449  
    55        $version = isset($_POST['version']) ? $_POST['version'] : '0.0.0dev'; 
    66        $xdDojoUrl = isset($_POST['xdDojoUrl']) ? $_POST['xdDojoUrl'] : ''; 
     7        $doCompression = isset($_POST['doCompression']) ? $_POST['doCompression'] : 'false'; 
    78 
    89        if(!isset($depList)){ 
     
    1617                header("Content-disposition: attachment; filename=dojo.js"); 
    1718                 
    18                 $dojoContents = `/usr/bin/java -jar $buildScriptsDir/lib/custom_rhino.jar $buildScriptsDir/makeDojoJsWeb.js $depList $provideList $version $xdDojoUrl`; 
     19                $dojoContents = `/usr/bin/java -jar $buildScriptsDir/lib/custom_rhino.jar $buildScriptsDir/makeDojoJsWeb.js $depList $provideList $version $xdDojoUrl $doCompression`; 
    1920 
    2021                print($dojoContents); 
  • trunk/buildscripts/webbuild/index.html

    r7287 r7449  
    133133                depListForm.version.value = version; 
    134134                depListForm.xdDojoUrl.value = xdDojoUrl; 
     135                depListForm.doCompression.value = document.masterForm.doCompression[1].checked ? true : false; 
    135136 
    136137                //reset the hidden frame so we can do another build. 
     
    375376 
    376377<table id="outerTable"> 
    377         <tr><td colspan=3><h2>Dojo Builder (highly experimental) 
     378        <tr><td colspan=3><h2>Dojo Builder (experimental) 
    378379                                                        <div id="version">for version @VERSION@</div> 
    379380                                                </h2></td></tr> 
     
    527528                        <table class="labelRow_table" width=100% cellpadding=1><tr> 
    528529                                <td id="dependencyRow_Arrow" class="labelRow_toggler"><div id="dependencyRow_toggler" class="toggler">&ndash;</div></td> 
    529                                 <td id="dependencyRow_Title" class="labelRow_title">Modules to include:</td> 
     530                                <td id="dependencyRow_Title" class="labelRow_title">Resources to include:</td> 
    530531                                <td id="dependencyRow_Arrow" class="labelRow_values"></td> 
    531532                        </tr></table> 
     
    548549                                        <td class="tree"><div id="treeContainer"></div></td> 
    549550                                </tr>                    
    550                                 <tr><td class="underLabel">Enter module names separated by line returns and/or commas. <br>  
    551                                                                                         "Quotes" around module names are optional.</td> 
     551                                <tr><td class="underLabel">Enter resource names separated by line returns and/or commas. <br>  
     552                                                                                        "Quotes" around resource names are optional.</td> 
    552553                                        <td class="colSpacer">&nbsp;</td> 
    553554                                        <td class="underLabel">Double click items above to add them to the list.</td> 
     
    558559        </tr> 
    559560 
    560         <tr style="display:none"><td colspan=3 class="rowSpacer">&nbsp;</td></tr> 
    561         <tr style="display:none"><td colspan=3 class="labelRow outsetBorder" id="optionsRow_label" onclick="toggleRow('optionsRow')"> 
     561        <tr><td colspan=3 class="rowSpacer">&nbsp;</td></tr> 
     562        <tr><td colspan=3 class="labelRow outsetBorder" id="optionsRow_label" onclick="toggleRow('optionsRow')"> 
    562563                        <table class="labelRow_table" width=100% cellpadding=1><tr> 
    563564                                <td id="optionsRow_Arrow" class="labelRow_toggler"><div id="optionsRow_toggler" class="toggler">&ndash;</div></td> 
     
    567568                </td> 
    568569        </tr> 
    569         <tr id="optionsRow" style="display:none"> 
     570        <tr id="optionsRow"> 
    570571                <td class="colSpacer">&nbsp;</td> 
    571572                <td> 
    572573                        <table> 
    573                                 <tr><td class="fieldLabel">Profile name:</td> 
    574                                         <td class="field"><input id="profileName"></td> 
    575                                         <td class="colSpacer">&nbsp;</td> 
    576                                         <td class="check"><input id="tellDojo" type="checkbox"></td> 
    577                                         <td class="checkLabel"><label for="tellDojo">Let dojo know about this profile</label><br> 
    578                                                                                                                                         <span class="note">(anonymous, for usage pattern info gathering only)</span></td> 
    579                                 </tr>                    
    580  
    581                                 <tr><td class="check"><input id="strip" type="checkbox"></td> 
    582                                         <td class="checkLabel"><label for="strip">Strip whitespace</label></td> 
    583                                 </tr>                    
    584  
    585                                 <tr><td class="check"><input id="removeComments" type="checkbox"></td> 
    586                                         <td class="checkLabel"><label for="removeComments">Remove comments</label></td> 
    587                                 </tr>                    
    588  
    589                                 <tr><td class="check"><input id="compress" type="checkbox"></td> 
    590                                         <td class="checkLabel"><label for="compress">Compress the contents (very slow)</label></td> 
    591                                 </tr>                    
     574                                <tr><td class="radio"><input id="minify" name="doCompression" type="radio" value="false" CHECKED></td> 
     575                                        <td class="radioLabel"><label for="minify">Minify <span class="underLabel">Removes comments, but code is still readable for debugging</span></label></td> 
     576                                </tr>                    
     577 
     578                                <tr><td class="radio" style="vertical-align: top"><input id="compress" name="doCompression" type="radio" value="false"></td> 
     579                                        <td class="radioLabel"><label for="compress">Compress <span class="underLabel">Modifies code to shrink size, but is harder to debug. Gives about a 10% file reduction when comparing its gzipped size to the gzipped size of the Minify option (tool does not do gzipping, you must do it yourself)</span></label></td> 
     580                                </tr> 
    592581<!-- 
    593582--> 
     
    634623        <input type="hidden" name="depList" value="" /> 
    635624        <input type="hidden" name="provideList" value="" /> 
    636         <input type="hidden" name="version" value="" />          
    637         <input type="hidden" name="compress" value="false" /> 
     625        <input type="hidden" name="version" value="" /> 
    638626        <input type="hidden" name="xdDojoUrl" value="" /> 
     627        <input type="hidden" name="doCompression" value="" /> 
    639628</form> 
    640629