Skip to content

Commit 5604aa6

Browse files
committed
Merge branch 'ps/build-meson-fixes-0130' into seen
Assorted fixes and improvements to the build procedure based on meson. * ps/build-meson-fixes-0130: gitlab-ci: restrict maximum number of link jobs on Windows meson: consistently use custom program paths to resolve programs meson: fix overwritten `git` variable meson: prevent finding sed(1) in a loop meson: improve handling of `sane_tool_path` option meson: improve PATH handling meson: drop separate version library meson: stop linking libcurl into all executables meson: introduce `libgit_curl` dependency meson: simplify use of the common-main library meson: inline the static 'git' library meson: fix OpenSSL fallback when not explicitly required meson: fix exec path with enabled runtime prefix
2 parents ac3f4ba + 8ce506d commit 5604aa6

File tree

8 files changed

+85
-97
lines changed

8 files changed

+85
-97
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ build:msvc-meson:
164164
extends: .msvc-meson
165165
stage: build
166166
script:
167-
- meson setup build -Dperl=disabled
167+
- meson setup build -Dperl=disabled -Dbackend_max_links=1
168168
- meson compile -C build
169169
artifacts:
170170
paths:

Documentation/howto/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ custom_target(
4141
foreach howto : howto_sources
4242
howto_stripped = custom_target(
4343
command: [
44-
find_program('sed'),
44+
sed,
4545
'-e',
4646
'1,/^$/d',
4747
'@INPUT@',

Documentation/meson.build

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,17 @@ manpages = {
207207

208208
docs_backend = get_option('docs_backend')
209209
if docs_backend == 'auto'
210-
if find_program('asciidoc', required: false).found()
210+
if find_program('asciidoc', dirs: program_path, required: false).found()
211211
docs_backend = 'asciidoc'
212-
elif find_program('asciidoctor', required: false).found()
212+
elif find_program('asciidoctor', dirs: program_path, required: false).found()
213213
docs_backend = 'asciidoctor'
214214
else
215215
error('Neither asciidoc nor asciidoctor were found.')
216216
endif
217217
endif
218218

219219
if docs_backend == 'asciidoc'
220-
asciidoc = find_program('asciidoc', required: true)
220+
asciidoc = find_program('asciidoc', dirs: program_path)
221221
asciidoc_html = 'xhtml11'
222222
asciidoc_docbook = 'docbook'
223223
xmlto_extra = [ ]
@@ -246,7 +246,7 @@ if docs_backend == 'asciidoc'
246246
asciidoc_conf,
247247
]
248248
elif docs_backend == 'asciidoctor'
249-
asciidoctor = find_program('asciidoctor', required: true)
249+
asciidoctor = find_program('asciidoctor', dirs: program_path)
250250
asciidoc_html = 'xhtml5'
251251
asciidoc_docbook = 'docbook5'
252252
xmlto_extra = [
@@ -284,8 +284,7 @@ elif docs_backend == 'asciidoctor'
284284
]
285285
endif
286286

287-
git = find_program('git', required: false)
288-
xmlto = find_program('xmlto')
287+
xmlto = find_program('xmlto', dirs: program_path)
289288

290289
cmd_lists = [
291290
'cmds-ancillaryinterrogators.adoc',
@@ -406,7 +405,7 @@ if get_option('docs').contains('html')
406405
pointing_to: 'git.html',
407406
)
408407

409-
xsltproc = find_program('xsltproc')
408+
xsltproc = find_program('xsltproc', dirs: program_path)
410409

411410
user_manual_xml = custom_target(
412411
command: asciidoc_common_options + [

meson.build

Lines changed: 70 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -191,30 +191,29 @@ project('git', 'c',
191191
fs = import('fs')
192192

193193
program_path = []
194-
# Git for Windows provides all the tools we need to build Git.
195-
if host_machine.system() == 'windows'
196-
program_path += [ 'C:/Program Files/Git/bin', 'C:/Program Files/Git/usr/bin' ]
194+
if get_option('sane_tool_path').length() != 0
195+
program_path = get_option('sane_tool_path')
196+
elif host_machine.system() == 'windows'
197+
# Git for Windows provides all the tools we need to build Git.
198+
program_path = [ 'C:/Program Files/Git/bin', 'C:/Program Files/Git/usr/bin' ]
197199
endif
198200

199201
cygpath = find_program('cygpath', dirs: program_path, required: false)
200202
diff = find_program('diff', dirs: program_path)
203+
git = find_program('git', dirs: program_path, required: false)
204+
sed = find_program('sed', dirs: program_path)
201205
shell = find_program('sh', dirs: program_path)
202206
tar = find_program('tar', dirs: program_path)
203207

204-
script_environment = environment()
205-
foreach tool : ['cat', 'cut', 'grep', 'sed', 'sort', 'tr', 'uname']
206-
program = find_program(tool, dirs: program_path)
207-
script_environment.prepend('PATH', fs.parent(program.full_path()))
208+
# Sanity-check that programs required for the build exist.
209+
foreach tool : ['cat', 'cut', 'grep', 'sort', 'tr', 'uname']
210+
find_program(tool, dirs: program_path)
208211
endforeach
209212

210-
git = find_program('git', dirs: program_path, required: false)
211-
if git.found()
212-
script_environment.prepend('PATH', fs.parent(git.full_path()))
213-
endif
214-
215-
if get_option('sane_tool_path') != ''
216-
script_environment.prepend('PATH', get_option('sane_tool_path'))
217-
endif
213+
script_environment = environment()
214+
foreach path : program_path
215+
script_environment.prepend('PATH', path)
216+
endforeach
218217

219218
# The environment used by GIT-VERSION-GEN. Note that we explicitly override
220219
# environment variables that might be set by the user. This is by design so
@@ -480,6 +479,7 @@ libgit_sources = [
480479
'userdiff.c',
481480
'utf8.c',
482481
'varint.c',
482+
'version.c',
483483
'versioncmp.c',
484484
'walker.c',
485485
'wildmatch.c',
@@ -679,8 +679,9 @@ else
679679
build_options_config.set('WITH_BREAKING_CHANGES', '')
680680
endif
681681

682-
if get_option('sane_tool_path') != ''
683-
build_options_config.set_quoted('BROKEN_PATH_FIX', 's|^\# @BROKEN_PATH_FIX@$|git_broken_path_fix "' + get_option('sane_tool_path') + '"|')
682+
if get_option('sane_tool_path').length() != 0
683+
sane_tool_path = (host_machine.system() == 'windows' ? ';' : ':').join(get_option('sane_tool_path'))
684+
build_options_config.set_quoted('BROKEN_PATH_FIX', 's|^\# @BROKEN_PATH_FIX@$|git_broken_path_fix "' + sane_tool_path + '"|')
684685
else
685686
build_options_config.set_quoted('BROKEN_PATH_FIX', '/^\# @BROKEN_PATH_FIX@$/d')
686687
endif
@@ -700,7 +701,6 @@ libgit_c_args = [
700701
'-DETC_GITATTRIBUTES="' + get_option('gitattributes') + '"',
701702
'-DETC_GITCONFIG="' + get_option('gitconfig') + '"',
702703
'-DFALLBACK_RUNTIME_PREFIX="' + get_option('prefix') + '"',
703-
'-DGIT_EXEC_PATH="' + get_option('prefix') / get_option('libexecdir') / 'git-core"',
704704
'-DGIT_HOST_CPU="' + host_machine.cpu_family() + '"',
705705
'-DGIT_HTML_PATH="' + get_option('datadir') / 'doc/git-doc"',
706706
'-DGIT_INFO_PATH="' + get_option('infodir') + '"',
@@ -949,7 +949,9 @@ if curl.found()
949949
use_curl_for_imap_send = true
950950
endif
951951

952-
libgit_dependencies += curl
952+
# Most executables don't have to link against libcurl, but we still need its
953+
# include directories so that we can resolve LIBCURL_VERSION in "help.c".
954+
libgit_dependencies += curl.partial_dependency(includes: true)
953955
libgit_c_args += '-DCURL_DISABLE_TYPECHECK'
954956
build_options_config.set('NO_CURL', '')
955957
else
@@ -1376,7 +1378,11 @@ if https_backend == 'auto' and security_framework.found()
13761378
endif
13771379

13781380
openssl_required = 'openssl' in [csprng_backend, https_backend, sha1_backend, sha1_unsafe_backend, sha256_backend]
1379-
openssl = dependency('openssl', required: openssl_required, default_options: ['default_library=static'])
1381+
openssl = dependency('openssl',
1382+
required: openssl_required,
1383+
allow_fallback: openssl_required or https_backend == 'auto',
1384+
default_options: ['default_library=static'],
1385+
)
13801386
if https_backend == 'auto' and openssl.found()
13811387
https_backend = 'openssl'
13821388
endif
@@ -1390,6 +1396,7 @@ elif https_backend == 'openssl'
13901396
else
13911397
# We either couldn't find any dependencies with 'auto' or the user requested
13921398
# 'none'. Both cases are benign.
1399+
https_backend = 'none'
13931400
endif
13941401

13951402
if https_backend != 'openssl'
@@ -1489,6 +1496,7 @@ endif
14891496
if get_option('runtime_prefix')
14901497
libgit_c_args += '-DRUNTIME_PREFIX'
14911498
build_options_config.set('RUNTIME_PREFIX', 'true')
1499+
git_exec_path = get_option('libexecdir') / 'git-core'
14921500

14931501
if compiler.has_header('mach-o/dyld.h')
14941502
libgit_c_args += '-DHAVE_NS_GET_EXECUTABLE_PATH'
@@ -1525,7 +1533,9 @@ if get_option('runtime_prefix')
15251533
endif
15261534
else
15271535
build_options_config.set('RUNTIME_PREFIX', 'false')
1536+
git_exec_path = get_option('prefix') / get_option('libexecdir') / 'git-core'
15281537
endif
1538+
libgit_c_args += '-DGIT_EXEC_PATH="' + git_exec_path + '"'
15291539

15301540
git_version_file = custom_target(
15311541
command: [
@@ -1556,32 +1566,18 @@ version_def_h = custom_target(
15561566
depends: [git_version_file],
15571567
env: version_gen_environment,
15581568
)
1559-
1560-
# Build a separate library for "version.c" so that we do not have to rebuild
1561-
# everything when the current Git commit changes.
1562-
libgit_version_library = static_library('git-version',
1563-
sources: [
1564-
'version.c',
1565-
version_def_h,
1566-
],
1567-
c_args: libgit_c_args + [
1568-
'-DGIT_VERSION_H="' + version_def_h.full_path() + '"',
1569-
],
1570-
dependencies: libgit_dependencies,
1571-
include_directories: libgit_include_directories,
1572-
)
1573-
1574-
libgit_library = static_library('git',
1575-
sources: libgit_sources,
1576-
c_args: libgit_c_args,
1577-
link_with: libgit_version_library,
1578-
dependencies: libgit_dependencies,
1579-
include_directories: libgit_include_directories,
1580-
)
1569+
libgit_sources += version_def_h
15811570

15821571
libgit = declare_dependency(
1572+
link_with: static_library('git',
1573+
sources: libgit_sources,
1574+
c_args: libgit_c_args + [
1575+
'-DGIT_VERSION_H="' + version_def_h.full_path() + '"',
1576+
],
1577+
dependencies: libgit_dependencies,
1578+
include_directories: libgit_include_directories,
1579+
),
15831580
compile_args: libgit_c_args,
1584-
link_with: libgit_library,
15851581
dependencies: libgit_dependencies,
15861582
include_directories: libgit_include_directories,
15871583
)
@@ -1622,97 +1618,95 @@ if host_machine.system() == 'windows'
16221618
error('Unsupported compiler ' + compiler.get_id())
16231619
endif
16241620
endif
1625-
common_main_library = static_library('common-main',
1621+
1622+
libgit_commonmain = declare_dependency(
16261623
sources: common_main_sources,
1627-
c_args: libgit_c_args,
1628-
dependencies: libgit_dependencies,
1629-
include_directories: libgit_include_directories,
1630-
)
1631-
common_main = declare_dependency(
1632-
link_with: common_main_library,
16331624
link_args: common_main_link_args,
1625+
dependencies: [ libgit ],
16341626
)
16351627

16361628
bin_wrappers = [ ]
16371629
test_dependencies = [ ]
16381630

1639-
git = executable('git',
1631+
git_builtin = executable('git',
16401632
sources: builtin_sources + 'git.c',
1641-
dependencies: [libgit, common_main],
1633+
dependencies: [libgit_commonmain],
16421634
install: true,
16431635
install_dir: get_option('libexecdir') / 'git-core',
16441636
)
1645-
bin_wrappers += git
1637+
bin_wrappers += git_builtin
16461638

16471639
test_dependencies += executable('git-daemon',
16481640
sources: 'daemon.c',
1649-
dependencies: [libgit, common_main],
1641+
dependencies: [libgit_commonmain],
16501642
install: true,
16511643
install_dir: get_option('libexecdir') / 'git-core',
16521644
)
16531645

16541646
test_dependencies += executable('git-sh-i18n--envsubst',
16551647
sources: 'sh-i18n--envsubst.c',
1656-
dependencies: [libgit, common_main],
1648+
dependencies: [libgit_commonmain],
16571649
install: true,
16581650
install_dir: get_option('libexecdir') / 'git-core',
16591651
)
16601652

16611653
bin_wrappers += executable('git-shell',
16621654
sources: 'shell.c',
1663-
dependencies: [libgit, common_main],
1655+
dependencies: [libgit_commonmain],
16641656
install: true,
16651657
install_dir: get_option('libexecdir') / 'git-core',
16661658
)
16671659

16681660
test_dependencies += executable('git-http-backend',
16691661
sources: 'http-backend.c',
1670-
dependencies: [libgit, common_main],
1662+
dependencies: [libgit_commonmain],
16711663
install: true,
16721664
install_dir: get_option('libexecdir') / 'git-core',
16731665
)
16741666

16751667
bin_wrappers += executable('scalar',
16761668
sources: 'scalar.c',
1677-
dependencies: [libgit, common_main],
1669+
dependencies: [libgit_commonmain],
16781670
install: true,
16791671
install_dir: get_option('libexecdir') / 'git-core',
16801672
)
16811673

16821674
if get_option('curl').enabled()
1683-
curl_sources = [
1684-
'http.c',
1685-
'http-walker.c',
1686-
]
1675+
libgit_curl = declare_dependency(
1676+
sources: [
1677+
'http.c',
1678+
'http-walker.c',
1679+
],
1680+
dependencies: [libgit_commonmain, curl],
1681+
)
16871682

1688-
git_remote_http = executable('git-remote-http',
1689-
sources: curl_sources + 'remote-curl.c',
1690-
dependencies: [libgit, common_main],
1683+
test_dependencies += executable('git-remote-http',
1684+
sources: 'remote-curl.c',
1685+
dependencies: [libgit_curl],
16911686
install: true,
16921687
install_dir: get_option('libexecdir') / 'git-core',
16931688
)
1694-
test_dependencies += git_remote_http
16951689

16961690
test_dependencies += executable('git-http-fetch',
1697-
sources: curl_sources + 'http-fetch.c',
1698-
dependencies: [libgit, common_main],
1691+
sources: 'http-fetch.c',
1692+
dependencies: [libgit_curl],
16991693
install: true,
17001694
install_dir: get_option('libexecdir') / 'git-core',
17011695
)
17021696

17031697
if expat.found()
17041698
test_dependencies += executable('git-http-push',
1705-
sources: curl_sources + 'http-push.c',
1706-
dependencies: [libgit, common_main],
1699+
sources: 'http-push.c',
1700+
dependencies: [libgit_curl],
17071701
install: true,
17081702
install_dir: get_option('libexecdir') / 'git-core',
17091703
)
17101704
endif
17111705

17121706
foreach alias : [ 'git-remote-https', 'git-remote-ftp', 'git-remote-ftps' ]
17131707
test_dependencies += executable(alias,
1714-
objects: git_remote_http.extract_all_objects(recursive: false),
1715-
dependencies: [libgit, common_main],
1708+
sources: 'remote-curl.c',
1709+
dependencies: [libgit_curl],
17161710
)
17171711

17181712
install_symlink(alias + executable_suffix,
@@ -1722,22 +1716,17 @@ if get_option('curl').enabled()
17221716
endforeach
17231717
endif
17241718

1725-
imap_send_sources = ['imap-send.c']
1726-
if use_curl_for_imap_send
1727-
imap_send_sources += curl_sources
1728-
endif
1729-
17301719
test_dependencies += executable('git-imap-send',
1731-
sources: imap_send_sources,
1732-
dependencies: [libgit, common_main],
1720+
sources: 'imap-send.c',
1721+
dependencies: [ use_curl_for_imap_send ? libgit_curl : libgit_commonmain ],
17331722
install: true,
17341723
install_dir: get_option('libexecdir') / 'git-core',
17351724
)
17361725

17371726
foreach alias : [ 'git-receive-pack', 'git-upload-archive', 'git-upload-pack' ]
17381727
bin_wrappers += executable(alias,
1739-
objects: git.extract_all_objects(recursive: false),
1740-
dependencies: [libgit, common_main],
1728+
objects: git_builtin.extract_all_objects(recursive: false),
1729+
dependencies: [libgit],
17411730
)
17421731

17431732
install_symlink(alias + executable_suffix,

meson_options.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ option('perl_cpan_fallback', type: 'boolean', value: true,
1313
description: 'Install bundled copies of CPAN modules that serve as a fallback in case the modules are not available on the system.')
1414
option('runtime_prefix', type: 'boolean', value: false,
1515
description: 'Resolve ancillary tooling and support files relative to the location of the runtime binary instead of hard-coding them into the binary.')
16-
option('sane_tool_path', type: 'string', value: '',
17-
description: 'A colon-separated list of paths to prepend to PATH if your tools in /usr/bin are broken.')
16+
option('sane_tool_path', type: 'array', value: [],
17+
description: 'An array of paths to pick up tools from in case the normal tools are broken or lacking.')
1818

1919
# Build information compiled into Git and other parts like documentation.
2020
option('build_date', type: 'string', value: '',

0 commit comments

Comments
 (0)