diff --git a/.travis.yml b/.travis.yml index 995551df..57113f77 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,13 @@ -language: c -compiler: - - clang - - gcc -before_script: - - sudo apt-get update -q - - sudo apt-get install nodejs -script: make +language: node_js +node_js: + - "0.12" + +sudo: false + +before_install: + - npm install grunt-cli -g + +addons: + apt: + packages: + - gcc \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index ba9eab71..28ca81ef 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -4,21 +4,33 @@ module.exports = function(grunt) { require('load-grunt-tasks')(grunt); + var config = { + libName: 'css-layout', + distFolder: 'dist', + srcFolder: 'src', + testFolder: 'src/__tests__', + cTestFiles: 'src/__tests__/Layout-test.c src/Layout.c src/Layout-test-utils.c', + cTestOutput: 'c_test', + javaLibFolder: 'src/java/lib', + 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' + }; + grunt.initConfig({ - paths: { - distFolder: 'dist', - srcFolder: 'src', - testFolder: 'src/__tests__', - }, + config: config, - clean: ['<%= paths.distFolder %>'], + clean: { + dist: ['<%= config.distFolder %>'], + cTest: ['<%= config.cTestOutput %>'], + javaTest: ['**/*.class'] + }, eslint: { options: { configFile: '.eslintrc' }, - target: ['<%= paths.srcFolder %>/Layout.js'] + target: ['<%= config.srcFolder %>/Layout.js'] }, includereplace: { @@ -26,8 +38,8 @@ module.exports = function(grunt) { prefix: '// @@', }, main: { - src: '<%= paths.srcFolder %>/css-layout.js', - dest: '<%= paths.distFolder %>/css-layout.js' + src: '<%= config.srcFolder %>/<%= config.libName %>.js', + dest: '<%= config.distFolder %>/<%= config.libName %>.js' } }, @@ -38,7 +50,8 @@ module.exports = function(grunt) { }, main: { files: { - '<%= paths.distFolder %>/css-layout.min.js': ['<%= paths.distFolder %>/css-layout.js'] + '<%= config.distFolder %>/<%= config.libName %>.min.js': + ['<%= config.distFolder %>/<%= config.libName %>.js'] } } }, @@ -47,20 +60,67 @@ module.exports = function(grunt) { main: { options: { files: [ - '<%= paths.srcFolder %>/Layout.js', - '<%= paths.srcFolder %>/Layout-test-utils.js', - '<%= paths.testFolder %>/Layout-test.js', - '<%= paths.testFolder %>/Layout-consts-test.js' + '<%= config.srcFolder %>/Layout.js', + '<%= config.srcFolder %>/Layout-test-utils.js', + '<%= config.testFolder %>/Layout-test.js', + '<%= config.testFolder %>/Layout-consts-test.js' ], browsers: ['Chrome'], frameworks: ['jasmine'], singleRun: true } } + }, + + execute: { + transpile: { + src: ['<%= config.srcFolder %>/transpile.js'] + } + }, + + shell: { + cCompile: { + command: 'gcc -std=c99 -Werror -Wno-padded <%= config.cTestFiles %> -lm -o "./<%= config.cTestOutput %>"' + }, + cTestExecute: { + command: './<%= config.cTestOutput %>' + }, + 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 %>' + }, + javaTestExecute: { + command: 'java -cp ./src/java/src:./src/java/tests:<%= config.javaLibFolder %>/junit4.jar:<%= config.javaLibFolder %>/infer-annotations-1.4.jar <%= config.javaTestFiles %>' + }, + javaPackage: { + command: 'jar cf <%= config.distFolder %>/<%= config.libName %>.jar <%= config.javaSource %>' + } } }); - grunt.registerTask('build', ['eslint', 'clean', 'karma' ,'includereplace', 'uglify']); + // Compiles and runs the Java tests + grunt.registerTask('test-java', ['shell:javaCompile', 'shell:javaTestExecute', 'clean:javaTest']); + + // Compiles and runs the C tests + grunt.registerTask('test-c', ['shell:cCompile', 'shell:cTestExecute', 'clean:cTest']); + + // Transpiles the JavaScript to C and Java, running tests + grunt.registerTask('transpile', ['execute:transpile', 'test-c', 'test-java']); + + // Lints and tests the JavaScritp using Chrome + grunt.registerTask('test-javascript', ['eslint', 'karma']); + + // Packages the JavaScript as a single UMD module and minifies + grunt.registerTask('package-javascript', ['includereplace', 'uglify']); + + // Packages the Java as a JAR + grunt.registerTask('package-java', ['shell:javaPackage']); + + // Default build, performs the full works! + grunt.registerTask('build', ['test-javascript', 'transpile', 'clean:dist', 'package-javascript', 'package-java']); + + // The JavaScript unit tests require Chrome (they need a faithful flexbox implementation + // to test against), so under CI this step is skipped. + grunt.registerTask('ci', ['eslint', 'transpile', 'clean:dist', 'package-javascript', 'package-java']); grunt.registerTask('default', ['build']); }; diff --git a/Makefile b/Makefile deleted file mode 100644 index 736e8f27..00000000 --- a/Makefile +++ /dev/null @@ -1,65 +0,0 @@ -# Copyright (c) 2014, Facebook, Inc. -# All rights reserved. -# -# This source code is licensed under the BSD-style license found in the -# LICENSE file in the root directory of this source tree. An additional grant -# of patent rights can be found in the PATENTS file in the same directory. - -FILES=src/__tests__/Layout-test.c src/Layout.c src/Layout-test-utils.c -JAVA_LIB_DIR=lib - -ifeq ($(OS),Windows_NT) - C_TEST_EXE=./c_test.exe - ENVSEP=";" - WGET=wget --no-check-certificate - LLDB=gdb -else - C_TEST_EXE=./c_test - ENVSEP=":" - WGET=wget - LLDB=lldb -endif - -all: c c_test java java_test - -c: transpile_all - -ifeq ($(OS),Windows_NT) -c_test: c - @cl -nologo -Zi -Tpsrc/__tests__/Layout-test.c -Tpsrc/Layout.c -Tpsrc/Layout-test-utils.c -link -incremental:no -out:"$(C_TEST_EXE)" && "$(C_TEST_EXE)" - @rm "$(C_TEST_EXE)" ./*.obj ./*.pdb - -else -c_test: c - @gcc -std=c99 -Werror -Wno-padded $(FILES) -lm -o "$(C_TEST_EXE)" && "$(C_TEST_EXE)" - @rm "$(C_TEST_EXE)" - -debug: - @gcc -std=c99 -ggdb $(FILES) -lm -o $(C_TEST_EXE) && $(LLDB) $(C_TEST_EXE) - @rm $(C_TEST_EXE) - -endif - -$(JAVA_LIB_DIR): - mkdir $(JAVA_LIB_DIR) - -$(JAVA_LIB_DIR)/junit4.jar: | $(JAVA_LIB_DIR) - $(WGET) -O $(JAVA_LIB_DIR)/junit4.jar http://search.maven.org/remotecontent?filepath=junit/junit/4.10/junit-4.10.jar - -$(JAVA_LIB_DIR)/jsr305.jar: | $(JAVA_LIB_DIR) - $(WGET) -O $(JAVA_LIB_DIR)/jsr305.jar http://search.maven.org/remotecontent?filepath=net/sourceforge/findbugs/jsr305/1.3.7/jsr305-1.3.7.jar - -$(JAVA_LIB_DIR)/infer-annotations-1.4.jar: | $(JAVA_LIB_DIR) - $(WGET) -O $(JAVA_LIB_DIR)/infer-annotations-1.4.jar https://github.com/facebook/buck/raw/027ffe2b230c08cad7b340646c6f801bd6dabc78/third-party/java/infer-annotations/infer-annotations-1.4.jar - -java: transpile_all src/java | $(JAVA_LIB_DIR)/junit4.jar $(JAVA_LIB_DIR)/jsr305.jar $(JAVA_LIB_DIR)/infer-annotations-1.4.jar - @javac -cp ./$(JAVA_LIB_DIR)/junit4.jar$(ENVSEP)./$(JAVA_LIB_DIR)/jsr305.jar$(ENVSEP)./$(JAVA_LIB_DIR)/infer-annotations-1.4.jar -sourcepath ./src/java/src$(ENVSEP)./src/java/tests src/java/tests/com/facebook/csslayout/*.java - -java_test: java - @java -cp ./src/java/src$(ENVSEP)./src/java/tests$(ENVSEP)./$(JAVA_LIB_DIR)/junit4.jar$(ENVSEP)./$(JAVA_LIB_DIR)/infer-annotations-1.4.jar org.junit.runner.JUnitCore \ - com.facebook.csslayout.LayoutEngineTest \ - com.facebook.csslayout.LayoutCachingTest \ - com.facebook.csslayout.CSSNodeTest - -transpile_all: ./src/transpile.js - @node ./src/transpile.js diff --git a/README.md b/README.md index 965aa6ff..1f54abd2 100644 --- a/README.md +++ b/README.md @@ -82,9 +82,10 @@ Development The core logic resides with `Layout.js`, which is transpiled into equivalent C and Java implementations. -To run the tests +The JavaScript build process is managed via Grunt. The build performs linting, runs the tests against Chrome, transpiles and packages the code (JavaScript and Java) into the `dist` folder. For JavaScript, the build output uses the Universal Module Format (UMD) so that it can be used via AMD / RequireJS, CommonJS or included directly into an HTML page. -- For the JS tests: run `grunt karma` -- For the C and Java tests: run `make` in your terminal. It will also transpile the JS code. This build is also run via Travis CI. +While developing you can just run the lint / Chrome-based tests a follows: -The JavaScript build process is managed via Grunt. The build performs linting, runs the tests and produce a minified version of the code within a `dist` folder. The build output uses the Universal Module Format (UMD) so that it can be used via AMD / RequireJS, CommonJS or included directly into an HTML page. +``` +grunt test-javascript +``` diff --git a/dist/css-layout.jar b/dist/css-layout.jar new file mode 100644 index 00000000..b28dea04 Binary files /dev/null and b/dist/css-layout.jar differ diff --git a/package.json b/package.json index a3550da1..812f0f29 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,9 @@ "version": "0.0.2", "description": "Reimplementation of CSS layout using pure JavaScript", "main": "src/main.js", + "scripts": { + "test": "grunt ci" + }, "repository": { "type": "git", "url": "https://github.com/facebook/css-layout.git" @@ -20,8 +23,10 @@ "grunt-contrib-copy": "^0.8.0", "grunt-contrib-uglify": "^0.9.1", "grunt-eslint": "^17.1.0", + "grunt-execute": "^0.2.2", "grunt-include-replace": "^3.1.0", "grunt-karma": "^0.12.0", + "grunt-shell": "^1.1.2", "jasmine-core": "^2.2.0", "karma": "^0.13.8", "karma-chrome-launcher": "^0.1.7", diff --git a/src/java/lib/infer-annotations-1.4.jar b/src/java/lib/infer-annotations-1.4.jar new file mode 100644 index 00000000..42722464 Binary files /dev/null and b/src/java/lib/infer-annotations-1.4.jar differ diff --git a/src/java/lib/jsr305.jar b/src/java/lib/jsr305.jar new file mode 100644 index 00000000..43807b02 Binary files /dev/null and b/src/java/lib/jsr305.jar differ diff --git a/src/java/lib/junit4.jar b/src/java/lib/junit4.jar new file mode 100644 index 00000000..954851e6 Binary files /dev/null and b/src/java/lib/junit4.jar differ