Skip to content

Commit

Permalink
header dependency sequence changed to remove JsonData dependency adde…
Browse files Browse the repository at this point in the history
…d in the inculde files (to avoid cpp header dependency from c headers)
  • Loading branch information
HaseenaSainul committed Jun 14, 2023
1 parent 654cae9 commit 8e4ab25
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 73 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions languages/c/templates/imports/default.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "Common/${info.title}.h"
1 change: 1 addition & 0 deletions languages/c/templates/imports/default.jsondata
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "JsonData_${info.title}.h"
40 changes: 0 additions & 40 deletions languages/c/templates/modules/include/Common/Module.h

This file was deleted.

29 changes: 0 additions & 29 deletions languages/c/templates/modules/src/JsonData_Module.h

This file was deleted.

1 change: 1 addition & 0 deletions languages/c/templates/schemas/src/JsonData_Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#pragma once

/* ${IMPORTS} */
#include "Common/${info.title}.h"

namespace FireboltSDK {
Expand Down
1 change: 1 addition & 0 deletions languages/c/templates/schemas/src/Module_Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include "FireboltSDK.h"
/* ${IMPORTS} */
#include "JsonData_${info.title}.h"

/* ${ENUMS} */
Expand Down
15 changes: 11 additions & 4 deletions src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ const generateMacros = (obj, templates, languages, options = {}) => {
// grab the options so we don't have to pass them from method to method
Object.assign(state, options)

const imports = generateImports(obj, templates)
const imports = generateImports(obj, templates, { destination : (options.destination ? options.destination : '') })
const initialization = generateInitialization(obj, templates)
const enums = generateEnums(obj, templates, { destination : (options.destination ? options.destination : '') })
const eventsEnum = generateEvents(obj, templates)
Expand Down Expand Up @@ -759,7 +759,7 @@ function getRelatedSchemaLinks(schema = {}, json = {}, templates = {}, options =
return links
}

const generateImports = (json, templates) => {
const generateImports = (json, templates, options = { destination: '' }) => {
let imports = ''

if (rpcMethodsOrEmptyArray(json).length) {
Expand Down Expand Up @@ -789,14 +789,21 @@ const generateImports = (json, templates) => {
if (methodsWithXMethodsInResult(json).length) {
imports += getTemplate('/imports/x-method', templates)
}
const suffix = options.destination.split('.').pop()
const prefix = options.destination.split('/').pop().split('_')[0].toLowerCase()

let template = prefix ? getTemplate(`/imports/default.${prefix}`, templates) : ''
if (!template) {
template = getTemplate(suffix ? `/imports/default.${suffix}` : '/imports/default', templates)
}

if (json['x-schemas'] && Object.keys(json['x-schemas']).length > 0 && !json.info['x-uri-titles']) {
imports += Object.keys(json['x-schemas']).map(shared => getTemplate('/imports/default', templates).replace(/\$\{info.title\}/g, shared)).join('')
imports += Object.keys(json['x-schemas']).map(shared => template.replace(/\$\{info.title\}/g, shared)).join('')
}

let componentExternalSchema = getComponentExternalSchema(json)
if (componentExternalSchema.length && json.info['x-uri-titles']) {
imports += componentExternalSchema.map(shared => getTemplate('/imports/default', templates).replace(/\$\{info.title\}/g, shared)).join('')
imports += componentExternalSchema.map(shared => template.replace(/\$\{info.title\}/g, shared)).join('')
}
return imports
}
Expand Down

0 comments on commit 8e4ab25

Please sign in to comment.