Skip to content
This repository was archived by the owner on Mar 12, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Library/Homebrew/brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ onoe() {
fi
if [[ $# -eq 0 ]]
then
/bin/cat >&2
cat >&2
Copy link
Member

Choose a reason for hiding this comment

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

You can submit this change to Homebrew/brew.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

else
echo "$*" >&2
fi
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def check_cellar
def symlink_ld_so
ld_so = HOMEBREW_PREFIX/"lib/ld.so"
return if ld_so.readable?
sys_interpreter = ["/lib64/ld-linux-x86-64.so.2", "/lib/ld-linux.so.3", "/lib/ld-linux.so.2", "/lib/ld-linux-armhf.so.3"].find do |s|
sys_interpreter = ["/lib64/ld-linux-x86-64.so.2", "/lib/ld-linux.so.3", "/lib/ld-linux.so.2", "/lib/ld-linux-armhf.so.3", "/system/bin/linker"].find do |s|
Pathname.new(s).executable?
Copy link
Member

Choose a reason for hiding this comment

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

You can submit this change to Linuxbrew/brew.

Copy link
Member

Choose a reason for hiding this comment

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

Please submit this change to Linuxbrew/brew in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

end
raise "Unable to locate the system's ld.so" unless sys_interpreter
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
(OS.mac? ? "~/Library/Logs/Homebrew/" : "~/.cache/Homebrew/Logs")).expand_path

# Must use /tmp instead of $TMPDIR because long paths break Unix domain sockets
HOMEBREW_TEMP = Pathname.new(ENV.fetch("HOMEBREW_TEMP", "/tmp"))
# IF ANDROID
HOMEBREW_TEMP = Pathname.new(ENV.fetch("HOMEBREW_TEMP", "/data/data/com.termux/files/usr/tmp"))

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to just use $TMPDIR, but the line above dissuaded me.
The strategy I've used in past for such a problem is to create a short symlink (e.g. /tmp/t) that points to the arbitrary-length TMPDIR, then use the shorter path as TMPDIR. Of course, if /tmp isn't writable, it seems best to use TMPDIR as is.

Do you think the above suggestion could fit upstream?

Copy link
Member

Choose a reason for hiding this comment

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

My guess is that they'd prefer to keep the existing behaviour, using HOMEBREW_TEMP and ignoring TMPDIR. An Android specific installer for Linuxbrew could set the environment variables needed for Android.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unless defined? HOMEBREW_LIBRARY_PATH
# Root of the Homebrew code base
Expand Down
6 changes: 6 additions & 0 deletions Library/Homebrew/development_tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ def locate(tool)
path
elsif File.executable?(path = "/usr/bin/#{tool}")
Pathname.new path
# IF ANDROID
elsif File.executable?(path = "/data/data/com.termux/files/usr/bin/#{tool}")
Pathname.new path
Copy link
Member

Choose a reason for hiding this comment

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

Add to https://github.com/Linuxbrew/brew/wiki/Android

ln -s /data/data/com.termux/files/usr/bin/* ~/.linuxbrew/bin/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

# Homebrew GCCs most frequently; much faster to check this before xcrun
elsif (path = HOMEBREW_PREFIX/"bin/#{tool}").executable?
path
Expand Down Expand Up @@ -79,6 +82,9 @@ def clang_build_version
if (path = locate("clang")) &&
build_version = `#{path} --version`[/clang-(\d{2,})/, 1]
Version.new build_version
elsif (path = locate("clang")) &&
build_version = `#{path} --version`[/clang version (\d\.\d\.\d)/, 1]
Version.new build_version
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest removing this chunk and changing line 83 to (untested)

build_version = Utils.popen_read(path, "--version")[/clang(-| version )(\d{2,})/, 2]

If clang --version also displays clang version x.x.x on Ubuntu, this change can go upstream to Homebrew/brew.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems to!

$ clang --version
clang version 4.0.1-6 (tags/RELEASE_401/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ which clang
/usr/bin/clang

$ dpkg -S /usr/bin/clang
clang: /usr/bin/clang

$ dpkg -l clang
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                 Version         Architecture    Description
+++-====================-===============-===============-=============================================
ii  clang                1:4.0-37~exp3ub amd64           C, C++ and Objective-C compiler (LLVM based)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

else
Version::NULL
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/extend/ENV/shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module SharedEnvExtension
MACOSX_DEPLOYMENT_TARGET SDKROOT DEVELOPER_DIR
CMAKE_PREFIX_PATH CMAKE_INCLUDE_PATH CMAKE_FRAMEWORK_PATH
GOBIN GOPATH GOROOT PERL_MB_OPT PERL_MM_OPT
LIBRARY_PATH LD_LIBRARY_PATH LD_PRELOAD LD_RUN_PATH
LIBRARY_PATH LD_PRELOAD LD_RUN_PATH
Copy link
Member

Choose a reason for hiding this comment

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

Termux can use RUNPATH rather than LD_LIBRARY_PATH.

].freeze

def inherit?
Expand Down
9 changes: 7 additions & 2 deletions Library/Homebrew/extend/os/linux/extend/ENV/super.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def xorg_recursive_deps

def homebrew_extra_paths
paths = []
# IF ANDROID
paths += ["/data/data/com.termux/files/usr/bin", "/data/data/com.termux/files/usr/bin/applets"]
Copy link
Member

Choose a reason for hiding this comment

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

Add to https://github.com/Linuxbrew/brew/wiki/Android

ln -s /data/data/com.termux/files/usr/bin/applets/* ~/.linuxbrew/bin/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


paths += %w[binutils make].map do |f|
begin
Expand All @@ -39,15 +41,16 @@ def homebrew_extra_paths
end

def determine_extra_rpath_paths
paths = ["#{HOMEBREW_PREFIX}/lib"]
paths = ["/data/data/com.termux/files/usr/lib"]
Copy link
Member

Choose a reason for hiding this comment

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

Add to https://github.com/Linuxbrew/brew/wiki/Android

ln -s /data/data/com.termux/files/usr/lib/* ~/.linuxbrew/lib/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

paths += ["#{HOMEBREW_PREFIX}/lib"]
paths += run_time_deps.map { |d| d.opt_lib.to_s }
paths += homebrew_extra_library_paths
paths
end

def determine_dynamic_linker_path(formula)
return "" if formula&.name == "glibc"
"#{HOMEBREW_PREFIX}/lib/ld.so"
"/system/bin/linker"
Copy link
Member

Choose a reason for hiding this comment

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

There should be no need for this chunk. …/lib/ld.so is a symlink to /system/bin/linker.

end

# @private
Expand Down Expand Up @@ -93,12 +96,14 @@ def homebrew_extra_isystem_paths

def homebrew_extra_library_paths
paths = []
paths += ["/data/data/com.termux/files/usr/lib"]
Copy link
Member

Choose a reason for hiding this comment

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

Symlink these libraries.

paths += xorg_lib_paths if x11?
paths
end

def homebrew_extra_cmake_include_paths
paths = []
paths += ["/data/data/com.termux/files/usr/include"]
Copy link
Member

Choose a reason for hiding this comment

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

Add to https://github.com/Linuxbrew/brew/wiki/Android

ln -s /data/data/com.termux/files/usr/include ~/.linuxbrew/include/

paths += xorg_include_paths if x11?
paths
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/os/linux/glibc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Glibc

def system_version
return @system_version if @system_version
version = Utils.popen_read("/usr/bin/ldd", "--version")[/ (\d+\.\d+)/, 1]
version = Utils.popen_read("/usr/bin/objdump", "--version")[/ (\d+\.\d+)/, 1]
Copy link
Member

Choose a reason for hiding this comment

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

You should be able to revert this chunk. Linuxbrew should operate correctly if it's not able to determine the version of glibc. It's a bug if not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It crashes on this line. I forget why. Will file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, machomebrew crashes, but linuxbrew seems fine. I don't think it's possible that I was on the wrong fork, but I can't tell if this is an actionable bug:

$ git checkout machomebrew/origin
$ brew config
...
OS: Ubuntu 17.10 (artful)
Host glibc: N/A
/usr/bin/gcc: 7.2.0
glibc: N/A
Error: uninitialized constant Formulary::FormulaNamespacea0c71e341d02dc282fdc357aca4c912d::Gcc::GlibcRequirement
Did you mean?  Requirement
               GitRequirement
               MPIRequirement
/home/buck/prefix/brew/Library/Taps/homebrew/homebrew-core/Formula/gcc.rb:51:in `<class:Gcc>'
/home/buck/prefix/brew/Library/Taps/homebrew/homebrew-core/Formula/gcc.rb:1:in `load_formula'
/home/buck/prefix/brew/Library/Homebrew/formulary.rb:27:in `module_eval'
/home/buck/prefix/brew/Library/Homebrew/formulary.rb:27:in `load_formula'
/home/buck/prefix/brew/Library/Homebrew/formulary.rb:47:in `load_formula_from_path'
/home/buck/prefix/brew/Library/Homebrew/formulary.rb:102:in `load_file'
/home/buck/prefix/brew/Library/Homebrew/formulary.rb:93:in `klass'
/home/buck/prefix/brew/Library/Homebrew/formulary.rb:89:in `get_formula'
/home/buck/prefix/brew/Library/Homebrew/formulary.rb:280:in `factory'
/home/buck/prefix/brew/Library/Homebrew/extend/os/linux/system_config.rb:32:in `formula_linked_version'
/home/buck/prefix/brew/Library/Homebrew/extend/os/linux/system_config.rb:44:in `block in dump_verbose_config'
/home/buck/prefix/brew/Library/Homebrew/extend/os/linux/system_config.rb:43:in `each'
/home/buck/prefix/brew/Library/Homebrew/extend/os/linux/system_config.rb:43:in `dump_verbose_config'
/home/buck/prefix/brew/Library/Homebrew/cmd/config.rb:12:in `config'
/home/buck/prefix/brew/Library/Homebrew/brew.rb:100:in `<main>'

return Version::NULL unless version
@system_version = Version.new version
end
Expand Down
6 changes: 5 additions & 1 deletion Library/Homebrew/shims/linux/super/cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ class Cmd
# -R is not the correct way to pass rpaths to the linker
path = chuzzle($1) || enum.next
wl = "-Wl," unless mode == :ld
args << "#{wl}-rpath=" if keep?(path)
if keep?(path)
args << "#{wl}--enable-new-dtags"
args << "#{wl}-rpath="
end
Copy link
Member

Choose a reason for hiding this comment

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

This change cannot be sent upstream. Since the Android dynamic linker is open source, playing the long game, I'd suggest contributing a patch to Android to add support for DT_RPATH. Alternatively, I'd suggest the Termux ld tool enable --enable-new-dtags by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't imagine Android being amenable to that since "rpath is a design bug". I'll look into option B.

else
args << arg
end
Expand Down Expand Up @@ -255,6 +258,7 @@ class Cmd
args += ["#{wl}--dynamic-linker=#{dynamic_linker_path}"] if dynamic_linker_path
args << "-B#{@opt}/glibc/lib" unless mode == :ld
args += path_flags("-L", library_paths)
args << "#{wl}--enable-new-dtags"
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

args += rpath_flags("#{wl}-rpath=", rpath_paths)
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/shims/scm/git
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ brew_repo_version="$(quiet_safe_cd "$SCM_DIR/../../../../bin" && pwd -P)/$SCM_FI
safe_exec "$brew_repo_version" "$@"

IFS=$'\n'
for path in $(/usr/bin/which -a "$SCM_FILE" 2>/dev/null)
for path in $(command -v "$SCM_FILE" 2>/dev/null)
Copy link
Member

Choose a reason for hiding this comment

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

This patch can go upstream to Homebrew/brew. which is not an essential utility on Debian and is not installed by default in the fedora Docker image. command -v is POSIX and universal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you suggest a separate CL for each of these little bits?

Copy link
Member

Choose a reason for hiding this comment

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

What's a CL? I'd suggest a separate PR for each change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, yes. "CL" is our jargon at work for PR. You'll see a bunch of small PRs for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do
if [[ "$path" != "/usr/bin/$SCM_FILE" ]]
then
Expand Down
3 changes: 2 additions & 1 deletion bin/brew
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ done
# test-bot does environment filtering itself
if [[ -z "$HOMEBREW_NO_ENV_FILTERING" && "$1" != "test-bot" ]]
then
PATH="/usr/bin:/bin:/usr/sbin:/sbin"
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/bin/applets"
Copy link
Member

Choose a reason for hiding this comment

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

Symlink


FILTERED_ENV=()
# Filter all but the specific variables.
for VAR in HOME SHELL PATH TERM LOGNAME USER CI CIRCLECI TRAVIS SSH_AUTH_SOCK SUDO_ASKPASS \
LD_LIBRARY_PATH ANDROID_ROOT ANDROID_DATA \
Copy link
Member

Choose a reason for hiding this comment

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

This patch cannot go upstream. As a workaround, you can use HOMEBREW_NO_ENV_FILTERING=1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hope to convince termux to switch to using DT_RUNPATH, then we don't need this any more.
I added ANDROID_ROOT/DATA to silence some warnings, but I didn't dig into it much, and I suspect they're not essential.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the environment variable to the android wiki page, and suggested upstream that termux enable RUNPATH by default like the rest of Linux. IMHO Homebrew should as well, but I'll leave well enough alone :)

http_proxy https_proxy ftp_proxy no_proxy all_proxy HTTPS_PROXY FTP_PROXY ALL_PROXY \
"${!HOMEBREW_@}" "${!TRAVIS_@}" "${!JENKINS_@}"
do
Expand Down