Merge pull request #109 from prenaux/master

Windows build, package C, and updated README
This commit is contained in:
Colin Eberhardt
2015-08-13 18:00:22 +01:00
5 changed files with 1393 additions and 14 deletions

View File

@@ -1,28 +1,54 @@
'use strict'; 'use strict';
module.exports = function(grunt) { module.exports = function(grunt) {
var fs = require('fs');
var path = require('path');
var isWindows = /^win/.test(process.platform);
require('load-grunt-tasks')(grunt); require('load-grunt-tasks')(grunt);
// config
var config = { var config = {
delimiter: path.delimiter,
libName: 'css-layout', libName: 'css-layout',
distFolder: 'dist', distFolder: 'dist',
srcFolder: 'src', srcFolder: 'src',
testFolder: 'src/__tests__', testFolder: 'src/__tests__',
cTestFiles: 'src/__tests__/Layout-test.c src/Layout.c src/Layout-test-utils.c',
cTestOutput: 'c_test',
javaLibFolder: 'src/java/lib', javaLibFolder: 'src/java/lib',
javaSource: 'src/java/tests/com/facebook/csslayout/*.java', javaSource: 'src/java/tests/com/facebook/csslayout/*.java',
javaTestFiles: 'org.junit.runner.JUnitCore com.facebook.csslayout.LayoutEngineTest com.facebook.csslayout.LayoutCachingTest com.facebook.csslayout.CSSNodeTest' javaTestFiles: 'org.junit.runner.JUnitCore com.facebook.csslayout.LayoutEngineTest com.facebook.csslayout.LayoutCachingTest com.facebook.csslayout.CSSNodeTest'
}; };
grunt.initConfig({ // C compilation configuration
if (isWindows) {
// Windows build, assumes cl is in the path (see https://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx).
config.cTestOutput = 'c_test.exe';
config.cTestCompile = 'cl -nologo -Zi -Tpsrc/__tests__/Layout-test.c -Tpsrc/Layout.c -Tpsrc/Layout-test-utils.c -link -incremental:no -out:"<%= config.cTestOutput %>"';
config.cTestExecute = '<%= config.cTestOutput %>';
config.cTestClean = ['<%= config.cTestOutput %>','*.obj','*.pdb'];
}
else {
// GCC build (OSX, Linux, ...), assumes gcc is in the path.
config.cTestOutput = 'c_test';
config.cTestCompile = 'gcc -std=c99 -Werror -Wno-padded src/__tests__/Layout-test.c src/Layout.c src/Layout-test-utils.c -lm -o "./<%= config.cTestOutput %>"';
config.cTestExecute = './<%= config.cTestOutput %>';
config.cTestClean = ['<%= config.cTestOutput %>'];
}
grunt.initConfig({
config: config, config: config,
mkdir: {
dist: {
options: {
create: ['<%= config.distFolder %>']
},
},
},
clean: { clean: {
dist: ['<%= config.distFolder %>'], dist: ['<%= config.distFolder %>'],
cTest: ['<%= config.cTestOutput %>'], cTest: config.cTestClean,
javaTest: ['**/*.class'] javaTest: ['**/*.class']
}, },
@@ -78,18 +104,47 @@ module.exports = function(grunt) {
} }
}, },
concat: {
options: {
separator: '\n',
// Replace all 'use strict' statements in the code with a single one at the top
banner: [
'/*',
' * #define CSS_LAYOUT_IMPLEMENTATION',
' * before you include this file in *one* C or C++ file to create the implementation.',
' */\n'
].join('\n'),
process: function(src, filepath) {
if (path.extname(filepath) === '.c') {
return [
'#ifdef CSS_LAYOUT_IMPLEMENTATION',
src,
'#endif // CSS_LAYOUT_IMPLEMENTATION'
].join('\n')
}
else {
return src;
}
},
},
dist: {
src: ['<%= config.srcFolder %>/Layout.h', '<%= config.srcFolder %>/Layout.c'],
dest: '<%= config.distFolder %>/css-layout.h',
},
},
shell: { shell: {
cCompile: { cCompile: {
command: 'gcc -std=c99 -Werror -Wno-padded <%= config.cTestFiles %> -lm -o "./<%= config.cTestOutput %>"' command: config.cTestCompile
}, },
cTestExecute: { cTestExecute: {
command: './<%= config.cTestOutput %>' command: config.cTestExecute
}, },
javaCompile: { javaCompile: {
command: 'javac -cp <%= config.javaLibFolder %>/junit4.jar:<%= config.javaLibFolder %>/jsr305.jar:<%= config.javaLibFolder %>/infer-annotations-1.4.jar -sourcepath ./src/java/src:./src/java/tests <%= config.javaSource %>' command: 'javac -cp <%= config.javaLibFolder %>/junit4.jar<%= config.delimiter %><%= config.javaLibFolder %>/jsr305.jar<%= config.delimiter %><%= config.javaLibFolder %>/infer-annotations-1.4.jar' + ' -sourcepath ./src/java/src<%= config.delimiter %>./src/java/tests' + ' <%= config.javaSource %>'
}, },
javaTestExecute: { javaTestExecute: {
command: 'java -cp ./src/java/src:./src/java/tests:<%= config.javaLibFolder %>/junit4.jar:<%= config.javaLibFolder %>/infer-annotations-1.4.jar <%= config.javaTestFiles %>' command: 'java -cp ./src/java/src<%= config.delimiter %>./src/java/tests<%= config.delimiter %><%= config.javaLibFolder %>/junit4.jar<%= config.delimiter %><%= config.javaLibFolder %>/infer-annotations-1.4.jar <%= config.javaTestFiles %>'
}, },
javaPackage: { javaPackage: {
command: 'jar cf <%= config.distFolder %>/<%= config.libName %>.jar <%= config.javaSource %>' command: 'jar cf <%= config.distFolder %>/<%= config.libName %>.jar <%= config.javaSource %>'
@@ -110,17 +165,20 @@ module.exports = function(grunt) {
grunt.registerTask('test-javascript', ['eslint', 'karma']); grunt.registerTask('test-javascript', ['eslint', 'karma']);
// Packages the JavaScript as a single UMD module and minifies // Packages the JavaScript as a single UMD module and minifies
grunt.registerTask('package-javascript', ['includereplace', 'uglify']); grunt.registerTask('package-javascript', ['mkdir:dist', 'includereplace', 'uglify']);
// Packages the Java as a JAR // Packages the Java as a JAR
grunt.registerTask('package-java', ['shell:javaPackage']); grunt.registerTask('package-java', ['mkdir:dist', 'shell:javaPackage']);
// Packages the C code as a single header
grunt.registerTask('package-c', ['mkdir:dist', 'concat']);
// Default build, performs the full works! // Default build, performs the full works!
grunt.registerTask('build', ['test-javascript', 'transpile', 'clean:dist', 'package-javascript', 'package-java']); grunt.registerTask('build', ['test-javascript', 'transpile', 'clean:dist', 'package-javascript', 'package-java', 'package-c']);
// The JavaScript unit tests require Chrome (they need a faithful flexbox implementation // The JavaScript unit tests require Chrome (they need a faithful flexbox implementation
// to test against), so under CI this step is skipped. // to test against), so under CI this step is skipped.
grunt.registerTask('ci', ['eslint', 'transpile', 'clean:dist', 'package-javascript', 'package-java']); grunt.registerTask('ci', ['eslint', 'transpile', 'clean:dist', 'package-javascript', 'package-java', 'package-c']);
grunt.registerTask('default', ['build']); grunt.registerTask('default', ['build']);
}; };

View File

@@ -43,7 +43,7 @@ padding, paddingLeft, paddingRight, paddingTop, paddingBottom | positive number
borderWidth, borderLeftWidth, borderRightWidth, borderTopWidth, borderBottomWidth | positive number borderWidth, borderLeftWidth, borderRightWidth, borderTopWidth, borderBottomWidth | positive number
flexDirection | 'column', 'row' flexDirection | 'column', 'row'
justifyContent | 'flex-start', 'center', 'flex-end', 'space-between', 'space-around' justifyContent | 'flex-start', 'center', 'flex-end', 'space-between', 'space-around'
alignItems, alignSelf | 'flex-start', 'center', 'flex-end', 'stretch' alignItems, alignSelf, alignContent | 'flex-start', 'center', 'flex-end', 'stretch'
flex | positive number flex | positive number
flexWrap | 'wrap', 'nowrap' flexWrap | 'wrap', 'nowrap'
position | 'relative', 'absolute' position | 'relative', 'absolute'
@@ -65,6 +65,7 @@ div, span {
flex-direction: column; flex-direction: column;
align-items: stretch; align-items: stretch;
flex-shrink: 0; flex-shrink: 0;
align-content: flex-start;
border: 0 solid black; border: 0 solid black;
margin: 0; margin: 0;

1315
dist/css-layout.h vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -20,12 +20,14 @@
"grunt": "^0.4.5", "grunt": "^0.4.5",
"grunt-cli": "^0.1.13", "grunt-cli": "^0.1.13",
"grunt-contrib-clean": "^0.6.0", "grunt-contrib-clean": "^0.6.0",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-copy": "^0.8.0", "grunt-contrib-copy": "^0.8.0",
"grunt-contrib-uglify": "^0.9.1", "grunt-contrib-uglify": "^0.9.1",
"grunt-eslint": "^17.1.0", "grunt-eslint": "^17.1.0",
"grunt-execute": "^0.2.2", "grunt-execute": "^0.2.2",
"grunt-include-replace": "^3.1.0", "grunt-include-replace": "^3.1.0",
"grunt-karma": "^0.12.0", "grunt-karma": "^0.12.0",
"grunt-mkdir": "^0.1.2",
"grunt-shell": "^1.1.2", "grunt-shell": "^1.1.2",
"jasmine-core": "^2.2.0", "jasmine-core": "^2.2.0",
"karma": "^0.13.8", "karma": "^0.13.8",

View File

@@ -12,7 +12,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
// in concatenated header, don't include Layout.h it's already at the top
#ifndef CSS_LAYOUT_IMPLEMENTATION
#include "Layout.h" #include "Layout.h"
#endif
#ifdef _MSC_VER #ifdef _MSC_VER
#include <float.h> #include <float.h>