From a8a8bdf431bfa164092f541fb309e422cda3be6f Mon Sep 17 00:00:00 2001 From: Leo Natan Date: Wed, 28 Feb 2018 15:46:51 +0200 Subject: [PATCH 1/2] Add RCTGetReactNativeVersion() to expose version in native code --- React/Base/RCTPlatform.m | 2 +- React/Base/RCTVersion.h | 17 +++++----- React/Base/RCTVersion.m | 33 +++++++++++++++++++ React/React.xcodeproj/project.pbxproj | 2 ++ scripts/bump-oss-version.js | 4 +-- .../versiontemplates/RCTVersion.h.template | 15 --------- .../versiontemplates/RCTVersion.m.template | 33 +++++++++++++++++++ 7 files changed, 80 insertions(+), 26 deletions(-) create mode 100644 React/Base/RCTVersion.m delete mode 100644 scripts/versiontemplates/RCTVersion.h.template create mode 100644 scripts/versiontemplates/RCTVersion.m.template diff --git a/React/Base/RCTPlatform.m b/React/Base/RCTPlatform.m index 8aed9fe386947f..4c1124b54cce58 100644 --- a/React/Base/RCTPlatform.m +++ b/React/Base/RCTPlatform.m @@ -45,7 +45,7 @@ + (BOOL)requiresMainQueueSetup @"systemName": [device systemName], @"interfaceIdiom": interfaceIdiom([device userInterfaceIdiom]), @"isTesting": @(RCTRunningInTestEnvironment()), - @"reactNativeVersion": RCT_REACT_NATIVE_VERSION, + @"reactNativeVersion": RCTGetReactNativeVersion(), }; } diff --git a/React/Base/RCTVersion.h b/React/Base/RCTVersion.h index f224a341af3eaa..ca46f31421eac3 100644 --- a/React/Base/RCTVersion.h +++ b/React/Base/RCTVersion.h @@ -1,15 +1,16 @@ /** - * @generated by scripts/bump-oss-version.js - * * Copyright (c) 2015-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -#define RCT_REACT_NATIVE_VERSION @{ \ - @"major": @(0), \ - @"minor": @(0), \ - @"patch": @(0), \ - @"prerelease": [NSNull null], \ -} + +#import + +extern NSString* const RCTVersionMajor; +extern NSString* const RCTVersionMinor; +extern NSString* const RCTVersionPatch; +extern NSString* const RCTVersionPrerelease; + +extern NSDictionary* RCTGetReactNativeVersion(void); diff --git a/React/Base/RCTVersion.m b/React/Base/RCTVersion.m new file mode 100644 index 00000000000000..41f178395c9018 --- /dev/null +++ b/React/Base/RCTVersion.m @@ -0,0 +1,33 @@ +/** + * @generated by scripts/bump-oss-version.js + * + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "RCTVersion.h" + +NSString* const RCTVersionMajor = @"major"; +NSString* const RCTVersionMinor = @"minor"; +NSString* const RCTVersionPatch = @"patch"; +NSString* const RCTVersionPrerelease = @"prerelease"; + +static NSDictionary* __rnVersion; + +__attribute__((constructor)) +static void __makeVersion() +{ + __rnVersion = @{ + RCTVersionMajor: @(0), + RCTVersionMinor: @(0), + RCTVersionPatch: @(0), + RCTVersionPrerelease: [NSNull null], + }; +} + +NSDictionary* RCTGetReactNativeVersion(void) +{ + return __rnVersion; +} diff --git a/React/React.xcodeproj/project.pbxproj b/React/React.xcodeproj/project.pbxproj index 0f79353b3f2dea..a36b7ce338648b 100644 --- a/React/React.xcodeproj/project.pbxproj +++ b/React/React.xcodeproj/project.pbxproj @@ -334,6 +334,7 @@ 352DCFF01D19F4C20056D623 /* RCTI18nUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 352DCFEF1D19F4C20056D623 /* RCTI18nUtil.m */; }; 369123E11DDC75850095B341 /* RCTJSCSamplingProfiler.m in Sources */ = {isa = PBXBuildFile; fileRef = 369123E01DDC75850095B341 /* RCTJSCSamplingProfiler.m */; }; 391E86A41C623EC800009732 /* RCTTouchEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 391E86A21C623EC800009732 /* RCTTouchEvent.m */; }; + 39C50FF92046EACF00CEE534 /* RCTVersion.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 199B8A6E1F44DB16005DEF67 /* RCTVersion.h */; }; 3D05745A1DE5FFF500184BB4 /* RCTJavaScriptLoader.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC70D2E81DE489E4002E6351 /* RCTJavaScriptLoader.mm */; }; 3D0B84221EC0B3F600B2BD8E /* RCTResizeMode.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 3D1FA0851DE4F3A000E03CC6 /* RCTResizeMode.h */; }; 3D0B84231EC0B40D00B2BD8E /* RCTImageLoader.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 3D1FA0831DE4F3A000E03CC6 /* RCTImageLoader.h */; }; @@ -1589,6 +1590,7 @@ dstPath = include/React; dstSubfolderSpec = 16; files = ( + 39C50FF92046EACF00CEE534 /* RCTVersion.h in Copy Headers */, 591F78DE202ADB8F004A668C /* RCTLayout.h in Copy Headers */, 59EDBCBD1FDF4E43003573DE /* RCTScrollableProtocol.h in Copy Headers */, 59EDBCBE1FDF4E43003573DE /* (null) in Copy Headers */, diff --git a/scripts/bump-oss-version.js b/scripts/bump-oss-version.js index 03f5ec19093df2..11ac0f940e0f95 100755 --- a/scripts/bump-oss-version.js +++ b/scripts/bump-oss-version.js @@ -67,8 +67,8 @@ fs.writeFileSync( ); fs.writeFileSync( - 'React/Base/RCTVersion.h', - cat('scripts/versiontemplates/RCTVersion.h.template') + 'React/Base/RCTVersion.m', + cat('scripts/versiontemplates/RCTVersion.m.template') .replace('${major}', `@(${major})`) .replace('${minor}', `@(${minor})`) .replace('${patch}', `@(${patch})`) diff --git a/scripts/versiontemplates/RCTVersion.h.template b/scripts/versiontemplates/RCTVersion.h.template deleted file mode 100644 index 1ab81aacc44aec..00000000000000 --- a/scripts/versiontemplates/RCTVersion.h.template +++ /dev/null @@ -1,15 +0,0 @@ -/** - * @generated by scripts/bump-oss-version.js - * - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#define RCT_REACT_NATIVE_VERSION @{ \ - @"major": ${major}, \ - @"minor": ${minor}, \ - @"patch": ${patch}, \ - @"prerelease": ${prerelease}, \ -} diff --git a/scripts/versiontemplates/RCTVersion.m.template b/scripts/versiontemplates/RCTVersion.m.template new file mode 100644 index 00000000000000..a550fb3216014d --- /dev/null +++ b/scripts/versiontemplates/RCTVersion.m.template @@ -0,0 +1,33 @@ +/** + * @generated by scripts/bump-oss-version.js + * + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "RCTVersion.h" + +NSString* const RCTVersionMajor = @"major"; +NSString* const RCTVersionMinor = @"minor"; +NSString* const RCTVersionPatch = @"patch"; +NSString* const RCTVersionPrerelease = @"prerelease"; + +static NSDictionary* __rnVersion; + +__attribute__((constructor)) +static void __makeVersion() +{ + __rnVersion = @{ + RCTVersionMajor: ${major}, + RCTVersionMinor: ${minor}, + RCTVersionPatch: ${patch}, + RCTVersionPrerelease: ${prerelease}, + }; +} + +NSDictionary* RCTGetReactNativeVersion(void) +{ + return __rnVersion; +} From bdcfcebbd1628f558d0490ba2426156f9b922a2a Mon Sep 17 00:00:00 2001 From: Leo Natan Date: Wed, 28 Feb 2018 16:04:12 +0200 Subject: [PATCH 2/2] RCTVersion.m was somehow removed from project. Add it back --- React/React.xcodeproj/project.pbxproj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/React/React.xcodeproj/project.pbxproj b/React/React.xcodeproj/project.pbxproj index a36b7ce338648b..1ec79122f44a68 100644 --- a/React/React.xcodeproj/project.pbxproj +++ b/React/React.xcodeproj/project.pbxproj @@ -335,6 +335,8 @@ 369123E11DDC75850095B341 /* RCTJSCSamplingProfiler.m in Sources */ = {isa = PBXBuildFile; fileRef = 369123E01DDC75850095B341 /* RCTJSCSamplingProfiler.m */; }; 391E86A41C623EC800009732 /* RCTTouchEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 391E86A21C623EC800009732 /* RCTTouchEvent.m */; }; 39C50FF92046EACF00CEE534 /* RCTVersion.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 199B8A6E1F44DB16005DEF67 /* RCTVersion.h */; }; + 39C50FFB2046EE3500CEE534 /* RCTVersion.m in Sources */ = {isa = PBXBuildFile; fileRef = 39C50FFA2046EE3500CEE534 /* RCTVersion.m */; }; + 39C50FFC2046EE3500CEE534 /* RCTVersion.m in Sources */ = {isa = PBXBuildFile; fileRef = 39C50FFA2046EE3500CEE534 /* RCTVersion.m */; }; 3D05745A1DE5FFF500184BB4 /* RCTJavaScriptLoader.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC70D2E81DE489E4002E6351 /* RCTJavaScriptLoader.mm */; }; 3D0B84221EC0B3F600B2BD8E /* RCTResizeMode.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 3D1FA0851DE4F3A000E03CC6 /* RCTResizeMode.h */; }; 3D0B84231EC0B40D00B2BD8E /* RCTImageLoader.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 3D1FA0831DE4F3A000E03CC6 /* RCTImageLoader.h */; }; @@ -2061,6 +2063,7 @@ 369123E01DDC75850095B341 /* RCTJSCSamplingProfiler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTJSCSamplingProfiler.m; sourceTree = ""; }; 391E86A21C623EC800009732 /* RCTTouchEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTouchEvent.m; sourceTree = ""; }; 391E86A31C623EC800009732 /* RCTTouchEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTTouchEvent.h; sourceTree = ""; }; + 39C50FFA2046EE3500CEE534 /* RCTVersion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTVersion.m; sourceTree = ""; }; 3D0B84281EC0B49400B2BD8E /* RCTTVRemoteHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTTVRemoteHandler.h; sourceTree = ""; }; 3D0B84291EC0B49400B2BD8E /* RCTTVRemoteHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTVRemoteHandler.m; sourceTree = ""; }; 3D0B842D1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTTVNavigationEventEmitter.h; sourceTree = ""; }; @@ -2999,6 +3002,7 @@ 83CBBA4F1A601E3B00E9B192 /* RCTUtils.h */, 83CBBA501A601E3B00E9B192 /* RCTUtils.m */, 199B8A6E1F44DB16005DEF67 /* RCTVersion.h */, + 39C50FFA2046EE3500CEE534 /* RCTVersion.m */, 599FAA291FB274970058CCF6 /* Surface */, ); path = Base; @@ -4155,6 +4159,7 @@ 5960C1BC1F0804A00066FD5B /* RCTLayoutAnimationGroup.m in Sources */, 2D3B5ECF1D9B096F00451313 /* RCTFont.mm in Sources */, 2D3B5ED51D9B098000451313 /* RCTModalHostViewController.m in Sources */, + 39C50FFC2046EE3500CEE534 /* RCTVersion.m in Sources */, 2D3B5EBC1D9B092600451313 /* RCTKeyboardObserver.m in Sources */, 657734931EE8356100A0E9EA /* RCTInspector.mm in Sources */, 59EB6DBE1EBD6FC90072A5E7 /* RCTUIManagerObserverCoordinator.mm in Sources */, @@ -4469,6 +4474,7 @@ 13D9FEEB1CDCCECF00158BD7 /* RCTEventEmitter.m in Sources */, 599FAA3E1FB274980058CCF6 /* RCTSurfaceRootShadowView.m in Sources */, AC70D2E91DE489E4002E6351 /* RCTJavaScriptLoader.mm in Sources */, + 39C50FFB2046EE3500CEE534 /* RCTVersion.m in Sources */, 14F7A0EC1BDA3B3C003C6C10 /* RCTPerfMonitor.m in Sources */, 5960C1B71F0804A00066FD5B /* RCTLayoutAnimation.m in Sources */, 13134C9E1E296B2A00B9F3CB /* RCTCxxModule.mm in Sources */,