Changeset 7187

Show
Ignore:
Timestamp:
02/04/07 22:45:38 (22 months ago)
Author:
jburke
Message:

(merge from 0.4 branch) Fixes #2301 and #2404, and references #2366. web built dojo.js now has strings interned, and for regular builds, all widget js files have strings interned now for the intern-strings target. To get those things to work, I moved the internStrings.js functions into buildUtil.js, but I did it slightly differently than the patch in #2301.

Location:
trunk/buildscripts
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/buildscripts/buildUtil.js

    r7102 r7187  
    606606} 
    607607 
     608 
     609function makeResourceUri(resourceName, templatePath, srcRoot, prefixes){ 
     610        var bestPrefix = ""; 
     611        var bestPrefixPath = "" 
     612        if(prefixes){ 
     613                for (var i = 0; i < prefixes.length; i++){ 
     614                        var prefix = prefixes[i]; 
     615                        //Prefix must match from the start of the resourceName string. 
     616                        if(resourceName.indexOf(prefix[0]) == 0){ 
     617                                if(prefix[0].length > bestPrefix.length){ 
     618                                        bestPrefix = prefix[0]; 
     619                                        bestPrefixPath = prefix[1]; 
     620                                } 
     621                        } 
     622                } 
     623 
     624                if(bestPrefixPath != ""){ 
     625                        //Convert resourceName to a path 
     626                        resourceName = resourceName.replace(bestPrefix, ""); 
     627                        if(resourceName.indexOf(".") == 0){ 
     628                                resourceName = resourceName.substring(1, resourceName.length); 
     629                        } 
     630                        resourceName = resourceName.replace(/\./g, "/"); 
     631 
     632                        //Final path construction 
     633                        var finalPath = srcRoot; 
     634                        finalPath += bestPrefixPath + "/"; 
     635                        if(resourceName){ 
     636                                finalPath += resourceName + "/"; 
     637                        } 
     638                        finalPath += templatePath; 
     639 
     640                        return finalPath; 
     641                } 
     642        } 
     643 
     644        return srcRoot + templatePath; 
     645} 
     646 
     647buildUtil.internTemplateStrings = function(profileFile, loader, releaseDir, srcRoot){ 
     648        loader = loader || "default"; 
     649        releaseDir = releaseDir || "../release/dojo"; 
     650        srcRoot = srcRoot || "../"; 
     651         
     652        print("loader: " + loader); 
     653        print("releaseDir - " + releaseDir); 
     654        var resourceFile = releaseDir + "/dojo.js"; 
     655 
     656        //Load Dojo so we can use readText() defined in hostenv_rhino.js. 
     657        //Also gives us the ability to use all the neato toolkit features. 
     658        djConfig={ 
     659                baseRelativePath: "../" 
     660        }; 
     661        load('../dojo.js'); 
     662        dojo.require("dojo.string.extras"); 
     663        dojo.require("dojo.i18n.common"); 
     664        dojo.require("dojo.json"); 
     665         
     666        //Find the bundles that need to be flattened. 
     667        load("buildUtil.js"); 
     668 
     669        var prefixes = buildUtil.getDependencyPropertyFromProfile(profileFile, "prefixes"); 
     670        //Make sure dojo is in the list. 
     671        var dojoPath = releaseDir.replace(/^.*(\/|\\)release(\/|\\)/, "release/"); 
     672        prefixes.push(["dojo", dojoPath + "/src"]); 
     673 
     674        var skiplist = buildUtil.getDependencyPropertyFromProfile(profileFile, "internSkipList"); 
     675         
     676        buildUtil.internTemplateStringsInFile(loader, resourceFile, srcRoot, prefixes, skiplist); 
     677 
     678        //Intern strings for all files in widget dir (xdomain and regular files) 
     679        var fileList = buildUtil.getFilteredFileList(releaseDir + "/src/widget", 
     680                /\.js$/, true); 
     681 
     682        if(fileList){ 
     683                for(var i = 0; i < fileList.length; i++){ 
     684                        buildUtil.internTemplateStringsInFile(loader, fileList[i], srcRoot, prefixes, skiplist) 
     685                } 
     686        } 
     687} 
     688 
     689buildUtil.internTemplateStringsInFile = function(loader, resourceFile, srcRoot, prefixes, skiplist){ 
     690        var resourceContent = new String(readText(resourceFile)); 
     691        resourceContent = buildUtil.interningRegexpMagic(loader, resourceContent, srcRoot, prefixes, skiplist); 
     692        buildUtil.saveUtf8File(resourceFile, resourceContent); 
     693} 
     694 
     695buildUtil.interningDojoUriRegExpString = "(((templatePath|templateCssPath)\\s*(=|:)\\s*)|dojo\\.uri\\.cache\\.allow\\(\\s*)dojo\\.uri\\.(dojo|module)?Uri\\(\\s*?[\\\"\\']([\\w\\.\\/]+)[\\\"\\'](([\\,\\s]*)[\\\"\\']([\\w\\.\\/]*)[\\\"\\'])?\\s*\\)"; 
     696buildUtil.interningGlobalDojoUriRegExp = new RegExp(buildUtil.interningDojoUriRegExpString, "g"); 
     697buildUtil.interningLocalDojoUriRegExp = new RegExp(buildUtil.interningDojoUriRegExpString); 
     698 
     699//WARNING: This function assumes dojo.string.escapeString() has been loaded. 
     700buildUtil.interningRegexpMagic = function(loader, resourceContent, srcRoot, prefixes, skiplist){ 
     701        return resourceContent.replace(buildUtil.interningGlobalDojoUriRegExp, function(matchString){ 
     702                var parts = matchString.match(buildUtil.interningLocalDojoUriRegExp); 
     703 
     704                var filePath = ""; 
     705                var resourceNsName = ""; 
     706                if(parts[5] == "dojo"){ 
     707                        if(parts[6].match(/(\.htm|\.html|\.css)$/)){ 
     708                                print("Dojo match: " + parts[6]); 
     709                                filePath = srcRoot + parts[6] 
     710                                resourceNsName = "dojo:" + parts[6]; 
     711                        } 
     712                }else{ 
     713                        print("Module match: " + parts[6] + " and " + parts[9]); 
     714                        filePath = makeResourceUri(parts[6], parts[9], srcRoot, prefixes); 
     715                        resourceNsName = parts[6] + ':' + parts[9];              
     716                } 
     717 
     718                if(!filePath || buildUtil.isValueInArray(resourceNsName, skiplist)){ 
     719                        if(filePath){ 
     720                                print("Skip intern resource: " + filePath); 
     721                        } 
     722                }else{ 
     723                        print("Interning resource path: " + filePath); 
     724                        //dojo.string.escapeString will add starting and ending double-quotes. 
     725                        var jsEscapedContent = dojo.string.escapeString(new String(readText(filePath))); 
     726                        if(jsEscapedContent){ 
     727                                if(matchString.indexOf("dojo.uri.cache.allow") != -1){ 
     728                                        //Handle dojo.uri.cache-related interning. 
     729                                        var parenIndex = matchString.lastIndexOf(")"); 
     730                                        matchString = matchString.substring(0, parenIndex + 1) + ", " + jsEscapedContent; 
     731                                        matchString = matchString.replace("dojo.uri.cache.allow", "dojo.uri.cache.set"); 
     732                                }else{ 
     733                                        //Handle templatePath/templateCssPath-related interning. 
     734                                        if(parts[3] == "templatePath"){ 
     735                                                //Replace templatePaths 
     736                                                matchString = "templateString" + parts[4] + jsEscapedContent; 
     737                                        }else{ 
     738                                                //Dealing with templateCssPath 
     739                                                //For the CSS we need to keep the template path in there 
     740                                                //since the widget loading stuff uses the template path to 
     741                                                //know whether the CSS has been processed yet. 
     742                                                //Could have matched assignment via : or =. Need different statement separators at the end. 
     743                                                var assignSeparator = parts[4]; 
     744                                                var statementSeparator = ","; 
     745                                                var statementPrefix = ""; 
     746                         
     747                                                //FIXME: this is a little weak because it assumes a "this" in front of the templateCssPath 
     748                                                //when it is assigned using an "=", as in 'this.templateCssPath = dojo.uri.dojoUri("some/path/to/Css.css");' 
     749                                                //In theory it could be something else, but in practice it is not, and it gets a little too weird 
     750                                                //to figure out, at least for now. 
     751                                                if(assignSeparator == "="){ 
     752                                                        statementSeparator = ";"; 
     753                                                        statementPrefix = "this."; 
     754                                                } 
     755                                                matchString = "templateCssString" + assignSeparator + jsEscapedContent + statementSeparator + statementPrefix + parts[0]; 
     756                                        } 
     757                                } 
     758                        } 
     759                } 
     760 
     761                return matchString; 
     762        }); 
     763} 
     764 
     765buildUtil.isValueInArray = function(value, ary){ 
     766        for(var i = 0; i < ary.length; i++){ 
     767                if(ary[i] == value){ 
     768                        return true; 
     769                } 
     770        } 
     771        return false; 
     772} 
     773 
     774 
    608775//Recurses startDir and finds matches to the files that match regExpFilter. 
    609776//Ignores files/directories that start with a period (.). 
  • trunk/buildscripts/internStrings.js

    r6973 r7187  
    1 //TODO: 
    2 //- Doesn't intern strings for prefix dirs in xd case? 
    3  
    4 function makeResourceUri(resourceName, templatePath, srcRoot, prefixes){ 
    5         var bestPrefix = ""; 
    6         var bestPrefixPath = "" 
    7         if(prefixes){ 
    8                 for (var i = 0; i < prefixes.length; i++){ 
    9                         var prefix = prefixes[i]; 
    10                         //Prefix must match from the start of the resourceName string. 
    11                         if(resourceName.indexOf(prefix[0]) == 0){ 
    12                                 if(prefix[0].length > bestPrefix.length){ 
    13                                         bestPrefix = prefix[0]; 
    14                                         bestPrefixPath = prefix[1]; 
    15                                 } 
    16                         } 
    17                 } 
    18  
    19                 if(bestPrefixPath != ""){ 
    20                         //Convert resourceName to a path 
    21                         resourceName = resourceName.replace(bestPrefix, ""); 
    22                         if(resourceName.indexOf(".") == 0){ 
    23                                 resourceName = resourceName.substring(1, resourceName.length); 
    24                         } 
    25                         resourceName = resourceName.replace(/\./g, "/"); 
    26  
    27                         //Final path construction 
    28                         var finalPath = srcRoot; 
    29                         finalPath += bestPrefixPath + "/"; 
    30                         if(resourceName){ 
    31                                 finalPath += resourceName + "/"; 
    32                         } 
    33                         finalPath += templatePath; 
    34  
    35                         return finalPath; 
    36                 } 
    37         } 
    38  
    39         return srcRoot + templatePath; 
    40 } 
    41  
    42 function internTemplateStrings(profileFile, loader, releaseDir, srcRoot){ 
    43         loader = loader || "default"; 
    44         releaseDir = releaseDir || "../release/dojo"; 
    45         srcRoot = srcRoot || "../"; 
    46          
    47         print("loader: " + loader); 
    48         print("releaseDir - " + releaseDir); 
    49         var resourceFile = releaseDir + "/dojo.js"; 
    50  
    51         //Load Dojo so we can use readText() defined in hostenv_rhino.js. 
    52         //Also gives us the ability to use all the neato toolkit features. 
    53         djConfig={ 
    54                 baseRelativePath: "../" 
    55         }; 
    56         load('../dojo.js'); 
    57         dojo.require("dojo.string.extras"); 
    58         dojo.require("dojo.i18n.common"); 
    59         dojo.require("dojo.json"); 
    60          
    61         //Find the bundles that need to be flattened. 
    62         load("buildUtil.js"); 
    63  
    64         var prefixes = buildUtil.getDependencyPropertyFromProfile(profileFile, "prefixes"); 
    65         //Make sure dojo is in the list. 
    66         var dojoPath = releaseDir.replace(/^.*(\/|\\)release(\/|\\)/, "release/"); 
    67         prefixes.push(["dojo", dojoPath + "/src"]); 
    68  
    69         var skiplist = buildUtil.getDependencyPropertyFromProfile(profileFile, "internSkipList"); 
    70          
    71         internTemplateStringsInFile(loader, resourceFile, srcRoot, prefixes, skiplist); 
    72  
    73         //If doing xdomain, then need to fix up the .xd.js files in the widget subdir. 
    74         if(loader == "xdomain"){ 
    75                 var fileList = buildUtil.getFilteredFileList(releaseDir + "/src/widget", 
    76                         /\.xd\.js$/, true); 
    77  
    78                 if(fileList){ 
    79                         for(var i = 0; i < fileList.length; i++){ 
    80                                 internTemplateStringsInFile(loader, fileList[i], srcRoot, prefixes, skiplist) 
    81                         } 
    82                 } 
    83         } 
    84 } 
    85  
    86 function internTemplateStringsInFile(loader, resourceFile, srcRoot, prefixes, skiplist){ 
    87         var resourceContent = new String(readText(resourceFile)); 
    88         resourceContent = regexpMagic(loader, resourceContent, srcRoot, prefixes, skiplist); 
    89         buildUtil.saveUtf8File(resourceFile, resourceContent); 
    90 } 
    91  
    92 var dojoUriRegExpString = "(((templatePath|templateCssPath)\\s*(=|:)\\s*)|dojo\\.uri\\.cache\\.allow\\(\\s*)dojo\\.uri\\.(dojo|module)?Uri\\(\\s*?[\\\"\\']([\\w\\.\\/]+)[\\\"\\'](([\\,\\s]*)[\\\"\\']([\\w\\.\\/]*)[\\\"\\'])?\\s*\\)"; 
    93 var globalDojoUriRegExp = new RegExp(dojoUriRegExpString, "g"); 
    94 var localDojoUriRegExp = new RegExp(dojoUriRegExpString); 
    95  
    96 function regexpMagic(loader, resourceContent, srcRoot, prefixes, skiplist){ 
    97         return resourceContent.replace(globalDojoUriRegExp, function(matchString){ 
    98                 var parts = matchString.match(localDojoUriRegExp); 
    99  
    100                 var filePath = ""; 
    101                 var resourceNsName = ""; 
    102                 if(parts[5] == "dojo"){ 
    103                         if(parts[6].match(/(\.htm|\.html|\.css)$/)){ 
    104                                 print("Dojo match: " + parts[6]); 
    105                                 filePath = srcRoot + parts[6] 
    106                                 resourceNsName = "dojo:" + parts[6]; 
    107                         } 
    108                 }else{ 
    109                         print("Module match: " + parts[6] + " and " + parts[9]); 
    110                         filePath = makeResourceUri(parts[6], parts[9], srcRoot, prefixes); 
    111                         resourceNsName = parts[6] + ':' + parts[9];              
    112                 } 
    113  
    114                 if(!filePath || isValueInArray(resourceNsName, skiplist)){ 
    115                         if(filePath){ 
    116                                 print("Skip intern resource: " + filePath); 
    117                         } 
    118                 }else{ 
    119                         print("Interning resource path: " + filePath); 
    120                         //dojo.string.escapeString will add starting and ending double-quotes. 
    121                         var jsEscapedContent = dojo.string.escapeString(new String(readText(filePath))); 
    122                         if(jsEscapedContent){ 
    123                                 if(matchString.indexOf("dojo.uri.cache.allow") != -1){ 
    124                                         //Handle dojo.uri.cache-related interning. 
    125                                         var parenIndex = matchString.lastIndexOf(")"); 
    126                                         matchString = matchString.substring(0, parenIndex + 1) + ", " + jsEscapedContent; 
    127                                         matchString = matchString.replace("dojo.uri.cache.allow", "dojo.uri.cache.set"); 
    128                                 }else{ 
    129                                         //Handle templatePath/templateCssPath-related interning. 
    130                                         if(parts[3] == "templatePath"){ 
    131                                                 //Replace templatePaths 
    132                                                 matchString = "templateString" + parts[4] + jsEscapedContent; 
    133                                         }else{ 
    134                                                 //Dealing with templateCssPath 
    135                                                 //For the CSS we need to keep the template path in there 
    136                                                 //since the widget loading stuff uses the template path to 
    137                                                 //know whether the CSS has been processed yet. 
    138                                                 //Could have matched assignment via : or =. Need different statement separators at the end. 
    139                                                 var assignSeparator = parts[4]; 
    140                                                 var statementSeparator = ","; 
    141                                                 var statementPrefix = ""; 
    142                          
    143                                                 //FIXME: this is a little weak because it assumes a "this" in front of the templateCssPath 
    144                                                 //when it is assigned using an "=", as in 'this.templateCssPath = dojo.uri.dojoUri("some/path/to/Css.css");' 
    145                                                 //In theory it could be something else, but in practice it is not, and it gets a little too weird 
    146                                                 //to figure out, at least for now. 
    147                                                 if(assignSeparator == "="){ 
    148                                                         statementSeparator = ";"; 
    149                                                         statementPrefix = "this."; 
    150                                                 } 
    151                                                 matchString = "templateCssString" + assignSeparator + jsEscapedContent + statementSeparator + statementPrefix + parts[0]; 
    152                                         } 
    153                                 } 
    154                         } 
    155                 } 
    156  
    157                 return matchString; 
    158         }); 
    159 } 
    160  
    161 function isValueInArray(value, ary){ 
    162         for(var i = 0; i < ary.length; i++){ 
    163                 if(ary[i] == value){ 
    164                         return true; 
    165                 } 
    166         } 
    167         return false; 
    168 } 
    169  
    1701//START of the "main" part of the script. 
    1712//This is the entry point for this script file. 
     
    1745var releaseDir = arguments[2]; 
    1756var srcRoot = arguments[3]; 
    176 internTemplateStrings(profileFile, loader, releaseDir, srcRoot); 
     7 
     8load("buildUtil.js"); 
     9 
     10buildUtil.internTemplateStrings(profileFile, loader, releaseDir, srcRoot); 
  • trunk/buildscripts/webbuild/webbuild.js

    r7175 r7187  
    55} 
    66 
    7 readFile = function(uri){ 
     7readText = readFile = function(uri){ 
    88        return dojo.hostenv.getText(uri); 
    99} 
     
    4343                var dependencyResult = buildUtil.getDependencyList(dependencies, null, true); 
    4444                var dojoResult = buildUtil.makeDojoJs(dependencyResult, version); 
    45          
     45 
     46                //Intern strings, and add license 
     47                dojoResult.dojoContents = new String(readFile("copyright.txt")) + buildUtil.interningRegexpMagic("xdomain", dojoResult.dojoContents, djConfig.baseRelativePath, [["dojo", "src"]], []); 
     48 
    4649                //Print out the file list. 
    4750                dojo.debug("files in the profile:"); 
     
    5962                } 
    6063 
    61                 parent.dojoContents = webbuild.dojoContents; 
     64 
     65 
    6266                var outputWindow = window.open("webbuild/dojo.js.html", "dojoOutput"); 
    6367                outputWindow.focus();