Changeset 7881
- Timestamp:
- 03/31/07 14:58:22 (16 months ago)
- Location:
- util/trunk/buildscripts
- Files:
-
- 1 added
- 1 removed
- 7 modified
-
build.js (modified) (8 diffs)
-
flattenResources.js (deleted)
-
jslib/buildUtil.js (modified) (11 diffs)
-
jslib/convertTestsToXDomain.js (modified) (1 diff)
-
jslib/fileUtil.js (modified) (1 diff)
-
jslib/i18nUtil.js (added)
-
makeDojoJsWeb.js (modified) (1 diff)
-
setXdDojoConfig.js (modified) (1 diff)
-
webbuild/makeWebBuildModuleList.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
util/trunk/buildscripts/build.js
r7785 r7881 5 5 load("jslib/fileUtil.js"); 6 6 load("jslib/buildUtil.js"); 7 load("jslib/i18nUtil.js"); 7 8 8 9 var DojoBuildOptions = { … … 26 27 defaultValue: "0.0.0.dev", 27 28 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." 28 33 }, 29 34 "releaseName": { … … 106 111 var dojoPrefixPath = null; 107 112 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"); 110 115 111 116 //Get the list of module directories we need to process. … … 113 118 //Copy each prefix dir to the releases and 114 119 //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 } 129 136 } 130 137 } … … 133 140 if(dojoPrefixPath){ 134 141 _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 } 135 147 136 148 //FIXME: loadDependency list reparses profile file, but we've already done that. … … 145 157 var fileContents = result[i].contents; 146 158 159 //Flatten resources 147 160 //FIXME: Flatten resources. Only do the top level flattening for bundles 148 161 //in the layer files. How to do this for layers? only do one nls file for 149 162 //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 } 153 166 154 167 //Save uncompressed file. … … 203 216 } 204 217 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); 206 221 207 222 //FIXME: Run xdgen if an xdomain build. … … 250 265 kwArgs.releaseDir = "release/" + kwArgs["releaseName"]; 251 266 kwArgs.action = kwArgs.action.split(","); 267 kwArgs.localeList = kwArgs.localeList.split(","); 252 268 253 269 return kwArgs; -
util/trunk/buildscripts/jslib/buildUtil.js
r7785 r7881 1 1 var buildUtil = {}; 2 3 buildUtil.interningDojoUriRegExpString = "(((templatePath|templateCssPath)\\s*(=|:)\\s*)|dojo\\.uri\\.cache\\.allow\\(\\s*)dojo\\.(module)?Uri\\(\\s*?[\\\"\\']([\\w\\.\\/]+)[\\\"\\'](([\\,\\s]*)[\\\"\\']([\\w\\.\\/]*)[\\\"\\'])?\\s*\\)"; 4 buildUtil.interningGlobalDojoUriRegExp = new RegExp(buildUtil.interningDojoUriRegExpString, "g"); 5 buildUtil.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. 9 buildUtil.masterRequireLocalizationRegExpString = "dojo.(requireLocalization)\\(([\\w\\W]*?)\\)"; 10 buildUtil.globalRequireLocalizationRegExp = new RegExp(buildUtil.masterRequireLocalizationRegExpString, "mg"); 11 buildUtil.requireLocalizationRegExp = new RegExp(buildUtil.masterRequireLocalizationRegExpString); 2 12 3 13 //FIXME: This should take the build kwArgs now instead. … … 70 80 } 71 81 } 72 82 73 83 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 } 74 89 75 90 //Override dojo.provide to get a list of resource providers. … … 278 293 var dependencies = null; 279 294 var hostenvType = null; 280 var profileText = new String(fileUtil.readFile(profileFile));295 var profileText = fileUtil.readFile(profileFile); 281 296 282 297 //Remove the call to getDependencyList.js because it is not supported anymore. … … 352 367 for(var i = 0; i < depList.length; i++){ 353 368 //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"; 355 370 } 356 371 … … 358 373 if(dojoContents.match(buildUtil.globalRequireLocalizationRegExp)){ 359 374 depList.push("../../dojo/i18n.js"); 360 dojoContents += new String(fileUtil.readFile(depList[depList.length-1]));375 dojoContents += fileUtil.readFile(depList[depList.length-1]); 361 376 } 362 377 … … 467 482 468 483 //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); 470 485 //Get rid of CR and LFs since they seem to mess with the regexp match. 471 486 //Using the "m" option on the regexp was not enough. … … 506 521 buildUtil.globalDependencyRegExp = new RegExp(buildUtil.masterDependencyRegExpString, "mg"); 507 522 buildUtil.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 the515 //list of supported locales as part of the call. This allows the i18n loading functions516 //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 loader533 //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 match583 //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.requireLocalization605 //call, separate the string into individual arguments.606 var argResult = {607 moduleName: null,608 bundleName: null,609 localeName: null610 };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.bar669 //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 }707 523 708 524 buildUtil.makeResourceUri = function(resourceName, templatePath, srcRoot, prefixes){ … … 758 574 759 575 buildUtil.internTemplateStringsInFile = function(resourceFile, srcRoot, prefixes, skiplist){ 760 var resourceContent = String(fileUtil.readFile(resourceFile));576 var resourceContent = fileUtil.readFile(resourceFile); 761 577 resourceContent = buildUtil.interningRegexpMagic(resourceContent, srcRoot, prefixes, skiplist); 762 578 fileUtil.saveFile(resourceFile, resourceContent); 763 579 } 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);768 580 769 581 buildUtil.interningRegexpMagic = function(resourceContent, srcRoot, prefixes, skiplist){ … … 783 595 logger.trace("Interning resource path: " + filePath); 784 596 //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)); 786 598 if(jsEscapedContent){ 787 599 if(matchString.indexOf("dojo.uri.cache.allow") != -1){ … … 924 736 buildUtil.stripComments = function(/*String*/startDir, /*boolean*/suppressDojoCopyright){ 925 737 //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()); 927 739 var fileList = fileUtil.getFilteredFileList(startDir, /\.js$/, true); 928 740 if(fileList){ … … 938 750 939 751 //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]); 941 753 942 754 //Do comment removal. -
util/trunk/buildscripts/jslib/convertTestsToXDomain.js
r7764 r7881 12 12 for(var i = 0; i < fileList.length; i++){ 13 13 var fileName = fileList[i]; 14 var fileContents = String(fileUtil.readFile(fileName));14 var fileContents = fileUtil.readFile(fileName); 15 15 fileContents = fileContents.replace(/src\=\".*dojo.js"/, 'src="' + xdDojoUrl + '"'); 16 16 fileUtil.saveUtf8File(fileName, fileContents); -
util/trunk/buildscripts/jslib/fileUtil.js
r7775 r7881 89 89 stringBuffer.append(lineSeparator); 90 90 } 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 92 93 } finally { 93 94 input.close(); -
util/trunk/buildscripts/makeDojoJsWeb.js
r7764 r7881 75 75 76 76 //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"); 79 79 contents = copyright + buildNotice + contents; 80 80 compressedContents = copyright + buildNotice + compressedContents; -
util/trunk/buildscripts/setXdDojoConfig.js
r7764 r7881 8 8 load("buildUtilXd.js"); 9 9 10 var fileContents = new String(fileUtil.readFile(dojoFile));10 var fileContents = fileUtil.readFile(dojoFile); 11 11 fileContents = buildUtilXd.setXdDojoConfig(fileContents, xdUrl); 12 12 fileUtil.saveFile(dojoFile, fileContents); -
util/trunk/buildscripts/webbuild/makeWebBuildModuleList.js
r7764 r7881 58 58 for(var i = 0; i < fileList.length; i++){ 59 59 var fileName = fileList[i]; 60 var fileContents = new String(fileUtil.readFile(fileName));60 var fileContents = new fileUtil.readFile(fileName); 61 61 62 62 var matches = fileContents.match(provideRegExp);