Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-24198] Force include Foundation framework (2.0.X) #115

Merged
merged 2 commits into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions metabase/ios/lib/metabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ function generateMetabase (buildDir, sdk, sdkPath, iosMinVersion, includes, excl
var header = path.join(buildDir, 'metabase-' + iosMinVersion + '-' + sdk + '-' + cacheToken + '.h');
var outfile = path.join(buildDir, 'metabase-' + iosMinVersion + '-' + sdk + '-' + cacheToken + '.json');

// Foundation header always needs to be included
var absoluteFoundationHeaderRegex = /Foundation\.framework\/Headers\/Foundation\.h$/;
var systemFoundationHeaderRegex = /^[<"]Foundation\/Foundation\.h[<"]$/;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex matches for some incorrect require-statements. Replace at least the latter < with >.

var isFoundationIncluded = includes.some(function(header) {
return systemFoundationHeaderRegex.test(header) || absoluteFoundationHeaderRegex.test(header);
});
if (!isFoundationIncluded) {
includes.unshift(path.join(sdkPath, 'System/Library/Frameworks/Foundation.framework/Headers/Foundation.h'));
}

// check for cached version and attempt to return if found
if (!force && fs.existsSync(header) && fs.existsSync(outfile)) {
try {
Expand Down
50 changes: 46 additions & 4 deletions metabase/ios/test/generate_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var should = require('should'),
generator = require('../lib/generate/index'),
util = require('../lib/generate/util'),
nodePath = require('path'),
wrench = require('wrench'),
buildDir = nodePath.join(__dirname, '..', 'build', 'hyperloop');

function Hyperloop () {
Expand Down Expand Up @@ -71,13 +72,14 @@ describe('generate', function () {
beforeEach(function () {
global.Hyperloop = Hyperloop;
global.HyperloopObject = HyperloopObject;

if (fs.existsSync(buildDir)) {
wrench.rmdirSyncRecursive(buildDir);
}
wrench.mkdirSyncRecursive(buildDir);
});

before(function () {

!fs.existsSync(nodePath.dirname(buildDir)) && fs.mkdir(nodePath.dirname(buildDir));
!fs.existsSync(buildDir) && fs.mkdir(buildDir);

var proxyCount = 0;
var Module = require('module').Module;
var old_nodeModulePaths = Module._nodeModulePaths;
Expand Down Expand Up @@ -158,6 +160,14 @@ describe('generate', function () {

// setup the node path to resolve files that we generated
addPath(nodePath.dirname(buildDir));

var originalRequire = Module.prototype.require;
Module.prototype.require = function(path) {
if (/^\/hyperloop/.test(path)) {
path = path.slice(1);
}
return originalRequire.call(this, path);
};
});

it('should generate UIView', function (done) {
Expand Down Expand Up @@ -243,4 +253,36 @@ describe('generate', function () {
});
});
});

it('should always generate Foundation', function (done) {
var includes = [
'<Intents/INPreferences.h>'
];
generateMetabase(includes, function (err, json, outfile) {
should(err).not.be.ok;
should(json).be.ok;
var state = generator.generateState();
generator.generate('Foundation', buildDir, outfile, state, function (err) {
should(err).not.be.ok;
// Check some Foundation basics...
var Foundation = require(nodePath.join(buildDir, 'foundation/foundation.js'));
should(Foundation).be.a.function;
should(Foundation.NSUTF8StringEncoding).be.a.number;
var NSString = require(nodePath.join(buildDir, 'foundation/nsstring.js'));
should(NSString).be.a.function;
should(NSString.name).be.equal('NSString');
var instance = new NSString();
should(instance).be.an.object;
should(instance.className).be.equal('NSString');
should(instance.$native).be.an.object;

// ... and if INPreferences is genreated correctly, which does not work without
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in genreated

// explicitly including Foundation framework
var INPreferences = require(nodePath.join(buildDir, 'intents/inpreferences.js'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we only run the test with iOS 10+? Otherwise, we need to wrap this out for iOS 9.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are currently not run by the CI build at all and need to be triggered manually, so you have to make sure to run them with Xcode 8 / iOS 10 selected. Most of them are broken anyway and i'll rework them in a separate PR.

should(INPreferences).be.a.function;
should(INPreferences.siriAuthorizationStatus).be.a.function;
done();
});
});
});
});