Skip to content

Commit

Permalink
[TIMOB-25564] Use correct umbrella header import in native helpers (#265
Browse files Browse the repository at this point in the history
)

* [TIMOB-25564] Use correct umbrella header import in native helpers

* Pass hyperloop config object only
  • Loading branch information
janvennemann authored and hansemannn committed Nov 29, 2017
1 parent 5fd3706 commit 9c7471d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion hooks/hyperloop-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class HyperloopBuilderFactory {
}
}

return config;
return config.hyperloop || {};
}

/**
Expand Down
27 changes: 27 additions & 0 deletions packages/hyperloop-ios-metabase/lib/generate/code-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down Expand Up @@ -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;
9 changes: 1 addition & 8 deletions packages/hyperloop-ios-metabase/lib/generate/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions packages/hyperloop-ios-metabase/templates/module.m.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 9c7471d

Please sign in to comment.