Add optional split output location to codegen scripts (#2152)

This commit is contained in:
mwilsnd
2024-02-27 16:11:33 -05:00
committed by GitHub
parent f27848fdaa
commit 003c062c25
3 changed files with 34 additions and 31 deletions

View File

@@ -15,8 +15,8 @@ const args = (() => {
const parser = new ArgumentParser({ const parser = new ArgumentParser({
description: "MapLibre Shader Tools" description: "MapLibre Shader Tools"
}); });
parser.add_argument("--root", "--r", { parser.add_argument("--out", "--o", {
help: "Directory root to place generated code", help: "Directory root to write generated code.",
required: false required: false
}); });
return parser.parse_args(); return parser.parse_args();
@@ -787,7 +787,8 @@ const lightProperties = Object.keys(spec['light']).reduce((memo, name) => {
const lightDoc = spec['light-cocoa-doc']; const lightDoc = spec['light-cocoa-doc'];
const lightType = 'light'; const lightType = 'light';
const root = args.root ? args.root : path.dirname(path.dirname(path.dirname(__dirname))); const root = path.dirname(path.dirname(path.dirname(__dirname)));
const outLocation = args.out ? args.out : root;
const layerH = readAndCompile('platform/darwin/src/MLNStyleLayer.h.ejs', root); const layerH = readAndCompile('platform/darwin/src/MLNStyleLayer.h.ejs', root);
const layerPrivateH = readAndCompile('platform/darwin/src/MLNStyleLayer_Private.h.ejs', root); const layerPrivateH = readAndCompile('platform/darwin/src/MLNStyleLayer_Private.h.ejs', root);
@@ -801,11 +802,11 @@ const lightH = readAndCompile('platform/darwin/src/MLNLight.h.ejs', root);
const lightM = readAndCompile('platform/darwin/src/MLNLight.mm.ejs', root); const lightM = readAndCompile('platform/darwin/src/MLNLight.mm.ejs', root);
const testLight = readAndCompile('platform/darwin/test/MLNLightTest.mm.ejs', root); const testLight = readAndCompile('platform/darwin/test/MLNLightTest.mm.ejs', root);
writeIfModified(`platform/darwin/src/MLNLight.h`, duplicatePlatformDecls( writeIfModified(`platform/darwin/src/MLNLight.h`, duplicatePlatformDecls(
lightH({ properties: lightProperties, doc: lightDoc, type: lightType })), root); lightH({ properties: lightProperties, doc: lightDoc, type: lightType })), outLocation);
writeIfModified(`platform/darwin/src/MLNLight.mm`, writeIfModified(`platform/darwin/src/MLNLight.mm`,
lightM({ properties: lightProperties, doc: lightDoc, type: lightType }), root); lightM({ properties: lightProperties, doc: lightDoc, type: lightType }), outLocation);
writeIfModified(`platform/darwin/test/MLNLightTest.mm`, writeIfModified(`platform/darwin/test/MLNLightTest.mm`,
testLight({ properties: lightProperties, doc: lightDoc, type: lightType }), root); testLight({ properties: lightProperties, doc: lightDoc, type: lightType }), outLocation);
const layers = _(spec.layer.type.values).map((value, layerType) => { const layers = _(spec.layer.type.values).map((value, layerType) => {
const layoutProperties = Object.keys(spec[`layout_${layerType}`]).reduce((memo, name) => { const layoutProperties = Object.keys(spec[`layout_${layerType}`]).reduce((memo, name) => {
@@ -879,13 +880,13 @@ for (var layer of layers) {
} }
writeIfModified(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.h`, writeIfModified(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.h`,
duplicatePlatformDecls(layerH(layer)), root); duplicatePlatformDecls(layerH(layer)), outLocation);
writeIfModified(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}_Private.h`, writeIfModified(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}_Private.h`,
duplicatePlatformDecls(layerPrivateH(layer)), root); duplicatePlatformDecls(layerPrivateH(layer)), outLocation);
writeIfModified(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.mm`, writeIfModified(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.mm`,
layerM(layer), root); layerM(layer), outLocation);
writeIfModified(`platform/darwin/test/${prefix}${camelize(layer.type)}${suffix}Tests.mm`, writeIfModified(`platform/darwin/test/${prefix}${camelize(layer.type)}${suffix}Tests.mm`,
testLayers(layer), root); testLayers(layer), outLocation);
} }
// Extract examples for guides from unit tests. // Extract examples for guides from unit tests.
@@ -927,21 +928,21 @@ writeIfModified(`platform/ios/docs/guides/For Style Authors.md`, forStyleAuthors
os: 'iOS', os: 'iOS',
renamedProperties: renamedPropertiesByLayerType, renamedProperties: renamedPropertiesByLayerType,
layers: layers, layers: layers,
}), root); }), outLocation);
writeIfModified(`platform/macos/docs/guides/For Style Authors.md`, forStyleAuthorsMD({ writeIfModified(`platform/macos/docs/guides/For Style Authors.md`, forStyleAuthorsMD({
os: 'macOS', os: 'macOS',
renamedProperties: renamedPropertiesByLayerType, renamedProperties: renamedPropertiesByLayerType,
layers: layers, layers: layers,
}), root); }), outLocation);
writeIfModified(`platform/ios/docs/guides/Migrating to Expressions.md`, ddsGuideMD({ writeIfModified(`platform/ios/docs/guides/Migrating to Expressions.md`, ddsGuideMD({
os: 'iOS', os: 'iOS',
}), root); }), outLocation);
writeIfModified(`platform/macos/docs/guides/Migrating to Expressions.md`, ddsGuideMD({ writeIfModified(`platform/macos/docs/guides/Migrating to Expressions.md`, ddsGuideMD({
os: 'macOS', os: 'macOS',
}), root); }), outLocation);
writeIfModified(`platform/ios/docs/guides/Tile URL Templates.md`, templatesMD({ writeIfModified(`platform/ios/docs/guides/Tile URL Templates.md`, templatesMD({
os: 'iOS', os: 'iOS',
}), root); }), outLocation);
writeIfModified(`platform/macos/docs/guides/Tile URL Templates.md`, templatesMD({ writeIfModified(`platform/macos/docs/guides/Tile URL Templates.md`, templatesMD({
os: 'macOS', os: 'macOS',
}), root);*/ }), rooutLocationot);*/

View File

@@ -14,8 +14,8 @@ const args = (() => {
const parser = new ArgumentParser({ const parser = new ArgumentParser({
description: "MapLibre Shader Tools" description: "MapLibre Shader Tools"
}); });
parser.add_argument("--root", "--r", { parser.add_argument("--out", "--o", {
help: "Directory root to place generated code", help: "Directory root to write generated code.",
required: false required: false
}); });
return parser.parse_args(); return parser.parse_args();
@@ -222,7 +222,8 @@ global.defaultValue = function (property) {
}; };
console.log("Generating style code..."); console.log("Generating style code...");
const root = args.root ? args.root : path.dirname(__dirname); const root = path.dirname(__dirname);
const outLocation = args.out ? args.out : root;
const layerHpp = readAndCompile(`include/mbgl/style/layers/layer.hpp.ejs`, root); const layerHpp = readAndCompile(`include/mbgl/style/layers/layer.hpp.ejs`, root);
const layerCpp = readAndCompile(`src/mbgl/style/layers/layer.cpp.ejs`, root); const layerCpp = readAndCompile(`src/mbgl/style/layers/layer.cpp.ejs`, root);
@@ -275,16 +276,16 @@ const layers = Object.keys(spec.layer.type.values).map((type) => {
for (const layer of layers) { for (const layer of layers) {
const layerFileName = layer.type.replace('-', '_'); const layerFileName = layer.type.replace('-', '_');
writeIfModified(`src/mbgl/style/layers/${layerFileName}_layer_properties.hpp`, propertiesHpp(layer), root); writeIfModified(`src/mbgl/style/layers/${layerFileName}_layer_properties.hpp`, propertiesHpp(layer), outLocation);
writeIfModified(`src/mbgl/style/layers/${layerFileName}_layer_properties.cpp`, propertiesCpp(layer), root); writeIfModified(`src/mbgl/style/layers/${layerFileName}_layer_properties.cpp`, propertiesCpp(layer), outLocation);
// Remove our fake property for the external interace. // Remove our fake property for the external interace.
if (layer.type === 'line') { if (layer.type === 'line') {
layer.paintProperties = layer.paintProperties.filter(property => property.name !== 'line-floor-width'); layer.paintProperties = layer.paintProperties.filter(property => property.name !== 'line-floor-width');
} }
writeIfModified(`include/mbgl/style/layers/${layerFileName}_layer.hpp`, layerHpp(layer), root); writeIfModified(`include/mbgl/style/layers/${layerFileName}_layer.hpp`, layerHpp(layer), outLocation);
writeIfModified(`src/mbgl/style/layers/${layerFileName}_layer.cpp`, layerCpp(layer), root); writeIfModified(`src/mbgl/style/layers/${layerFileName}_layer.cpp`, layerCpp(layer), outLocation);
} }
// Light // Light
@@ -302,5 +303,5 @@ lightProperties.sort((a, b) => collator.compare(a.name, b.name));
const lightHpp = readAndCompile(`include/mbgl/style/light.hpp.ejs`, root); const lightHpp = readAndCompile(`include/mbgl/style/light.hpp.ejs`, root);
const lightCpp = readAndCompile(`src/mbgl/style/light.cpp.ejs`, root); const lightCpp = readAndCompile(`src/mbgl/style/light.cpp.ejs`, root);
writeIfModified(`include/mbgl/style/light.hpp`, lightHpp({properties: lightProperties}), root); writeIfModified(`include/mbgl/style/light.hpp`, lightHpp({properties: lightProperties}), outLocation);
writeIfModified(`src/mbgl/style/light.cpp`, lightCpp({properties: lightProperties}), root); writeIfModified(`src/mbgl/style/light.cpp`, lightCpp({properties: lightProperties}), outLocation);

View File

@@ -62,7 +62,7 @@ ${precision} ${type} ${name} = u_${name};
return source.replace(re, (match, operation, precision, type, name) => { return source.replace(re, (match, operation, precision, type, name) => {
const attrType = type === 'float' ? 'vec2' : 'vec4'; const attrType = type === 'float' ? 'vec2' : 'vec4';
const unpackType = name.match(/color/) ? 'color' : attrType; const unpackType = name.match(/color/) ? 'color' : attrType;
if (pragmaMap[name]) { if (pragmaMap[name]) {
if (operation === 'define') { if (operation === 'define') {
return `#ifndef HAS_UNIFORM_u_${name} return `#ifndef HAS_UNIFORM_u_${name}
@@ -140,7 +140,7 @@ ${precision} ${type} ${name} = u_${name};
return source.replace(re, (match, operation, precision, type, name) => { return source.replace(re, (match, operation, precision, type, name) => {
const attrType = type === 'float' ? 'vec2' : 'vec4'; const attrType = type === 'float' ? 'vec2' : 'vec4';
const unpackType = name.match(/color/) ? 'color' : attrType; const unpackType = name.match(/color/) ? 'color' : attrType;
if (pragmaMap[name]) { if (pragmaMap[name]) {
if (operation === 'define') { if (operation === 'define') {
return `#ifndef HAS_UNIFORM_u_${name} return `#ifndef HAS_UNIFORM_u_${name}
@@ -202,8 +202,8 @@ const args = (() => {
const parser = new ArgumentParser({ const parser = new ArgumentParser({
description: "MapLibre Shader Tools" description: "MapLibre Shader Tools"
}); });
parser.add_argument("--root", "--r", { parser.add_argument("--out", "--o", {
help: "Directory root to place generated code", help: "Directory root to write generated code.",
required: false required: false
}); });
parser.add_argument("--compress", "--c", { parser.add_argument("--compress", "--c", {
@@ -220,9 +220,10 @@ const args = (() => {
// Generate shader source headers // Generate shader source headers
const root = args.root ? args.root : path.dirname(__dirname); const root = path.dirname(__dirname);
const outLocation = args.out ? args.out : root;
const shaderRoot = path.join(root, "shaders"); const shaderRoot = path.join(root, "shaders");
const outputRoot = path.join(root, "include/mbgl/shaders"); const outputRoot = path.join(outLocation, "include/mbgl/shaders");
let generatedHeaders = []; let generatedHeaders = [];
let shaderNames = []; let shaderNames = [];