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

Simulator/Android: embedding runtime so no Java installation is required anymore #200

Merged
merged 5 commits into from
Dec 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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 .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ jobs:
uses: actions/download-artifact@v1
with:
name: Native
- name: Put JRE in place
shell: bash
run: |
curl -sL https://github.com/coronalabs/binary-data/releases/download/1.0/jre.macos.tgz -o jre.macos.tgz
tar xzf jre.macos.tgz
- name: install appdmg
run: npm install -g appdmg
- name: install imagemagick
Expand Down Expand Up @@ -416,6 +421,11 @@ jobs:
mv CoronaEnterprise Native
del /q /f /a Native\.*
del /q /f /a Native\Icon?
- name: Put JRE in place
shell: bash
run: |
curl -sL https://github.com/coronalabs/binary-data/releases/download/1.0/jre.win32.7z -o jre.win32.7z
7z x jre.win32.7z -o"%WORKSPACE%\platform\windows\Bin"
- name: Build Corona Simulator
shell: cmd
run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ plugins/**/android/gen/*
plugins/**/android/libs/*
plugins/analytics/win32/*analytics.c

platform/switch/

# Windows
# autogenerated from Lua
platform/win32/simulator/Setup/Intermediate/*
Expand Down Expand Up @@ -285,3 +287,4 @@ external/JNLua/.classpath
external/JNLua/.project
/output/

/jre/
79 changes: 79 additions & 0 deletions librtt/Rtt_JavaHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
#include "shellapi.h" // ShellExecute()
#include "WinString.h"
#include "Resource.h" // error string ids
#ifdef Rtt_NO_GUI
#include "Rtt_WinConsolePlatform.h"
#else
#include "Interop/ApplicationServices.h"
#endif

#elif Rtt_MAC_ENV
#include <dlfcn.h>
#endif // Rtt_WIN_ENV
Expand Down Expand Up @@ -379,6 +385,27 @@ static bool CopyJavaDevelopmentKitRegistryKeyPathTo(WinString* pPath)
return false;
}

LPCTSTR GetApplicationPath()
{
#ifdef Rtt_NO_GUI
static std::wstring ret = WinConsolePlatform::GetDirectoryPath();
return ret.c_str();
#else
return Interop::ApplicationServices::GetDirectoryPath();
#endif
}

bool CheckDirExists(LPCTSTR dirName)
{
WIN32_FIND_DATA data;
HANDLE handle = FindFirstFile(dirName, &data);
if (handle != INVALID_HANDLE_VALUE)
{
FindClose(handle);
return (0 != (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
}
return false;
}

// Fetches the Java Development Kit's JavaHome in registry.
const char *JavaHost::GetJdkPath()
Expand All @@ -387,6 +414,32 @@ const char *JavaHost::GetJdkPath()

if( s_sJdkJavaHome[0] == '\0' )
{
// try to find bunled JRE
TCHAR buffer[MAX_PATH] = _T("");
WinString rootPath;
GetFullPathName(_T("jre"), MAX_PATH, buffer, NULL);
if (buffer[0] && CheckDirExists(buffer)) {
rootPath.SetTCHAR(buffer);
strcpy_s(s_sJdkJavaHome, MAX_PATH, rootPath.GetUTF8());
return s_sJdkJavaHome;
}

rootPath.SetUTF16(GetApplicationPath());
rootPath.Append("\\jre");
if (CheckDirExists(rootPath.GetUTF16())) {
strcpy_s(s_sJdkJavaHome, MAX_PATH, rootPath.GetUTF8());
return s_sJdkJavaHome;
}

rootPath.SetUTF16(GetApplicationPath());
rootPath.Append("\\..\\..\\..\\..\\jre");
GetFullPathName(rootPath.GetTCHAR(), MAX_PATH, buffer, NULL);
if (CheckDirExists(rootPath.GetUTF16())) {
rootPath.SetTCHAR(buffer);
strcpy_s(s_sJdkJavaHome, MAX_PATH, rootPath.GetUTF8());
return s_sJdkJavaHome;
}

WinString sRegistryKeyPath;
WinString sValue;
if (CopyJavaDevelopmentKitRegistryKeyPathTo(&sRegistryKeyPath))
Expand All @@ -407,6 +460,32 @@ const char *JavaHost::GetJrePath()

if( s_sJreJavaHome[0] == '\0' )
{
// try to find bunled JRE
TCHAR buffer[MAX_PATH] = _T("");
WinString rootPath;
GetFullPathName(_T("jre\\jre"), MAX_PATH, buffer, NULL);
if (buffer[0] && CheckDirExists(buffer)) {
rootPath.SetTCHAR(buffer);
strcpy_s(s_sJreJavaHome, MAX_PATH, rootPath.GetUTF8());
return s_sJreJavaHome;
}

rootPath.SetUTF16(GetApplicationPath());
rootPath.Append("\\jre\\jre");
if (CheckDirExists(rootPath.GetUTF16())) {
strcpy_s(s_sJreJavaHome, MAX_PATH, rootPath.GetUTF8());
return s_sJreJavaHome;
}

rootPath.SetUTF16(GetApplicationPath());
rootPath.Append("\\..\\..\\..\\..\\jre\\jre");
GetFullPathName(rootPath.GetTCHAR(), MAX_PATH, buffer, NULL);
if (CheckDirExists(rootPath.GetUTF16())) {
rootPath.SetTCHAR(buffer);
strcpy_s(s_sJreJavaHome, MAX_PATH, rootPath.GetUTF8());
return s_sJreJavaHome;
}

WinString sRegistryKeyPath;
WinString sValue;
if (CopyJavaRuntimeRegistryKeyPathTo(&sRegistryKeyPath))
Expand Down
8 changes: 8 additions & 0 deletions platform/mac/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Core/Rtt_Build.h"

#import "AppDelegate.h"
#include <stdlib.h>

#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5)
#import <Foundation/NSAutoreleasePool.h>
Expand Down Expand Up @@ -1383,6 +1384,13 @@ -(void)applicationWillFinishLaunching:(NSNotification*)aNotification

[self checkOpenGLRequirements];
[self coronaInit:aNotification];

#ifdef Rtt_AUTHORING_SIMULATOR
NSString *jhome = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Contents/jre/jdk/Contents/Home"];
if([[NSFileManager defaultManager] fileExistsAtPath:jhome]) {
setenv("JAVA_HOME", [jhome UTF8String], YES);
}
#endif
}

- (void) startDebugAndOpenPanel
Expand Down
22 changes: 22 additions & 0 deletions platform/mac/ratatouille.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -6081,6 +6081,7 @@
C2FD8EDF19C904DA00CBE369 /* Run Script (copy Skins files) */,
C2B5FEF11B336C9000DD49E6 /* Run Script (build OSXAppTemplate.zip) */,
C2E454671F844BFC00717681 /* Run Script (copy device-support files) */,
F5608E22257AB801000612C1 /* Run Script (copy JRE if exists) */,
);
buildRules = (
001F574112B6018500F52101 /* PBXBuildRule */,
Expand Down Expand Up @@ -6700,6 +6701,27 @@
shellScript = "set -x\nmkdir -p \"$BUILT_PRODUCTS_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/Skins\"\n# Copy all Skins .lua files and the associated .png files, excluding dot files and\n# deleting any that no longer exist in the source directory\nrsync -av --delete --include='*.lua' --include='*.png' --include='*.template' --exclude='.*' --exclude='*' \"$SRCROOT/../resources/Skins/\" \"$BUILT_PRODUCTS_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/Skins/\"\n";
showEnvVarsInLog = 0;
};
F5608E22257AB801000612C1 /* Run Script (copy JRE if exists) */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"$(SRCROOT)/../../jre",
);
name = "Run Script (copy JRE if exists)";
outputFileListPaths = (
);
outputPaths = (
"$(BUILT_PRODUCTS_DIR)/$(UNLOCALIZED_RESOURCES_FOLDER_PATH_SHALLOW_BUNDLE_YES)/jre",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "set -x\n\nif [ -d \"$SRCROOT/../../jre\" ]\nthen\n\tcp -r \"$SRCROOT/../../jre\" \"$BUILT_PRODUCTS_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH_SHALLOW_BUNDLE_YES\"\nfi\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down
10 changes: 10 additions & 0 deletions tools/CoronaBuilder/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ int main( int argc, const char *argv[] )
int result = 0;
@autoreleasepool
{
NSString *jhome = [[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"../../../../../Corona Simulator.app/Contents/jre/jdk/Contents/Home"] stringByStandardizingPath];
if([[NSFileManager defaultManager] fileExistsAtPath:jhome]) {
setenv("JAVA_HOME", [jhome UTF8String], YES);
} else {
jhome = [[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"../Corona Simulator.app/Contents/jre/jdk/Contents/Home"] stringByStandardizingPath];
if([[NSFileManager defaultManager] fileExistsAtPath:jhome]) {
setenv("JAVA_HOME", [jhome UTF8String], YES);
}
}

MacConsolePlatform platform;
MacPlatformServices services( platform );

Expand Down