From 9c7471d34a136a120c0a0bd7daac154977d39c64 Mon Sep 17 00:00:00 2001 From: Jan Vennemann Date: Wed, 29 Nov 2017 11:02:05 +0100 Subject: [PATCH] [TIMOB-25564] Use correct umbrella header import in native helpers (#265) * [TIMOB-25564] Use correct umbrella header import in native helpers * Pass hyperloop config object only --- hooks/hyperloop-init.js | 2 +- .../lib/generate/code-generator.js | 27 +++++++++++++++++++ .../lib/generate/module.js | 9 +------ .../templates/module.m.ejs | 5 +--- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/hooks/hyperloop-init.js b/hooks/hyperloop-init.js index d17fa437..c1dfa858 100644 --- a/hooks/hyperloop-init.js +++ b/hooks/hyperloop-init.js @@ -86,7 +86,7 @@ class HyperloopBuilderFactory { } } - return config; + return config.hyperloop || {}; } /** diff --git a/packages/hyperloop-ios-metabase/lib/generate/code-generator.js b/packages/hyperloop-ios-metabase/lib/generate/code-generator.js index 78a50a57..a20968c6 100644 --- a/packages/hyperloop-ios-metabase/lib/generate/code-generator.js +++ b/packages/hyperloop-ios-metabase/lib/generate/code-generator.js @@ -185,6 +185,7 @@ class CodeGenerator { var moduleSourceInfo = this.sourceSet.modules[moduleName]; if (this.doesModuleNeedsNativeWrapper(moduleSourceInfo)) { + this.convertToUmbrellaHeaderImports(moduleSourceInfo.frameworks); var nativeCode = util.generateTemplate('module.m', { data: moduleSourceInfo }); @@ -276,6 +277,32 @@ class CodeGenerator { } }); } + + /** + * Takes a map of used framework names and converts it to their correct umbrella + * header imports. + * + * Prior to this we would simply assume umbrella headers as Framework/Framework.h, + * which is a best practive though, but not every framework sticks to this. + * + * Utilizes the frameworks metadata to read the umbrella header from a framework's + * module map or falls back to the old naming scheme. + * + * @param {Object} frameworks Object map of used frameworks as keys + */ + convertToUmbrellaHeaderImports(frameworks) { + Object.keys(frameworks).forEach(frameworkName => { + if (this.iosBuilder.frameworks.has(frameworkName)) { + const meta = this.iosBuilder.frameworks.get(frameworkName); + let frameworkUmbrellaHeaderImport = `${meta.name}/${meta.name}.h`; + if (meta.umbrellaHeader) { + frameworkUmbrellaHeaderImport = `${meta.name}/${path.basename(meta.umbrellaHeader)}`; + } + delete frameworks[frameworkName]; + frameworks[frameworkUmbrellaHeaderImport] = 1; + } + }); + } } module.exports = CodeGenerator; diff --git a/packages/hyperloop-ios-metabase/lib/generate/module.js b/packages/hyperloop-ios-metabase/lib/generate/module.js index a7a04af7..9b24becf 100644 --- a/packages/hyperloop-ios-metabase/lib/generate/module.js +++ b/packages/hyperloop-ios-metabase/lib/generate/module.js @@ -77,14 +77,7 @@ function generate (json, mod, state) { m.class.obj_class_method.length || Object.keys(m.class.static_variables).length || m.class.blocks.length) { - if (mod.filename.match(/-Swift\.h$/)) { - m.import = mod.framework + '/' + path.basename(mod.filename); - if (m.frameworks[mod.framework]) { - delete m.frameworks[mod.framework]; - } - } else { - m.frameworks[mod.framework] = 1; - } + m.frameworks[mod.framework] = 1; } return m; diff --git a/packages/hyperloop-ios-metabase/templates/module.m.ejs b/packages/hyperloop-ios-metabase/templates/module.m.ejs index 514e7b6f..35fda6a9 100644 --- a/packages/hyperloop-ios-metabase/templates/module.m.ejs +++ b/packages/hyperloop-ios-metabase/templates/module.m.ejs @@ -5,11 +5,8 @@ * All Rights Reserved. This code contains patents and/or patents pending. */ <% Object.keys(data.frameworks).forEach(function (f) { -%> -#import <<%=f%>/<%=f%>.h> +#import <<%=f%>> <% }) -%> -<% if (data.import) { -%> -#import <<%-data.import%>> -<% } -%> #import "TiBase.h" #import "KrollCallback.h"