Changeset 7881

Show
Ignore:
Timestamp:
03/31/07 14:58:22 (16 months ago)
Author:
jburke
Message:

Refs #2607. Moved i18n bundle flattening to the new build model. It probably has bugs since I will not be able to test it until we have some real modules that use i18n in the new structure, but at least the code is set up. Still need to do xdomain work in the build process.

Location:
util/trunk/buildscripts
Files:
1 added
1 removed
7 modified

Legend:

Unmodified
Added
Removed
  • util/trunk/buildscripts/build.js

    r7785 r7881  
    55load("jslib/fileUtil.js"); 
    66load("jslib/buildUtil.js"); 
     7load("jslib/i18nUtil.js"); 
    78 
    89var DojoBuildOptions = { 
     
    2627                defaultValue: "0.0.0.dev", 
    2728                helpText: "The build will be stamped with this version string." 
     29        }, 
     30        "localeList": { 
     31                defaultValue: "en-gb,en-us,de-de,es-es,fr-fr,it-it,pt-br,ko-kr,zh-tw,zh-cn,ja-jp", 
     32                helpText: "The set of locales to use when flattening i18n bundles." 
    2833        }, 
    2934        "releaseName": { 
     
    106111        var dojoPrefixPath = null; 
    107112        var lineSeparator = fileUtil.getLineSeparator(); 
    108         var copyrightText = String(fileUtil.readFile("copyright.txt")); 
    109         var buildNoticeText = String(fileUtil.readFile("build_notice.txt")); 
     113        var copyrightText = fileUtil.readFile("copyright.txt"); 
     114        var buildNoticeText = fileUtil.readFile("build_notice.txt"); 
    110115         
    111116        //Get the list of module directories we need to process. 
     
    113118        //Copy each prefix dir to the releases and 
    114119        //operate on that copy. 
    115         for(var i = 0; i < prefixes.length; i++){ 
    116                 var prefixName = prefixes[i][0]; 
    117                 var prefixPath = prefixes[i][1]; 
    118                  
    119                 //Set prefix path to the release location, so that 
    120                 //build operations that depend/operate on it are using 
    121                 //the release location. 
    122                 prefixes[i][1] = kwArgs.releaseDir + "/"  + prefixName; 
    123  
    124                 //Save dojo for last. 
    125                 if(prefixName == "dojo"){ 
    126                         dojoPrefixPath = prefixPath; 
    127                 }else{ 
    128                         _prefixPathRelease(prefixName, prefixPath, kwArgs); 
     120        if(prefixes && prefixes.length > 0){ 
     121                for(var i = 0; i < prefixes.length; i++){ 
     122                        var prefixName = prefixes[i][0]; 
     123                        var prefixPath = prefixes[i][1]; 
     124                         
     125                        //Set prefix path to the release location, so that 
     126                        //build operations that depend/operate on it are using 
     127                        //the release location. 
     128                        prefixes[i][1] = kwArgs.releaseDir + "/"  + prefixName; 
     129         
     130                        //Save dojo for last. 
     131                        if(prefixName == "dojo"){ 
     132                                dojoPrefixPath = prefixPath; 
     133                        }else{ 
     134                                _prefixPathRelease(prefixName, prefixPath, kwArgs); 
     135                        } 
    129136                } 
    130137        } 
     
    133140        if(dojoPrefixPath){ 
    134141                 _prefixPathRelease("dojo", dojoPrefixPath, kwArgs); 
     142 
     143                //Make sure dojo is clear before trying to map dependencies. 
     144                if(typeof dojo != "undefined"){ 
     145                        dojo = undefined; 
     146                } 
    135147 
    136148                //FIXME: loadDependency list reparses profile file, but we've already done that. 
     
    145157                        var fileContents = result[i].contents; 
    146158                         
     159                        //Flatten resources  
    147160                        //FIXME: Flatten resources. Only do the top level flattening for bundles 
    148161                        //in the layer files. How to do this for layers? only do one nls file for 
    149162                        //all layers, or a different one for each layer? 
    150                         //              <replaceregexp match="/\*\*\*BUILD:localesGenerated\*\*\*/" byline="false" replace="=${generatedLocales}" 
    151                         //      file="${dstFile}"/> 
    152                         //remove dojo.requireLocalization calls. 
     163                        if(fileName == "dojo.js"){ 
     164                                i18n.flattenLayerFileBundles(fileName, dojoReleaseDir + "nls", "nls", kwArgs); 
     165                        } 
    153166 
    154167                        //Save uncompressed file. 
     
    203216        } 
    204217 
    205         //FIXME: flatten bundles inside the directory 
     218        //Flatten bundles inside the directory 
     219        //FIXME: Is baseRelativePath now obsolete? 
     220        i18nUtil.flattenDirBundles(prefixName, prefixPath, /*baseRelativePath*/"", kwArgs); 
    206221 
    207222        //FIXME: Run xdgen if an xdomain build. 
     
    250265        kwArgs.releaseDir = "release/" + kwArgs["releaseName"]; 
    251266        kwArgs.action = kwArgs.action.split(","); 
     267        kwArgs.localeList = kwArgs.localeList.split(","); 
    252268         
    253269        return kwArgs; 
  • util/trunk/buildscripts/jslib/buildUtil.js

    r7785 r7881  
    11var buildUtil = {}; 
     2 
     3buildUtil.interningDojoUriRegExpString = "(((templatePath|templateCssPath)\\s*(=|:)\\s*)|dojo\\.uri\\.cache\\.allow\\(\\s*)dojo\\.(module)?Uri\\(\\s*?[\\\"\\']([\\w\\.\\/]+)[\\\"\\'](([\\,\\s]*)[\\\"\\']([\\w\\.\\/]*)[\\\"\\'])?\\s*\\)"; 
     4buildUtil.interningGlobalDojoUriRegExp = new RegExp(buildUtil.interningDojoUriRegExpString, "g"); 
     5buildUtil.interningLocalDojoUriRegExp = new RegExp(buildUtil.interningDojoUriRegExpString); 
     6 
     7//Even though these are i18n-specific, they are not in i18nUtil.js since one is referenced 
     8//in this file. Want to avoid circular dependency loading issues. 
     9buildUtil.masterRequireLocalizationRegExpString = "dojo.(requireLocalization)\\(([\\w\\W]*?)\\)"; 
     10buildUtil.globalRequireLocalizationRegExp = new RegExp(buildUtil.masterRequireLocalizationRegExpString, "mg"); 
     11buildUtil.requireLocalizationRegExp = new RegExp(buildUtil.masterRequireLocalizationRegExpString); 
    212 
    313//FIXME: This should take the build kwArgs now instead. 
     
    7080                } 
    7181        } 
    72          
     82 
    7383        dojo._name = hostenvType; 
     84        if(hostenvType == "browser"){ 
     85                //Make sure we setup the env so that dojo 
     86                //thinks we are running in a browser. 
     87                dojo.isBrowser = true; 
     88        } 
    7489         
    7590        //Override dojo.provide to get a list of resource providers. 
     
    278293        var dependencies = null; 
    279294        var hostenvType = null; 
    280         var profileText = new String(fileUtil.readFile(profileFile)); 
     295        var profileText = fileUtil.readFile(profileFile); 
    281296         
    282297        //Remove the call to getDependencyList.js because it is not supported anymore. 
     
    352367        for(var i = 0; i < depList.length; i++){ 
    353368                //Make sure we have a JS string and not a Java string by using new String(). 
    354                 dojoContents += new String(fileUtil.readFile(depList[i])) + "\r\n"; 
     369                dojoContents += fileUtil.readFile(depList[i]) + "\r\n"; 
    355370        } 
    356371         
     
    358373        if(dojoContents.match(buildUtil.globalRequireLocalizationRegExp)){ 
    359374                depList.push("../../dojo/i18n.js"); 
    360                 dojoContents += new String(fileUtil.readFile(depList[depList.length-1])); 
     375                dojoContents += fileUtil.readFile(depList[depList.length-1]); 
    361376        } 
    362377 
     
    467482 
    468483        //Use new String to make sure we have a JS string (not a Java string) 
    469         var profileText = new String(fileUtil.readFile(profileFile)); 
     484        var profileText = fileUtil.readFile(profileFile); 
    470485        //Get rid of CR and LFs since they seem to mess with the regexp match. 
    471486        //Using the "m" option on the regexp was not enough. 
     
    506521buildUtil.globalDependencyRegExp = new RegExp(buildUtil.masterDependencyRegExpString, "mg"); 
    507522buildUtil.dependencyPartsRegExp = new RegExp(buildUtil.masterDependencyRegExpString); 
    508  
    509 buildUtil.masterRequireLocalizationRegExpString = "dojo.(requireLocalization)\\(([\\w\\W]*?)\\)"; 
    510 buildUtil.globalRequireLocalizationRegExp = new RegExp(buildUtil.masterRequireLocalizationRegExpString, "mg"); 
    511 buildUtil.requireLocalizationRegExp = new RegExp(buildUtil.masterRequireLocalizationRegExpString); 
    512  
    513 buildUtil.modifyRequireLocalization = function(fileContents, baseRelativePath, prefixes){ 
    514         //summary: Modifies any dojo.requireLocalization calls in the fileContents to have the 
    515         //list of supported locales as part of the call. This allows the i18n loading functions 
    516         //to only make request(s) for locales that actually exist on disk. 
    517         var dependencies = []; 
    518          
    519         //Make sure we have a JS string, and not a Java string. 
    520         fileContents = String(fileContents); 
    521          
    522         var modifiedContents = fileContents; 
    523          
    524         if(fileContents.match(buildUtil.globalRequireLocalizationRegExp)){ 
    525                 modifiedContents = fileContents.replace(buildUtil.globalRequireLocalizationRegExp, function(matchString){ 
    526                         var replacement = matchString; 
    527                         var partMatches = matchString.match(buildUtil.requireLocalizationRegExp); 
    528                         var depCall = partMatches[1]; 
    529                         var depArgs = partMatches[2]; 
    530          
    531                         if(depCall == "requireLocalization"){ 
    532                                 //Need to find out what locales are available so the dojo loader 
    533                                 //only has to do one script request for the closest matching locale. 
    534                                 var reqArgs = buildUtil.getRequireLocalizationArgsFromString(depArgs); 
    535                                 if(reqArgs.moduleName){ 
    536                                         //Find the list of locales supported by looking at the path names. 
    537                                         var locales = buildUtil.getLocalesForBundle(reqArgs.moduleName, reqArgs.bundleName, baseRelativePath, prefixes); 
    538          
    539                                         //Add the supported locales to the requireLocalization arguments. 
    540                                         if(!reqArgs.localeName){ 
    541                                                 depArgs += ", null"; 
    542                                         } 
    543          
    544                                         depArgs += ', "' + locales.join(",") + '"'; 
    545                                          
    546                                         replacement = "dojo." + depCall + "(" + depArgs + ")"; 
    547                                 } 
    548                         } 
    549                         return replacement;              
    550                 }); 
    551         }        
    552         return modifiedContents; 
    553 } 
    554  
    555 buildUtil.makeFlatBundleContents = function(prefix, prefixPath, srcFileName){ 
    556         //summary: Given a nls file name, flatten the bundles from parent locales into the nls bundle. 
    557         var bundleParts = buildUtil.getBundlePartsFromFileName(prefix, prefixPath, srcFileName); 
    558         if(!bundleParts){ 
    559                 return null; 
    560         } 
    561         var moduleName = bundleParts.moduleName; 
    562         var bundleName = bundleParts.bundleName; 
    563         var localeName = bundleParts.localeName; 
    564  
    565         //print("## moduleName: " + moduleName + ", bundleName: " + bundleName + ", localeName: " + localeName); 
    566         dojo.requireLocalization(moduleName, bundleName, localeName); 
    567          
    568         //Get the generated, flattened bundle. 
    569         var module = dojo.getObject(moduleName); 
    570         var bundleLocale = localeName ? localeName.replace(/-/g, "_") : "ROOT"; 
    571         var flattenedBundle = module.nls[bundleName][bundleLocale]; 
    572         //print("## flattenedBundle: " + flattenedBundle); 
    573         if(!flattenedBundle){ 
    574                 throw "Cannot create flattened bundle for src file: " + srcFileName; 
    575         } 
    576  
    577         return dojo.json.serialize(flattenedBundle); 
    578 } 
    579  
    580 //Given a module and bundle name, find all the supported locales. 
    581 buildUtil.getLocalesForBundle = function(moduleName, bundleName, baseRelativePath, prefixes){ 
    582         //Build a path to the bundle directory and ask for all files that match 
    583         //the bundle name. 
    584         var filePath = this.mapResourceToPath(moduleName, baseRelativePath, prefixes); 
    585          
    586         var bundleRegExp = new RegExp("nls[/]?([\\w\\-]*)/" + bundleName + ".js$"); 
    587         var bundleFiles = fileUtil.getFilteredFileList(filePath + "nls/", bundleRegExp, true); 
    588          
    589         //Find the list of locales supported by looking at the path names. 
    590         var locales = []; 
    591         for(var j = 0; j < bundleFiles.length; j++){ 
    592                 var bundleParts = bundleFiles[j].match(bundleRegExp); 
    593                 if(bundleParts && bundleParts[1]){ 
    594                         locales.push(bundleParts[1]); 
    595                 }else{ 
    596                         locales.push("ROOT"); 
    597                 } 
    598         } 
    599  
    600         return locales; 
    601 } 
    602  
    603 buildUtil.getRequireLocalizationArgsFromString = function(argString){ 
    604         //summary: Given a string of the arguments to a dojo.requireLocalization 
    605         //call, separate the string into individual arguments. 
    606         var argResult = { 
    607                 moduleName: null, 
    608                 bundleName: null, 
    609                 localeName: null 
    610         }; 
    611          
    612         var l10nMatches = argString.split(/\,\s*/); 
    613         if(l10nMatches && l10nMatches.length > 1){ 
    614                 argResult.moduleName = l10nMatches[0] ? l10nMatches[0].replace(/\"/g, "") : null; 
    615                 argResult.bundleName = l10nMatches[1] ? l10nMatches[1].replace(/\"/g, "") : null; 
    616                 argResult.localeName = l10nMatches[2]; 
    617         } 
    618         return argResult; 
    619 } 
    620  
    621 buildUtil.getBundlePartsFromFileName = function(prefix, prefixPath, srcFileName){ 
    622         //Pull off any ../ values from prefix path to make matching easier. 
    623         var prefixPath = prefixPath.replace(/\.\.\//g, ""); 
    624  
    625         //Strip off the prefix path so we can find the real resource and bundle names. 
    626         var prefixStartIndex = srcFileName.lastIndexOf(prefixPath); 
    627         if(prefixStartIndex != -1){ 
    628                 var startIndex = prefixStartIndex + prefixPath.length; 
    629                  
    630                 //Need to add one if the prefiPath does not include an ending /. Otherwise, 
    631                 //We'll get extra dots in our bundleName. 
    632                 if(prefixPath.charAt(prefixPath.length) != "/"){ 
    633                         startIndex += 1; 
    634                 } 
    635                 srcFileName = srcFileName.substring(startIndex, srcFileName.length); 
    636         } 
    637          
    638         //var srcIndex = srcFileName.indexOf("src/"); 
    639         //srcFileName = srcFileName.substring(srcIndex + 4, srcFileName.length); 
    640         var parts = srcFileName.split("/"); 
    641  
    642         //Split up the srcFileName into arguments that can be used for dojo.requireLocalization() 
    643         var moduleParts = [prefix]; 
    644         for(var i = 0; parts[i] != "nls"; i++){ 
    645                 moduleParts.push(parts[i]); 
    646         } 
    647         var moduleName = moduleParts.join("."); 
    648         if(parts[i+1].match(/\.js$/)){ 
    649                 var localeName = ""; 
    650                 var bundleName = parts[i+1]; 
    651         }else{ 
    652                 var localeName = parts[i+1]; 
    653                 var bundleName = parts[i+2];     
    654         } 
    655  
    656         if(!bundleName || bundleName.indexOf(".js") == -1){ 
    657                 //Not a valid bundle. Could be something like a README file. 
    658                 return null; 
    659         }else{ 
    660                 bundleName = bundleName.replace(/\.js/, ""); 
    661         } 
    662  
    663         return {moduleName: moduleName, bundleName: bundleName, localeName: localeName}; 
    664 } 
    665  
    666 buildUtil.mapResourceToPath = function(resourceName, baseRelativePath, prefixes){ 
    667         //summary: converts a resourceName to a path. 
    668         //resourceName: String: like dojo.foo or mymodule.bar 
    669         //baseRelativePath: String: the relative path to Dojo. All resource paths are relative to dojo. 
    670         //                  it always ends in with a slash. 
    671         //prefixes: Array: Actually an array of arrays. Comes from profile js file. 
    672         //          dependencies.prefixes = [["mymodule.foo", "../mymoduledir"]]; 
    673          
    674         var bestPrefix = ""; 
    675         var bestPrefixPath = ""; 
    676         if(prefixes){ 
    677                 for(var i = 0; i < prefixes.length; i++){ 
    678                         //Prefix must match from the start of the resourceName string. 
    679                         if(resourceName.indexOf(prefixes[i][0]) == 0){ 
    680                                 if(prefixes[i][0].length > bestPrefix.length){ 
    681                                         bestPrefix = prefixes[i][0]; 
    682                                         bestPrefixPath = prefixes[i][1]; 
    683                                 } 
    684                         } 
    685                 } 
    686         } 
    687  
    688         //Get rid of matching prefix from resource name. 
    689         resourceName = resourceName.replace(bestPrefix, ""); 
    690          
    691         if(resourceName.charAt(0) == '.'){ 
    692                 resourceName = resourceName.substring(1, resourceName.length); 
    693         } 
    694          
    695         resourceName = resourceName.replace(/\./g, "/"); 
    696  
    697         var finalPath = baseRelativePath + bestPrefixPath; 
    698         if(finalPath.charAt(finalPath.length - 1) != "/"){ 
    699                 finalPath += "/"; 
    700         } 
    701         if (resourceName){ 
    702                 finalPath += resourceName + "/"; 
    703         } 
    704          
    705         return finalPath; 
    706 } 
    707523 
    708524buildUtil.makeResourceUri = function(resourceName, templatePath, srcRoot, prefixes){ 
     
    758574 
    759575buildUtil.internTemplateStringsInFile = function(resourceFile, srcRoot, prefixes, skiplist){ 
    760         var resourceContent = String(fileUtil.readFile(resourceFile)); 
     576        var resourceContent = fileUtil.readFile(resourceFile); 
    761577        resourceContent = buildUtil.interningRegexpMagic(resourceContent, srcRoot, prefixes, skiplist); 
    762578        fileUtil.saveFile(resourceFile, resourceContent); 
    763579} 
    764  
    765 buildUtil.interningDojoUriRegExpString = "(((templatePath|templateCssPath)\\s*(=|:)\\s*)|dojo\\.uri\\.cache\\.allow\\(\\s*)dojo\\.(module)?Uri\\(\\s*?[\\\"\\']([\\w\\.\\/]+)[\\\"\\'](([\\,\\s]*)[\\\"\\']([\\w\\.\\/]*)[\\\"\\'])?\\s*\\)"; 
    766 buildUtil.interningGlobalDojoUriRegExp = new RegExp(buildUtil.interningDojoUriRegExpString, "g"); 
    767 buildUtil.interningLocalDojoUriRegExp = new RegExp(buildUtil.interningDojoUriRegExpString); 
    768580 
    769581buildUtil.interningRegexpMagic = function(resourceContent, srcRoot, prefixes, skiplist){ 
     
    783595                        logger.trace("Interning resource path: " + filePath); 
    784596                        //buildUtil.jsEscape will add starting and ending double-quotes. 
    785                         var jsEscapedContent = buildUtil.jsEscape(new String(fileUtil.readFile(filePath))); 
     597                        var jsEscapedContent = buildUtil.jsEscape(fileUtil.readFile(filePath)); 
    786598                        if(jsEscapedContent){ 
    787599                                if(matchString.indexOf("dojo.uri.cache.allow") != -1){ 
     
    924736buildUtil.stripComments = function(/*String*/startDir, /*boolean*/suppressDojoCopyright){ 
    925737        //summary: strips the JS comments from all the files in "startDir", and all subdirectories. 
    926         var copyright = suppressDojoCopyright ? "" : (new String(fileUtil.readFile("copyright.txt")) + fileUtil.getLineSeparator()); 
     738        var copyright = suppressDojoCopyright ? "" : (fileUtil.readFile("copyright.txt") + fileUtil.getLineSeparator()); 
    927739        var fileList = fileUtil.getFilteredFileList(startDir, /\.js$/, true); 
    928740        if(fileList){ 
     
    938750                                 
    939751                                //Read in the file. Make sure we have a JS string. 
    940                                 var fileContents = new String(fileUtil.readFile(fileList[i])); 
     752                                var fileContents = fileUtil.readFile(fileList[i]); 
    941753 
    942754                                //Do comment removal. 
  • util/trunk/buildscripts/jslib/convertTestsToXDomain.js

    r7764 r7881  
    1212for(var i = 0; i < fileList.length; i++){ 
    1313        var fileName = fileList[i];      
    14         var fileContents = String(fileUtil.readFile(fileName)); 
     14        var fileContents = fileUtil.readFile(fileName); 
    1515        fileContents = fileContents.replace(/src\=\".*dojo.js"/, 'src="' + xdDojoUrl + '"'); 
    1616        fileUtil.saveUtf8File(fileName, fileContents); 
  • util/trunk/buildscripts/jslib/fileUtil.js

    r7775 r7881  
    8989                        stringBuffer.append(lineSeparator); 
    9090                } 
    91                 return stringBuffer.toString(); //Java String 
     91                //Make sure we return a JavaScript string and not a Java string. 
     92                return new String(stringBuffer.toString()); //String 
    9293        } finally { 
    9394                input.close(); 
  • util/trunk/buildscripts/makeDojoJsWeb.js

    r7764 r7881  
    7575 
    7676                //Add copyright 
    77                 var copyright = new String(fileUtil.readFile("copyright.txt")); 
    78                 var buildNotice = new String(fileUtil.readFile("build_notice.txt")); 
     77                var copyright = fileUtil.readFile("copyright.txt"); 
     78                var buildNotice = fileUtil.readFile("build_notice.txt"); 
    7979                contents = copyright + buildNotice + contents; 
    8080                compressedContents = copyright + buildNotice + compressedContents; 
  • util/trunk/buildscripts/setXdDojoConfig.js

    r7764 r7881  
    88load("buildUtilXd.js"); 
    99 
    10 var fileContents = new String(fileUtil.readFile(dojoFile)); 
     10var fileContents = fileUtil.readFile(dojoFile); 
    1111fileContents = buildUtilXd.setXdDojoConfig(fileContents, xdUrl); 
    1212fileUtil.saveFile(dojoFile, fileContents); 
  • util/trunk/buildscripts/webbuild/makeWebBuildModuleList.js

    r7764 r7881  
    5858for(var i = 0; i < fileList.length; i++){ 
    5959        var fileName = fileList[i]; 
    60         var fileContents = new String(fileUtil.readFile(fileName)); 
     60        var fileContents = new fileUtil.readFile(fileName); 
    6161 
    6262        var matches = fileContents.match(provideRegExp);