Skip to content

Commit

Permalink
Add a makeZipFile build target.
Browse files Browse the repository at this point in the history
Refactor build script to get the "build" target even faster by running steps in parallel,
and only re-write generated files if the content is different.

Separate out the generated file that builds the complete Cesium object from the main.js used
with Almond to simply require the complete object and assign it globally.
  • Loading branch information
shunter committed May 11, 2012
1 parent 02e8a3c commit f3e085d
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 54 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
/.metadata
/Build
/Instrumented
/Cesium-*.zip
19 changes: 14 additions & 5 deletions .project
Expand Up @@ -32,7 +32,7 @@
</natures>
<filteredResources>
<filter>
<id>1335454855938</id>
<id>1336749948404</id>
<name></name>
<type>10</type>
<matcher>
Expand All @@ -41,7 +41,7 @@
</matcher>
</filter>
<filter>
<id>1335454855938</id>
<id>1336749948413</id>
<name></name>
<type>10</type>
<matcher>
Expand All @@ -50,7 +50,7 @@
</matcher>
</filter>
<filter>
<id>1335454855948</id>
<id>1336749948416</id>
<name></name>
<type>10</type>
<matcher>
Expand All @@ -59,12 +59,21 @@
</matcher>
</filter>
<filter>
<id>1335299856539</id>
<id>1336749948422</id>
<name></name>
<type>6</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-Cesium-*.zip</arguments>
</matcher>
</filter>
<filter>
<id>1336749023862</id>
<name>Source</name>
<type>6</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-main.js</arguments>
<arguments>1.0-name-matches-false-false-Cesium.js</arguments>
</matcher>
</filter>
<filter>
Expand Down
2 changes: 1 addition & 1 deletion Source/.gitignore
@@ -1 +1 @@
/main.js
/Cesium.js
7 changes: 7 additions & 0 deletions Source/main.js
@@ -0,0 +1,7 @@
/*global require*/
// require in the complete Cesium object and reassign it globally.
// This is meant for use with the Almond loader.
require(['Cesium'], function(Cesium) {
"use strict";
window.Cesium = Cesium;
}, undefined, true);
159 changes: 111 additions & 48 deletions build.xml
@@ -1,5 +1,19 @@
<project name="Cesium" default="combine">
<target name="build" description="A developer build that runs in-place." depends="convertShadersToJavaScript, buildSpecList" />
<target name="build" description="A developer build that runs in-place.">
<parallel>
<glslToJavascript destination="${shadersDirectory}" stripcomments="${build.minification}">
<fileset dir="${shadersDirectory}" includes="*.glsl" />
</glslToJavascript>

<createCesiumJs output="${sourceDirectory}/Cesium.js">
<fileset dir="${sourceDirectory}" includes="**/*.js" excludes="Cesium.js,main.js" />
</createCesiumJs>

<createSpecList output="${specsDirectory}/SpecList.js">
<fileset dir="${specsDirectory}" includes="**/*.js" excludes="*.js" />
</createSpecList>
</parallel>
</target>

<target name="combine" description="Combines all source files into a single stand-alone script." depends="build, combineJavaScript, concatenateSandboxSnippets" />

Expand All @@ -22,19 +36,36 @@
</exec>
</target>

<target name="makeZipFile" description="Builds a zip file containing all release files." depends="release">
<zip destfile="Cesium-${version}.zip" basedir="${basedir}">
<include name="Build/**" />
<include name="Examples/**" />
<include name="Images/**" />
<include name="Source/**" />
<include name="Specs/**" />
<include name="ThirdParty/**" />
<include name="CHANGES" />
<include name="index.html" />
<include name="LICENSE" />
<include name="README.md" />
</zip>
</target>

<target name="clean" description="Cleans the build.">
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${buildDirectory}" defaultexcludes="false" />
<fileset dir="${instrumentedDirectory}" defaultexcludes="false" />
<fileset dir="${shadersDirectory}" includes="*.js" />
<fileset dir="${specsDirectory}" includes="SpecList.js" />
<fileset dir="." includes="Cesium-*.zip" />
</delete>
</target>

<!-- properties controlling which steps get run -->
<property name="build.minification" value="false" />

<!-- Inputs -->
<property name="version" value="b5" />
<property name="sourceDirectory" location="Source" />
<property name="shadersDirectory" location="${sourceDirectory}/Shaders" />
<property name="examplesDirectory" location="Examples" />
Expand Down Expand Up @@ -63,7 +94,6 @@
<!-- Scott Hunter is my hero. - Cozzi -->
<attribute name="destination" />
<attribute name="stripcomments" />
<attribute name="overwrite" />
<element name="fileset" type="fileset" />
<![CDATA[
importClass(java.io.File);
Expand All @@ -74,7 +104,6 @@ importClass(Packages.org.apache.tools.ant.util.FileUtils);
importClass(Packages.org.apache.tools.ant.filters.StripJavaComments);
var stripComments = attributes.get("stripcomments");
var overwrite = attributes.get("overwrite");
var destination = attributes.get("destination");
var filesets = elements.get("fileset");
for (var i = 0; i < filesets.size(); i++) {
Expand All @@ -87,20 +116,20 @@ for (var i = 0; i < filesets.size(); i++) {
var file = new File(basedir, filename);
var targetFile = new File(destination, file.getName().replace('.glsl', '.js'));
if (!overwrite && file.lastModified() < targetFile.lastModified()) {
if (file.lastModified() < targetFile.lastModified()) {
continue;
}
var reader = new FileReader(file);
var contents = new String(FileUtils.readFully(reader));
var contents = String(FileUtils.readFully(reader));
reader.close();
contents = contents.replace(/\r\n/gm, '\n');
var copyrightComments = contents.match(/\/\*\!(?:.|\n)*?\*\//gm) || [];
if (stripComments) {
contents = new String(FileUtils.readFully(new StripJavaComments(new StringReader(contents))));
contents = String(FileUtils.readFully(new StripJavaComments(new StringReader(contents))));
contents = contents.replace(/\s+$/gm, '').replace(/^\s+/gm, '').replace(/\n+/gm, '\n');
contents += '\n';
}
Expand All @@ -118,78 +147,112 @@ for (var i = 0; i < filesets.size(); i++) {
writer.close();
}
}
]]>
]]>
</scriptdef>

<scriptdef name="createMainJs" language="javascript">
<scriptdef name="createCesiumJs" language="javascript">
<attribute name="output" />
<element name="fileset" type="fileset" />
<![CDATA[
importClass(java.io.File);
importClass(java.io.FileReader);
importClass(java.io.FileWriter);
importClass(Packages.org.apache.tools.ant.util.FileUtils);
var moduleIDs = [];
var parameters = [];
var assignments = [];
var output = attributes.get("output");
var filesets = elements.get("fileset");
var moduleIDs = [], parameters = [], assignments = [];
for (var i = 0; i < filesets.size(); i++) {
for (var i = 0, len = filesets.size(); i < len; i++) {
var fileset = filesets.get(i);
var basedir = fileset.getDir(project);
var basedir = fileset.getDir(project);
var filenames = fileset.getDirectoryScanner(project).getIncludedFiles();
for (var j = 0; j < filenames.length; j++) {
for (var j = 0, len2 = filenames.length; j < len2; j++) {
var relativePath = filenames[j];
var file = new File(basedir, relativePath);
var baseName = file.getName();
baseName = baseName.substring(0, baseName.lastIndexOf('.'));
var moduleID = relativePath.replace('\\', '/');
moduleID = moduleID.substring(0, moduleID.lastIndexOf('.'));
var assignmentName = baseName;
var baseName = file.getName();
var assignmentName = baseName.substring(0, baseName.lastIndexOf('.'));
if (/Shaders\//.test(moduleID)) {
assignmentName = '_shaders.' + assignmentName;
}
var parameterName = moduleID.replace('/', '_');
moduleIDs.push('"' + moduleID + '"');
moduleIDs.push("'" + moduleID + "'");
parameters.push(parameterName);
assignments.push('Cesium.' + assignmentName + ' = ' + parameterName + ';');
}
}
var contents = 'var Cesium = window.Cesium = {_shaders:{}};\n' +
'require([' + moduleIDs.join(', ') + '], function (' + parameters.join(', ') + ') {\n' +
assignments.join('\n') + '\n' +
'}, undefined, true);';
var output = attributes.get("output");
if (new File(output).exists()) {
var reader = new FileReader(output);
var oldContents = String(FileUtils.readFully(reader));
reader.close();
}
var writer = new FileWriter(output);
writer.write(contents);
writer.close();
]]>
var contents = '/*global define*/\n' +
'define([' + moduleIDs.join(', ') + '], function (' + parameters.join(', ') + ') {\n' +
' "use strict";\n' +
' var Cesium = { _shaders : {} };\n ' +
assignments.join('\n ') + '\n' +
' return Cesium;\n' +
'});';
if (oldContents !== contents) {
var writer = new FileWriter(output);
writer.write(contents);
writer.close();
}
]]>
</scriptdef>

<!-- ********************************************************************** -->
<scriptdef name="createSpecList" language="javascript">
<attribute name="output" />
<element name="fileset" type="fileset" />
<![CDATA[
importClass(java.io.File);
importClass(java.io.FileReader);
importClass(java.io.FileWriter);
importClass(Packages.org.apache.tools.ant.util.FileUtils);
<target name="convertShadersToJavaScript">
<glslToJavascript destination="${shadersDirectory}" stripcomments="${build.minification}">
<fileset dir="${shadersDirectory}" includes="*.glsl" />
</glslToJavascript>
</target>
var specs = [];
<target name="buildSpecList">
<pathconvert property="specList" pathsep="," dirsep="/">
<fileset dir="${specsDirectory}" includes="**/*.js" excludes="*.js" />
<globmapper from="${specsDirectory}/*.js" to="'*'" handledirsep="true" />
</pathconvert>
<echo file="Specs/SpecList.js" message="var specs = [${specList}];" />
</target>
var filesets = elements.get("fileset");
for (var i = 0, len = filesets.size(); i < len; i++) {
var fileset = filesets.get(i);
var basedir = fileset.getDir(project);
var filenames = fileset.getDirectoryScanner(project).getIncludedFiles();
<target name="combineJavaScript.createMain">
<createMainJs output="${sourceDirectory}/main.js">
<fileset dir="${sourceDirectory}" includes="**/*.js" excludes="main.js" />
</createMainJs>
</target>
for (var j = 0, len2 = filenames.length; j < len2; j++) {
var relativePath = filenames[j];
var spec = relativePath.substring(0, relativePath.lastIndexOf('.')).replace('\\', '/');
specs.push("'" + spec + "'");
}
}
var output = attributes.get("output");
if (new File(output).exists()) {
var reader = new FileReader(output);
var oldContents = String(FileUtils.readFully(reader));
reader.close();
}
var contents = 'var specs = [' + specs.join(',') + '];';
if (oldContents !== contents) {
var writer = new FileWriter(output);
writer.write(contents);
writer.close();
}
]]>
</scriptdef>

<target name="combineJavaScript.setNodePathValue">
<condition property="nodePathValue" value="${toolsDirectory}/nodejs-0.6.17/windows/node.exe">
Expand Down Expand Up @@ -251,14 +314,14 @@ writer.close();
<delete file="${buildDirectory}\temp.js" />
</target>

<target name="combineJavaScript.createUnminified" depends="combineJavaScript.setNodePath,combineJavaScript.createMain">
<target name="combineJavaScript.createUnminified" depends="combineJavaScript.setNodePath">
<antcall target="combineJavaScript.runrjs">
<param name="optimize" value="none" />
</antcall>
<copy file="${builtCesiumFile}" tofile="${buildDirectory}/CesiumUnminified.js" />
</target>

<target name="combineJavaScript.createMinified" if="${build.minification}" depends="combineJavaScript.createMain">
<target name="combineJavaScript.createMinified" if="${build.minification}">
<antcall target="combineJavaScript.runrjs">
<param name="optimize" value="uglify" />
</antcall>
Expand All @@ -281,9 +344,9 @@ writer.close();

<target name="generateDocumentation">
<!--
These needs to be a relative path because Rhino doesn't work properly with Windows
These needs to be a relative path because Rhino doesn't work properly with Windows
absolute paths:
https://github.com/mozilla/rhino/issues/10
https://github.com/mozilla/rhino/issues/10
-->
<property name="relativeDocOutputDirectory" location="${buildDocumentationDirectory}" relative="true" basedir="${jsdoc3Directory}" />
<property name="relativeSourceFilesPath" location="${sourceDirectory}" relative="true" basedir="${jsdoc3Directory}" />
Expand Down
19 changes: 19 additions & 0 deletions launches/makeZipFile.launch
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ant.AntLaunchConfigurationType">
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/Cesium/build.xml"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.ui.externaltools.launchGroup"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="Cesium"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_ANT_TARGETS" value="makeZipFile,"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/Cesium/build.xml}"/>
<stringAttribute key="process_factory_id" value="org.eclipse.ant.ui.remoteAntProcessFactory"/>
</launchConfiguration>

2 comments on commit f3e085d

@pjcozzi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Is there anything else we need to do before we can start making zips and uploading them?

@shunter
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, just adjust the version in build.xml if necessary, maybe do a clean, then run makeZipFile.

Please sign in to comment.