mbox series

[OpenWrt-Devel,0/1] libubox installs incorrectly on Ubuntu due to incorrect LUAPATH

Message ID 20181129152008.30897-1-stokito@gmail.com
Headers show
Series libubox installs incorrectly on Ubuntu due to incorrect LUAPATH | expand

Message

Sergey Ponomarev Nov. 29, 2018, 3:20 p.m. UTC
I'm working on porting openwrt utils like UCI and UHTTPD to Ubuntu and trying to create a PPA.
During creation of a debian package for libubox it's build failed with:
    dh_install: Cannot find (any matches for) "/usr/lib/x86_64-linux-gnu/lua/5.1/uloop.so" (tried in ., debian/tmp)
After investigation it turned out that LUAPATH variable was evaluated as /usr/local/lib/lua/5.1 while correct path is /usr/lib/x86_64-linux-gnu/lua/5.1.
The LUAPATH is evaluated by the command:
    $ lua -e "for k in string.gmatch(package.cpath .. \";\", \"([^;]+)/..so;\") do if k:sub(1,1) == \"/\" then print(k) break end end"
So it looks for array package.cpath and gets a first line which starts with / (this is why k:sub(1,1) == \"/\").
To see all pathes let's change the command a little bit:
    $ lua -e "for k in string.gmatch(package.cpath .. \";\", \"([^;]+)/..so;\") do print(k) end"
    .
    /usr/local/lib/lua/5.1
    /usr/lib/x86_64-linux-gnu/lua/5.1
    /usr/lib/lua/5.1
So on Ubuntu 18.10 and maybe in other distros the LUAPATH variable will receive the /usr/local/lib/lua/5.1 as first path.
To fix that all what we need to do is just to get path which starts with not just / but with /usr/lib/ i.e.
    $ lua -e "for k in string.gmatch(package.cpath .. \";\", \"([^;]+)/..so;\") do if k:sub(1,9) == \"/usr/lib/\" then print(k) break end end"
So this parch is intended to fix that.
Also the similar pathes needed for UCI and UBUS but I'll send them separately if you accept this patch. Also you can that yourself.

Sergey Ponomarev (1):
  libubox/lua/CMakeLists.txt: fix LUAPATH so it will use /usr/lib/
    instead of /usr/local/lib/

 lua/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Petr Štetiar Nov. 29, 2018, 4:17 p.m. UTC | #1
Sergey Ponomarev <stokito@gmail.com> [2018-11-29 17:20:07]:

Hi,

> I'm working on porting openwrt utils like UCI and UHTTPD to Ubuntu and trying to create a PPA.
> During creation of a debian package for libubox it's build failed with:
>     dh_install: Cannot find (any matches for) "/usr/lib/x86_64-linux-gnu/lua/5.1/uloop.so" (tried in ., debian/tmp)
> After investigation it turned out that LUAPATH variable was evaluated as /usr/local/lib/lua/5.1 while correct path is /usr/lib/x86_64-linux-gnu/lua/5.1.

That's wrong, see bellow.

> The LUAPATH is evaluated by the command:
>     $ lua -e "for k in string.gmatch(package.cpath .. \";\", \"([^;]+)/..so;\") do if k:sub(1,1) == \"/\" then print(k) break end end"
> So it looks for array package.cpath and gets a first line which starts with / (this is why k:sub(1,1) == \"/\").
> To see all pathes let's change the command a little bit:
>     $ lua -e "for k in string.gmatch(package.cpath .. \";\", \"([^;]+)/..so;\") do print(k) end"
>     .
>     /usr/local/lib/lua/5.1
>     /usr/lib/x86_64-linux-gnu/lua/5.1
>     /usr/lib/lua/5.1

All 4 paths are valid, Lua would search for dynamic loadable libraries in those
paths.

> So on Ubuntu 18.10 and maybe in other distros the LUAPATH variable will receive the /usr/local/lib/lua/5.1 as first path.
> To fix that all what we need to do is just to get path which starts with not just / but with /usr/lib/ i.e.
>     $ lua -e "for k in string.gmatch(package.cpath .. \";\", \"([^;]+)/..so;\") do if k:sub(1,9) == \"/usr/lib/\" then print(k) break end end"
> So this parch is intended to fix that.

No, this is not a fix, it's a hack for Ubuntu. You're probably breaking half of
the world where you've stuff usually installed in /usr/local and other
locations, like BSDs (and maybe OSX?) for example:

 ynezz@meh:~$ head -1 /etc/motd
 OpenBSD 6.4 (GENERIC) #349: Thu Oct 11 13:25:13 MDT 2018

 ynezz@meh:~$ lua51 -e "for k in string.gmatch(package.cpath .. \";\", \"([^;]+)/..so;\") do if k:sub(1,1) == \"/\" then print(k) break end end"
 /usr/local/lib/lua/5.1

 ynezz@meh:~$ lua51 -e "for k in string.gmatch(package.cpath .. \";\", \"([^;]+)/..so;\") do if k:sub(1,9) == \"/usr/lib/\" then print(k) break end end"

-- ynezz
Sergey Ponomarev Nov. 29, 2018, 5:48 p.m. UTC | #2
Hi and thank for the review,

We have two situations: installing from source (and in this situation
it's ok to use /usr/local/) and installation as part generating a *.deb
package and here we can't use /usr/local.

I checked my system and lua is installed properly but lua's
package.cpath anyway returns /usr/local as first path. What I get from
documentation this is properly behavior.

So I just decided to set LUAPATH manually and I think that would be ok.

Thank you


On 11/29/18 6:17 PM, Petr Štetiar wrote:
> Sergey Ponomarev <stokito@gmail.com> [2018-11-29 17:20:07]:
>
> Hi,
>
>> I'm working on porting openwrt utils like UCI and UHTTPD to Ubuntu and trying to create a PPA.
>> During creation of a debian package for libubox it's build failed with:
>>     dh_install: Cannot find (any matches for) "/usr/lib/x86_64-linux-gnu/lua/5.1/uloop.so" (tried in ., debian/tmp)
>> After investigation it turned out that LUAPATH variable was evaluated as /usr/local/lib/lua/5.1 while correct path is /usr/lib/x86_64-linux-gnu/lua/5.1.
> That's wrong, see bellow.
>
>> The LUAPATH is evaluated by the command:
>>     $ lua -e "for k in string.gmatch(package.cpath .. \";\", \"([^;]+)/..so;\") do if k:sub(1,1) == \"/\" then print(k) break end end"
>> So it looks for array package.cpath and gets a first line which starts with / (this is why k:sub(1,1) == \"/\").
>> To see all pathes let's change the command a little bit:
>>     $ lua -e "for k in string.gmatch(package.cpath .. \";\", \"([^;]+)/..so;\") do print(k) end"
>>     .
>>     /usr/local/lib/lua/5.1
>>     /usr/lib/x86_64-linux-gnu/lua/5.1
>>     /usr/lib/lua/5.1
> All 4 paths are valid, Lua would search for dynamic loadable libraries in those
> paths.
>
>> So on Ubuntu 18.10 and maybe in other distros the LUAPATH variable will receive the /usr/local/lib/lua/5.1 as first path.
>> To fix that all what we need to do is just to get path which starts with not just / but with /usr/lib/ i.e.
>>     $ lua -e "for k in string.gmatch(package.cpath .. \";\", \"([^;]+)/..so;\") do if k:sub(1,9) == \"/usr/lib/\" then print(k) break end end"
>> So this parch is intended to fix that.
> No, this is not a fix, it's a hack for Ubuntu. You're probably breaking half of
> the world where you've stuff usually installed in /usr/local and other
> locations, like BSDs (and maybe OSX?) for example:
>
>  ynezz@meh:~$ head -1 /etc/motd
>  OpenBSD 6.4 (GENERIC) #349: Thu Oct 11 13:25:13 MDT 2018
>
>  ynezz@meh:~$ lua51 -e "for k in string.gmatch(package.cpath .. \";\", \"([^;]+)/..so;\") do if k:sub(1,1) == \"/\" then print(k) break end end"
>  /usr/local/lib/lua/5.1
>
>  ynezz@meh:~$ lua51 -e "for k in string.gmatch(package.cpath .. \";\", \"([^;]+)/..so;\") do if k:sub(1,9) == \"/usr/lib/\" then print(k) break end end"
>
> -- ynezz