Files
chromebrew/packages/git.rb
Satadru Pramanik, DO, MPH, MEng 66ca77930b Add libc version and chromeos milestone to container bash prompts (#10335)
* Use agree_to_remove in ruby_pry.rb.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Add cmake options for build_relative_dir

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Adjust cmake buildsystems.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Alphabetize properties in buildsystems/python.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Add updated crew_profile_base.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Add missing filelists, add glibc fallback to gcc packages.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Add milestone to container git prompt.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Use more heredocs for the git commands.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Adjust git postinstall.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Add binaries.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Adjust unit test to do build test right after crew upgrade.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* lint

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Suggested changes.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

---------

Signed-off-by: Satadru Pramanik <satadru@gmail.com>
2024-08-22 21:26:03 -05:00

105 lines
5.1 KiB
Ruby

require 'buildsystems/cmake'
class Git < CMake
description 'Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.'
homepage 'https://git-scm.com/'
version '2.46.0-1' # Do not use @_ver here, it will break the installer.
license 'GPL-2'
compatibility 'all'
source_url "https://mirrors.edge.kernel.org/pub/software/scm/git/git-#{version.split('-').first}.tar.xz"
source_sha256 '7f123462a28b7ca3ebe2607485f7168554c2b10dfc155c7ec46300666ac27f95'
binary_compression 'tar.zst'
binary_sha256({
aarch64: 'a75eae1e96d4a9319e284afc682b7b68b50ec060e9ab518785df3c2a6ded5410',
armv7l: 'a75eae1e96d4a9319e284afc682b7b68b50ec060e9ab518785df3c2a6ded5410',
i686: '19e86f61ad78449fb1df678067ad38716430dd58767c953f2a3bac0cf632cc8a',
x86_64: 'fa26980dce128e72383fadbe3b0feedd6969e93f9cc1e9d461cc31ddf8ca9bcd'
})
depends_on 'ca_certificates' => :build
depends_on 'curl' # R
depends_on 'expat' # R
depends_on 'glibc' # R
depends_on 'libunistring' # R
depends_on 'pcre2' # R
depends_on 'zlib' # R
print_source_bashrc
cmake_build_relative_dir 'contrib/buildsystems'
cmake_options '-DUSE_VCPKG=FALSE'
def self.patch
# Patch to prevent error function conflict with libidn2
# By replacing all calls to error with git_error.
system "sed -i 's,^#undef error$,#undef git_error,' usage.c"
sedcmd = 's/\([[:blank:]]\)error(/\1git_error(/'.dump
system "grep -rl '[[:space:]]error(' . | xargs sed -i #{sedcmd}"
sedcmd2 = 's/\([[:blank:]]\)error (/\1git_error (/'.dump
system "grep -rl '[[:space:]]error (' . | xargs sed -i #{sedcmd2}"
system "grep -rl ' !!error(' . | xargs sed -i 's/ !!error(/ !!git_error(/g'"
system "sed -i 's/#define git_error(...) (error(__VA_ARGS__), const_error())/#define git_error(...) (git_error(__VA_ARGS__), const_error())/' git-compat-util.h"
# CMake patches.
# Avoid undefined reference to `trace2_collect_process_info' & `obstack_free'
system "sed -i 's,compat_SOURCES unix-socket.c unix-stream-server.c,compat_SOURCES unix-socket.c unix-stream-server.c compat/linux/procinfo.c compat/obstack.c,g' contrib/buildsystems/CMakeLists.txt"
# The VCPKG optout in this CmakeLists.txt file is quite broken.
system "sed -i 's/set(USE_VCPKG/#set(USE_VCPKG/g' contrib/buildsystems/CMakeLists.txt"
system "sed -i 's,set(PERL_PATH /usr/bin/perl),set(PERL_PATH #{CREW_PREFIX}/bin/perl),g' contrib/buildsystems/CMakeLists.txt"
system "sed -i 's,#!/usr/bin,#!#{CREW_PREFIX}/bin,g' contrib/buildsystems/CMakeLists.txt"
# Without the following DESTDIR doesn't work.
system "sed -i 's,${CMAKE_INSTALL_PREFIX}/bin/git,${CMAKE_BINARY_DIR}/git,g' contrib/buildsystems/CMakeLists.txt"
system "sed -i 's,${CMAKE_INSTALL_PREFIX}/bin/git,\\\\$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/git,g' contrib/buildsystems/CMakeLists.txt"
system "sed -i 's,${CMAKE_INSTALL_PREFIX},\\\\$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX},g' contrib/buildsystems/CMakeLists.txt"
end
cmake_build_extras do
git_env = <<~EOF
GIT_PS1_SHOWDIRTYSTATE=yes
GIT_PS1_SHOWSTASHSTATE=yes
GIT_PS1_SHOWUNTRACKEDFILES=yes
GIT_PS1_SHOWUPSTREAM=auto
GIT_PS1_DESCRIBE_STYLE=default
GIT_PS1_SHOWCOLORHINTS=yes
# Add LIBC_VERSION and CHROMEOS_RELEASE_CHROME_MILESTONE set in
# crew_profile_base to prompt if in a container.
if [[ -e /.dockerenv ]] && [ -n "${LIBC_VERSION+1}" ] && [ -n "${CHROMEOS_RELEASE_CHROME_MILESTONE+1}" ]; then
PS1='\\[\\033[1;34m\\]\\u@\\H:$LIBC_VERSION M$CHROMEOS_RELEASE_CHROME_MILESTONE \\[\\033[1;33m\\]\\w \\[\\033[1;31m\\]$(__git_ps1 "(%s)")\\[\\033[0m\\]\\$ '
else
PS1='\\[\\033[1;34m\\]\\u@\\H \\[\\033[1;33m\\]\\w \\[\\033[1;31m\\]$(__git_ps1 "(%s)")\\[\\033[0m\\]\\$ '
fi
EOF
File.write('contrib/completion/git-prompt.sh', git_env, mode: 'a')
end
cmake_install_extras do
FileUtils.mkdir_p "#{CREW_DEST_PREFIX}/share/git-completion"
FileUtils.cp_r Dir.glob('contrib/completion/.'), "#{CREW_DEST_PREFIX}/share/git-completion/"
File.write 'git_bashd_env', <<~GIT_BASHD_EOF
# git bash completion
source #{CREW_PREFIX}/share/git-completion/git-completion.bash
GIT_BASHD_EOF
FileUtils.install 'git_bashd_env', "#{CREW_DEST_PREFIX}/etc/bash.d/git", mode: 0o644
FileUtils.install 'contrib/completion/git-prompt.sh', "#{CREW_DEST_PREFIX}/etc/bash.d/git-prompt.sh", mode: 0o644
end
def self.check
# Check to see if linking libcurl worked, which means
# git-remote-https should exist
unless File.symlink?("#{CREW_DEST_PREFIX}/libexec/git-core/git-remote-https") ||
File.exist?("#{CREW_DEST_PREFIX}/libexec/git-core/git-remote-https")
abort 'git-remote-https is broken'.lightred
end
end
def self.postinstall
ExitMessage.add "\ncd /path/to/git/repo and you should see the branch displayed in the prompt.\n".lightblue
return unless File.directory?("#{CREW_PREFIX}/lib/crew/.git")
puts 'Running git garbage collection...'.lightblue
system 'git gc', chdir: CREW_LIB_PATH, exception: false
end
end