Skip to content

(release 30) Linux generic installer fixes#414

Merged
vadi2 merged 9 commits intoMudlet:release_30from
vadi2:(release_30)-generic-installer-fixes
Mar 13, 2017
Merged

(release 30) Linux generic installer fixes#414
vadi2 merged 9 commits intoMudlet:release_30from
vadi2:(release_30)-generic-installer-fixes

Conversation

@vadi2
Copy link
Copy Markdown
Member

@vadi2 vadi2 commented Mar 9, 2017

Need to fix the Linux generic installer - as the current one does not work, at all, for anybody. Switching over to using AppImage instead of BitRock as I've validated AppImage with two random Ubuntu users and it at least seems to work better. Plus, it seems to be a better thing for the Linux ecosystem in general.

These fixes cherrypick 7922a3a from the development branch, improve that function to return multiple paths, and in general, make Mudlet also search things relative to its binary using an absolute path. This is because AppImage does not set the current working directory for us unlike what Mudlet has been used to.

Merging this will also require merging which is a fix to LuaGlobal to also load stuff relative to the executable using a relative path.

vadi2 and others added 4 commits March 9, 2017 00:55
Mostly getting Mudlet to look for files using an absolute path, because AppImage doesn't run set the current working directory for us.

Also updated LuaGlobal C++ searchpath to include absolute path. This is necessary for AppImage to work on Linux, which does not set the current working directory to be the mudlet executable.
Add compile-time fallback to LuaGlobal.lua loading logic to attempt to load
from LUA_DEFAULT_PATH, defined in src/src.pro using the value from
LUA_DEFAULT_DIR.

For platforms that don't currently define LUA_DEFAULT_DIR in src/src.pro (e.g.
win32, macx), the loading logic will behave as though LUA_DEFAULT_DIR were
defined as "/", the root directory. This is accomplished by compile time
concatenation of LUA_DEFAULT_PATH and the string literal "/". If necessary,
LUA_DEFAULT_DIR can later be defined for additional platforms (win32, macx,
etc) in src/src.pro to provide a different compile-time fallback for that
platform.

(cherry picked from commit ee48788)
…locations

Added capability to return a LuaGlobal search path relative to the Mudlet binary - needed for AppImage on Linux which does not set the current working directory to the binary for us.

Renamed getMudletLuaDefaultPath() to getMudletLuaDefaultPaths() as it hasn't been out in a release yet and we need to return a list of values.
This is the standard - search paths closest first and then those further away. Makes it easier to modify settings if need be.
lua_newtable( L );
lua_createtable(L,2,0);
// add filepath relative to the binary itself (one usecase is AppImage on Linux)
QString nativePath = QDir::toNativeSeparators( QCoreApplication::applicationDirPath() + "/mudlet-lua/lua/" );
Copy link
Copy Markdown
Member

@keneanung keneanung Mar 9, 2017

Choose a reason for hiding this comment

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

I have no idea about C++, but this is not the correct path to look at for macOS. The code a few lines below works for locating the LuaGlobal.lua, though:

 #if defined(Q_OS_MAC)
     QString path = QCoreApplication::applicationDirPath() + "/../Resources/mudlet-lua/lua/LuaGlobal.lua";
 #else

Could you add this in? If so, we might be able to get rid of the run_mudlet helper.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The macOS code is already in there for a long while, this is a Linux-specific fix.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The macOS code only worked, because of the run_mudlet workaround, which was necessary, because, without that, the working directory is /. I only understood why, because you practically put the solution under my nose. We should be able to get rid of the workaround for good if we add the conditional compile in.

Otherwise, I'll make the changes and send in an extra PR if that's your preferred way.

Copy link
Copy Markdown
Member Author

@vadi2 vadi2 Mar 9, 2017

Choose a reason for hiding this comment

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

Well "Allow edits from maintainers." is ticked, I think it'll easiest to communicate if you add the changes you'd like to see. Not getting you 100% here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, it returns a table! I was somehow reading it as returning a single string (mostly in connection with your changes to LuaGlobal.cs

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Mar 10, 2017 via email

local prefixes = {"../src/mudlet-lua/lua/", "../Resources/mudlet-lua/lua/",
"mudlet.app/Contents/Resources/mudlet-lua/lua/", "mudlet-lua/lua"}
"mudlet.app/Contents/Resources/mudlet-lua/lua/", "mudlet-lua/lua",
getMudletLuaDefaultPath()}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. Typo: You defined the function as getDefaultPaths (missing an "s" here)
  2. The function returns a table right now, should probably add an unpack here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@keneanung

  1. getMudletLuaDefaultPaths != getMudletLuaDefaultPath
    AND
    getMudletLuaDefaultPath != getDefaultPaths 😜 - but well spotted!

  2. Does not the following code (lines 133-150 old; lines 134-151 new) handle stepping through the table?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just to explain... The function returns a table, so the table is now {"path1", "path2", {"path from C", "another path from C"}}. The loop below iterates over the outer table only, you want both tables merged.

But the actual LuaGlobal is in#415

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Could you approve this PR? #415 is where the table iteration is fixed.

With this change, we should be able to get rid of the `run_mudlet` workaround for the macOS Mudlet.app package.
@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Mar 10, 2017

Egh github email reply sync is slow. Anyway there's no typo, I just forgot to link the or in description, see #415 that follows.

@keneanung
Copy link
Copy Markdown
Member

Maybe don't change LuaGlobal here, if it's not correct anyways?

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Mar 10, 2017 via email

To avoid confusion about search paths, the macOS Lua default path is only added when compiling for macOS.
@keneanung
Copy link
Copy Markdown
Member

But now you need to make sure the branches are merged in the correct order.

There, added the #ifs, though the code became a bit less readable this way...

}

// returns search paths for LuaGlobal itself to look at when loading other modules
// follows the principle of closest paths to the binary first, furthest away lasy
Copy link
Copy Markdown
Member

@SlySven SlySven Mar 10, 2017

Choose a reason for hiding this comment

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

lasy ==> later/lastly?

#if defined(Q_OS_MAC)
lua_createtable(L,3,0);
#else
lua_createtable(L,2,0);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not a Lua genius, so is a comment about why there is a difference here for Macs appropriate?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Explained by the add macOS lua path relative to the binary itself, which is part of the Mudlet.app package comment below.


#ifdef Q_OS_LINUX
// if using LuaJIT, adjust the cpath to look in /usr/lib as well - it doesn't by default
luaL_dostring (pGlobalLua, "if jit then package.cpath = package.cpath .. ';/usr/lib/lua/5.1/?.so;/usr/lib/x86_64-linux-gnu/lua/5.1/?.so' end");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we have dropped support for LuaJIT in the development branch - this line was removed some time back from that branch IIRC...!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We'll clean it up in the release_30 merge into development.

{
// For the installer we do not go down a level to search for this. So
// we check again for the user case of a windows install.
#if QT_VERSION >= 0x050200
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We no longer support Qt 4.x (except in a port I keep on my Repo... 😏)

#else
path = "mudlet-lua/lua/LuaGlobal.lua";
#endif
error = luaL_dofile( pGlobalLua, path.toLatin1().data() );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We might want to substitute path.toUtf8().constData() for path.toLatin1().data() - (use utf8() for those Windows machines who's user name and thus path contains non-ASCII characters; and constData() because we do not need to/want to/can change the supplied string which is the raw characters of path IIRC).

}

// Finally try loading from LUA_DEFAULT_PATH
path = LUA_DEFAULT_PATH "/LuaGlobal.lua";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ℹ️ This is string catenation isn't it?


// Finally try loading from LUA_DEFAULT_PATH
path = LUA_DEFAULT_PATH "/LuaGlobal.lua";
error = luaL_dofile( pGlobalLua, path.toLatin1().data() );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Another place for path.toUtf8().constData() to be considered...

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Mar 10, 2017 via email

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Mar 10, 2017 via email

Copy link
Copy Markdown
Member

@SlySven SlySven left a comment

Choose a reason for hiding this comment

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

Generally 👍 approval-able with that getMudletLuaDefaultPath__s__ typo fixed.

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Mar 12, 2017

Hm... tried out the mac fix and it didn't help, mostly because Mudlet can't find the Lua libraries it needs to begin with. I think run_mudlet.sh is still needed to get those to work - that or modifying the Mudlet binary to search for additional rpaths on macOS.

Nonetheless, getting rid of run_mudlet.sh on macs isn't in scope on this PR - @keneanung could you approve this one?

@keneanung
Copy link
Copy Markdown
Member

Let me have one last look at it, I was just booting my hackintosh

@keneanung
Copy link
Copy Markdown
Member

@vadi2 found the issue that prevented it from working. The macOS path was missing a / Between the application path and the manual addition...

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Mar 13, 2017

It didn't seem to make a difference for me - but I could also be testing it wrong. The right way to do it would be to remove the run_mudlet.sh script and get rid of the plist editing we do - I was just trying to run /MacOS/Mudlet directly.

@vadi2 vadi2 merged commit c116a90 into Mudlet:release_30 Mar 13, 2017
@vadi2 vadi2 deleted the (release_30)-generic-installer-fixes branch March 13, 2017 01:04
vadi2 added a commit to vadi2/Mudlet that referenced this pull request Mar 13, 2017
7922a3a added getMudletLuaDefaultPath() that returned a single path, whereas the PR Mudlet#414 changed function to be getMudletLuaDefaultPaths() and made it return an indexed table. This fixes the wrong call that got left behind between cherrypicking and merging.
@keneanung
Copy link
Copy Markdown
Member

t didn't seem to make a difference for me - but I could also be testing it wrong.

The problem is, that the way we load LuaGlobal.lua doesn't differentiate between File not Found and a compile error during dofile. And since the LuaGlobal in this PR was not working, it tried the other paths as well. We should correct that behaviour after 3.0 is released.

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Mar 13, 2017

Aha, true. Will see how it is after #421 is in.

vadi2 added a commit that referenced this pull request Mar 15, 2017
7922a3a added getMudletLuaDefaultPath() that returned a single path, whereas the PR #414 changed function to be getMudletLuaDefaultPaths() and made it return an indexed table. This fixes the wrong call that got left behind between cherrypicking and merging.
vadi2 added a commit to vadi2/Mudlet that referenced this pull request Mar 16, 2017
7922a3a added getMudletLuaDefaultPath() that returned a single path, whereas the PR Mudlet#414 changed function to be getMudletLuaDefaultPaths() and made it return an indexed table. This fixes the wrong call that got left behind between cherrypicking and merging.
keneanung referenced this pull request in keneanung/Mudlet-1 Mar 21, 2017
* Changes to make AppImage install working on Linux

Mostly getting Mudlet to look for files using an absolute path, because AppImage doesn't run set the current working directory for us.

Also updated LuaGlobal C++ searchpath to include absolute path. This is necessary for AppImage to work on Linux, which does not set the current working directory to be the mudlet executable.

* Bugfix/Enhance: Load LuaGlobal.lua from LUA_DEFAULT_PATH

Add compile-time fallback to LuaGlobal.lua loading logic to attempt to load
from LUA_DEFAULT_PATH, defined in src/src.pro using the value from
LUA_DEFAULT_DIR.

For platforms that don't currently define LUA_DEFAULT_DIR in src/src.pro (e.g.
win32, macx), the loading logic will behave as though LUA_DEFAULT_DIR were
defined as "/", the root directory. This is accomplished by compile time
concatenation of LUA_DEFAULT_PATH and the string literal "/". If necessary,
LUA_DEFAULT_DIR can later be defined for additional platforms (win32, macx,
etc) in src/src.pro to provide a different compile-time fallback for that
platform.

(cherry picked from commit ee48788)

* Updated getMudletLuaDefaultPath+s to return a table of viable search locations

Added capability to return a LuaGlobal search path relative to the Mudlet binary - needed for AppImage on Linux which does not set the current working directory to the binary for us.

Renamed getMudletLuaDefaultPath() to getMudletLuaDefaultPaths() as it hasn't been out in a release yet and we need to return a list of values.

* Changed load order to be 'closest to binary first'

This is the standard - search paths closest first and then those further away. Makes it easier to modify settings if need be.

* Add macOS lua path to getMudletLuaDefaultPaths

With this change, we should be able to get rid of the `run_mudlet` workaround for the macOS Mudlet.app package.

* Add Mac lua default path only when compiling there

To avoid confusion about search paths, the macOS Lua default path is only added when compiling for macOS.
keneanung referenced this pull request in keneanung/Mudlet-1 Mar 21, 2017
7922a3a added getMudletLuaDefaultPath() that returned a single path, whereas the PR #414 changed function to be getMudletLuaDefaultPaths() and made it return an indexed table. This fixes the wrong call that got left behind between cherrypicking and merging.
mehulmathur16 pushed a commit to mehulmathur16/Mudlet that referenced this pull request Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants