summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile11
-rw-r--r--platform/android/scripts/generate-style-code.js42
-rw-r--r--platform/darwin/scripts/generate-style-code.js20
-rw-r--r--scripts/generate-style-code.js27
-rw-r--r--scripts/style-code.js36
5 files changed, 68 insertions, 68 deletions
diff --git a/Makefile b/Makefile
index 5b040c558e..2046f606a0 100644
--- a/Makefile
+++ b/Makefile
@@ -273,8 +273,10 @@ ideploy:
idocument:
OUTPUT=$(OUTPUT) ./platform/ios/scripts/document.sh
-style-code-darwin:
+.PHONY: darwin-style-code
+darwin-style-code:
node platform/darwin/scripts/generate-style-code.js
+style-code: darwin-style-code
endif
#### Linux targets #####################################################
@@ -467,13 +469,14 @@ test-node: node
ANDROID_ENV = platform/android/scripts/toolchain.sh
ANDROID_ABIS = arm-v5 arm-v7 arm-v8 x86 x86-64 mips
-.PHONY: style-code-android
-style-code-android: $(BUILD_DEPS)
+.PHONY: android-style-code
+android-style-code:
node platform/android/scripts/generate-style-code.js
+style-code: android-style-code
define ANDROID_RULES
-build/android-$1/$(BUILDTYPE): style-code-android
+build/android-$1/$(BUILDTYPE): $(BUILD_DEPS)
mkdir -p build/android-$1/$(BUILDTYPE)
build/android-$1/$(BUILDTYPE)/toolchain.cmake: platform/android/scripts/toolchain.sh build/android-$1/$(BUILDTYPE)
diff --git a/platform/android/scripts/generate-style-code.js b/platform/android/scripts/generate-style-code.js
index 1216bd4cbe..a19cc7c9b0 100644
--- a/platform/android/scripts/generate-style-code.js
+++ b/platform/android/scripts/generate-style-code.js
@@ -5,6 +5,8 @@ const ejs = require('ejs');
const spec = require('mapbox-gl-style-spec').latest;
const _ = require('lodash');
+require('../../../scripts/style-code');
+
// Specification parsing //
//Collect layer types from spec
@@ -38,29 +40,6 @@ const paintProperties = _(layers).map('paintProperties').flatten().value();
const allProperties = _(layoutProperties).union(paintProperties).value();
const enumProperties = _(allProperties).filter({'type': 'enum'}).value();
-// Global functions //
-
-global.iff = function (condition, val) {
- return condition() ? val : "";
-}
-
-
-global.camelize = function (str) {
- return str.replace(/(?:^|-)(.)/g, function (_, x) {
- return x.toUpperCase();
- });
-}
-
-global.camelizeWithLeadingLowercase = function (str) {
- return str.replace(/-(.)/g, function (_, x) {
- return x.toUpperCase();
- });
-}
-
-global.snakeCaseUpper = function snakeCaseUpper(str) {
- return str.replace(/-/g, "_").toUpperCase();
-}
-
global.propertyType = function propertyType(property) {
switch (property.type) {
case 'boolean':
@@ -235,7 +214,6 @@ global.propertyValueDoc = function (property, value) {
// Template processing //
-
// Java + JNI Layers (Peer model)
const layerHpp = ejs.compile(fs.readFileSync('platform/android/src/style/layers/layer.hpp.ejs', 'utf8'), {strict: true});
const layerCpp = ejs.compile(fs.readFileSync('platform/android/src/style/layers/layer.cpp.ejs', 'utf8'), {strict: true});
@@ -243,23 +221,23 @@ const layerJava = ejs.compile(fs.readFileSync('platform/android/MapboxGLAndroidS
const layerJavaUnitTests = ejs.compile(fs.readFileSync('platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs', 'utf8'), {strict: true});
for (const layer of layers) {
- fs.writeFileSync(`platform/android/src/style/layers/${layer.type}_layer.hpp`, layerHpp(layer));
- fs.writeFileSync(`platform/android/src/style/layers/${layer.type}_layer.cpp`, layerCpp(layer));
- fs.writeFileSync(`platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/${camelize(layer.type)}Layer.java`, layerJava(layer));
- fs.writeFileSync(`platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/${camelize(layer.type)}LayerTest.java`, layerJavaUnitTests(layer));
+ writeIfModified(`platform/android/src/style/layers/${layer.type}_layer.hpp`, layerHpp(layer));
+ writeIfModified(`platform/android/src/style/layers/${layer.type}_layer.cpp`, layerCpp(layer));
+ writeIfModified(`platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/${camelize(layer.type)}Layer.java`, layerJava(layer));
+ writeIfModified(`platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/${camelize(layer.type)}LayerTest.java`, layerJavaUnitTests(layer));
}
// Java PropertyFactory
const propertiesTemplate = ejs.compile(fs.readFileSync('platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property_factory.java.ejs', 'utf8'), {strict: true});
-fs.writeFileSync(
+writeIfModified(
`platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java`,
propertiesTemplate({layoutProperties: layoutProperties, paintProperties: paintProperties})
);
// Java Property
const enumPropertyJavaTemplate = ejs.compile(fs.readFileSync('platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property.java.ejs', 'utf8'), {strict: true});
-fs.writeFileSync(
+writeIfModified(
`platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java`,
enumPropertyJavaTemplate({properties: enumProperties})
);
@@ -269,14 +247,14 @@ const enumPropertiesDeDup = _(enumProperties).uniqBy(global.propertyNativeType).
// JNI Enum property conversion templates
const enumPropertyHppTypeStringValueTemplate = ejs.compile(fs.readFileSync('platform/android/src/style/conversion/types_string_values.hpp.ejs', 'utf8'), {strict: true});
-fs.writeFileSync(
+writeIfModified(
`platform/android/src/style/conversion/types_string_values.hpp`,
enumPropertyHppTypeStringValueTemplate({properties: enumPropertiesDeDup})
);
// JNI property value types conversion templates
const enumPropertyHppTypeTemplate = ejs.compile(fs.readFileSync('platform/android/src/style/conversion/types.hpp.ejs', 'utf8'), {strict: true});
-fs.writeFileSync(
+writeIfModified(
`platform/android/src/style/conversion/types.hpp`,
enumPropertyHppTypeTemplate({properties: enumPropertiesDeDup})
);
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js
index 80d7504de4..c4652e4e9b 100644
--- a/platform/darwin/scripts/generate-style-code.js
+++ b/platform/darwin/scripts/generate-style-code.js
@@ -6,21 +6,11 @@ const _ = require('lodash');
const colorParser = require('csscolorparser');
const spec = _.merge(require('mapbox-gl-style-spec').latest, require('./style-spec-overrides-v8.json'));
+require('../../../scripts/style-code');
+
const prefix = 'MGL';
const suffix = 'StyleLayer';
-global.camelize = function (str) {
- return str.replace(/(?:^|-)(.)/g, function (_, x) {
- return x.toUpperCase();
- });
-};
-
-global.camelizeWithLeadingLowercase = function (str) {
- return str.replace(/-(.)/g, function (_, x) {
- return x.toUpperCase();
- });
-};
-
global.objCName = function (property) {
return camelizeWithLeadingLowercase(property.name);
}
@@ -346,7 +336,7 @@ ${macosComment}${decl}
}
for (var layer of layers) {
- fs.writeFileSync(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.h`, duplicatePlatformDecls(layerH(layer)));
- fs.writeFileSync(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.mm`, layerM(layer));
- fs.writeFileSync(`platform/darwin/test/${prefix}${camelize(layer.type)}${suffix}Tests.m`, testLayers(layer));
+ writeIfModified(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.h`, duplicatePlatformDecls(layerH(layer)));
+ writeIfModified(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.mm`, layerM(layer));
+ writeIfModified(`platform/darwin/test/${prefix}${camelize(layer.type)}${suffix}Tests.m`, testLayers(layer));
}
diff --git a/scripts/generate-style-code.js b/scripts/generate-style-code.js
index dcb527e8c9..005bc022df 100644
--- a/scripts/generate-style-code.js
+++ b/scripts/generate-style-code.js
@@ -5,6 +5,8 @@ const ejs = require('ejs');
const spec = require('mapbox-gl-style-spec').latest;
var colorParser = require('csscolorparser');
+require('./style-code');
+
function parseCSSColor(str) {
var color = colorParser.parseCSSColor(str);
return [
@@ -12,18 +14,6 @@ function parseCSSColor(str) {
];
}
-global.camelize = function (str) {
- return str.replace(/(?:^|-)(.)/g, function (_, x) {
- return x.toUpperCase();
- });
-}
-
-global.camelizeWithLeadingLowercase = function (str) {
- return str.replace(/-(.)/g, function (_, x) {
- return x.toUpperCase();
- });
-}
-
global.propertyType = function (property) {
if (/-translate-anchor$/.test(property.name)) {
return 'TranslateAnchorType';
@@ -121,16 +111,19 @@ const layers = Object.keys(spec.layer.type.values).map((type) => {
type: type,
layoutProperties: layoutProperties,
paintProperties: paintProperties,
+ doc: spec.layer.type.values[type].doc,
+ layoutPropertiesByName: spec[`layout_${type}`],
+ paintPropertiesByName: spec[`paint_${type}`],
};
});
for (const layer of layers) {
- fs.writeFileSync(`include/mbgl/style/layers/${layer.type}_layer.hpp`, layerHpp(layer));
- fs.writeFileSync(`src/mbgl/style/layers/${layer.type}_layer.cpp`, layerCpp(layer));
+ writeIfModified(`include/mbgl/style/layers/${layer.type}_layer.hpp`, layerHpp(layer));
+ writeIfModified(`src/mbgl/style/layers/${layer.type}_layer.cpp`, layerCpp(layer));
- fs.writeFileSync(`src/mbgl/style/layers/${layer.type}_layer_properties.hpp`, propertiesHpp(layer));
- fs.writeFileSync(`src/mbgl/style/layers/${layer.type}_layer_properties.cpp`, propertiesCpp(layer));
+ writeIfModified(`src/mbgl/style/layers/${layer.type}_layer_properties.hpp`, propertiesHpp(layer));
+ writeIfModified(`src/mbgl/style/layers/${layer.type}_layer_properties.cpp`, propertiesCpp(layer));
}
const propertySettersHpp = ejs.compile(fs.readFileSync('include/mbgl/style/conversion/make_property_setters.hpp.ejs', 'utf8'), {strict: true});
-fs.writeFileSync('include/mbgl/style/conversion/make_property_setters.hpp', propertySettersHpp({layers: layers}));
+writeIfModified('include/mbgl/style/conversion/make_property_setters.hpp', propertySettersHpp({layers: layers}));
diff --git a/scripts/style-code.js b/scripts/style-code.js
new file mode 100644
index 0000000000..156934a240
--- /dev/null
+++ b/scripts/style-code.js
@@ -0,0 +1,36 @@
+// Global functions //
+
+const fs = require('fs');
+
+global.iff = function (condition, val) {
+ return condition() ? val : "";
+};
+
+global.camelize = function (str) {
+ return str.replace(/(?:^|-)(.)/g, function (_, x) {
+ return x.toUpperCase();
+ });
+};
+
+global.camelizeWithLeadingLowercase = function (str) {
+ return str.replace(/-(.)/g, function (_, x) {
+ return x.toUpperCase();
+ });
+};
+
+global.snakeCaseUpper = function snakeCaseUpper(str) {
+ return str.replace(/-/g, "_").toUpperCase();
+};
+
+global.writeIfModified = function(filename, newContent) {
+ try {
+ const oldContent = fs.readFileSync(filename, 'utf8');
+ if (oldContent == newContent) {
+ console.warn(`* Skipping current file '${filename}'`);
+ return;
+ }
+ } catch(err) {
+ }
+ fs.writeFileSync(filename, newContent);
+ console.warn(`* Updating outdated file '${filename}'`);
+};