Re: [PATCH v2 3/3] Makefile: replace most hardcoded object lists with $(wildcard)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Nov 06 2021, Phillip Wood wrote:

> On 06/11/2021 14:27, Ævar Arnfjörð Bjarmason wrote:
>> On Sat, Nov 06 2021, Phillip Wood wrote:
>> 
>>> Hi Ævar
>>>
>>> On 01/11/2021 19:19, Ævar Arnfjörð Bjarmason wrote:
>>>> Remove the hardcoded lists of objects in favor of using
>>>> $(wildcard). This means that every time a built-in, test tool etc. is
>>>> added we won't need to patch the top-level Makefile, except for the
>>>> few remaining cases where the asset in question would make it onto one
>>>> of our list of exceptions.
>>>> Ever since 81b50f3ce40 (Move 'builtin-*' into a 'builtin/'
>>>> subdirectory, 2010-02-22) this has been relatively easy to do (and
>>>> even before that we could glob builtin-*.c). This pattern of
>>>> exhaustively enumerating files was then carried forward for
>>>> e.g. TEST_BUILTINS_OBJS in efd71f8913a (t/helper: add an empty
>>>> test-tool program, 2018-03-24).
>>>> One reason not to do this is that now a new *.c file at the
>>>> top-level
>>>> will be immediately picked up, so if a new *.c file is being worked on
>>>> "make" will error if it doesn't compile, whereas before that file
>>>> would need to be explicitly listed in the Makefile. I think than small
>>>> trade-off is worth it.
>>>
>>> If I need to split up some uncommitted changes into several commits
>>> and I know it is going to be fiddly to do so I will sometimes copy the
>>> original file to foo.safe.c and then edit foo.c to create each
>>> commit. Then I can easily compile and test each commit and editing the
>>> file directly is often easier than using add -p and editing the
>>> hunks. With this patch running make will fail in that case I think.
>> Would being able to do something like:
>>      make EXCLUDE_WILDCARD=foo.safe.c
>> Satisfy this use-case?
>> We can also have some DEVOPTS knob so we'll prune out files found if
>> a
>> $(shell)-out to "git status" tells us they're untracked. I wouldn't mind
>> that (and could implement it) if it was optional.
>> Also note that you've got some of this already, e.g. we'll pick up
>> *.h
>> files via a glob for "make TAGS", the dependency graph etc.
>
> I'd be happier using 'git ls-files' with a glob if we need to move
> away from listing the files explicitly rather than having to pass some 
> exclude list when running make. Having seen your comments below about
> ls-files/find I had a look at the Makefile and they always seem to be 
> used together as "git ls-files ... || find ...". Doing that would mean
> we wouldn't try to build any untracked files but still find everything 
> in a tarball.

Yes we could use the $(wildcard) in a tarball, the issue of picking up
untracked files is a dev-checkout-only issue, no?

>>> [...]
>>> My recollection is that the discussions were about not having to touch
>>> CMakeList.txt when adding new files to the build and I think that
>>> largely works. I don't think a lot of the changes you have been making
>>> recently were anticipated in that discussion.
>> That's part of it, but the concern about needing to maintain two
>> systems
>> in perpetuity was also brought up, and it not being a hard dependency,
>> having that vs-{build,test} job soft-fail on it etc. were brought up but
>> that's not what we've got now.
>> In any case, having to maintain two build systems and the
>> maintainer(s)
>> of the CMake being inactive one is the situation we're in now.
>> 
>>>>    - The promised "We can add a (continue-on-error) to vs-build job to
>>>>      make this process less of a hindrance." in [2] never materialized.
>>>>      Since 4c2c38e800f (ci: modification of main.yml to use cmake for
>>>>      vs-build job, 2020-06-26) got a hard dependency on CMake as far as
>>>>      getting the CI to pass goes.
>>>>    - The "vs-build" CI doesn't actually require that there be no GNU
>>>> make
>>>>      usage in the job, as it itself has a hard dependency on running a
>>>>      "make -n artifacts-tar" command. So as far as any vs-specific special-sauce
>>>>      goes we don't need a GNU-make free build system for vs-build.
>>>
>>> We need GNU-make for the ci job but an individual developer using
>>> CMake does not need GNU-make installed. On linux it is possible to
>>> build git without having make installed by using cmake and ninja [1]
>> I'd tried that, but didn't know about your [1] topic. If you or
>> someone
>> is actively willing to fix things up in CMake....
>
> I only started working on that a few days ago. I was interested to see
> if using ninja was faster for building when just a few files have been 
> changed but it doesn't make much difference unless absolutely nothing
> has changed - I guess we don't have that many files in the grand
> scheme of things. The CMake support still lags the Makefile as
> currently things like GIT-VERSION-FILE and git-hooks.h are not
> regenerated when their inputs change. I'm not sure if I want to commit
> to doing much more on that at the moment.

I suspect that any other build system is faster because it doesn't
actually do what our Makefile does, which is something I've been trying
to slowly fix.

E.g. getting rid of the FORCE dependencies we've got. I submitted a
series just now to do some prep work for that:
https://lore.kernel.org/git/cover-00.16-00000000000-20211106T205717Z-avarab@xxxxxxxxx/

The performance of that:

0 $ hyperfine --warmup 3 -L v master,next,avar/Makefile-perl-python-shell-quote-various-fixes,avar/Makefile-get-rid-of-FORCE-rules-for-gmake-4.2-dependency -p 'git checkout {v} && make -j8 all' 'echo {v} && make -j8 all'
Benchmark #1: echo master && make -j8 all
  Time (mean ± σ):     127.7 ms ±  40.8 ms    [User: 111.5 ms, System: 17.4 ms]
  Range (min … max):   113.2 ms … 243.8 ms    10 runs
 
options.
 
Benchmark #2: echo next && make -j8 all
  Time (mean ± σ):     114.9 ms ±   0.9 ms    [User: 105.6 ms, System: 23.1 ms]
  Range (min … max):   113.5 ms … 116.3 ms    11 runs
 
Benchmark #3: echo avar/Makefile-perl-python-shell-quote-various-fixes && make -j8 all
  Time (mean ± σ):     121.6 ms ±  16.8 ms    [User: 107.9 ms, System: 22.2 ms]
  Range (min … max):   113.6 ms … 167.4 ms    10 runs
 
Benchmark #4: echo avar/Makefile-get-rid-of-FORCE-rules-for-gmake-4.2-dependency && make -j8 all
  Time (mean ± σ):      71.4 ms ±  17.2 ms    [User: 61.7 ms, System: 11.1 ms]
  Range (min … max):    64.2 ms … 131.9 ms    15 runs
 
Summary
  'echo avar/Makefile-get-rid-of-FORCE-rules-for-gmake-4.2-dependency && make -j8 all' ran
    1.61 ± 0.39 times faster than 'echo next && make -j8 all'
    1.70 ± 0.47 times faster than 'echo avar/Makefile-perl-python-shell-quote-various-fixes && make -j8 all'
    1.79 ± 0.72 times faster than 'echo master && make -j8 all'

I.e. so far I haven't really optimized anything much, but the next step
after that series above speeds it up by almost 2x for a noop run, and
there's other low-hanging fruit after that that I've got in some WIP
code somewhere. I think I managed to get it down to the 10-20ms range
for noop runs in one of those.

>>> [...]
>>>> My attempt to amend/revert 4c2c38e800f to have it use the
>>>> pre-4c2c38e800f "make" invocation as a fallback failed, partially
>>>> because I don't have a Windows development environment, so any attempt
>>>> to change it is a painfully slow round-trip to GitHub CI.
>>>> Let's instead have CMake call out to the Makefile asking it what the
>>>> definition of various variables lists is, rather than being forced to
>>>> maintain those lists in a way that CMake can parse with regexes (which
>>>> precludes anything but a giant hardcoded list).
>>>> I could familiarize myself enough with CMake to do this in some
>>>> CMake-native way, but that would take "just as long as adding it to
>>>> the Makefile"[2] (I think that took me <5 minutes, but I'm several
>>>> hours into fighting with CMake)
>>>> So I consider this both a bugfix to the stated aims of this CMake
>>>> integration, and a better way forward for having an alternate build
>>>> system. I.e. If someone really does care about a having a
>>>> GNU-make-less dependency for the "vs-build" I think this change offers
>>>> a much better way forward for that.
>>>
>>> I don't see how relying on GNU-make is a step forward for the CMake
>>> integration when it works without it now.
>> It's not if we assume we've got infinite man hours to maintain these
>> systems, but we don't.
>> I have some pending patches to make various common cases when using
>> make
>> much better, mainly speeding up no-op runs so things in rebase --exec go
>> faster.
>> So far I've been submitting the parts of that that don't step on the
>> toes of this cmake integration, and realistically if I've got to
>> implement everything in lockstep in two systems I'll probably just give
>> up on it.
>> Hence asking if there's some middle ground we can find here.
>
> What is it about listing the input files explicitly that slows things
> down? Surely it's faster than globbing the filesystem.

It doesn't slow things down. I'd like to get rid of these big hardcoded
lists to make it easier to add new [test] commands, anything that cuts
down on the "modify these N files, copy/pasting the last similar commit"
helps with that.

And we've got churn related to these lists being unsorted, being
re-sorted, and occasional tiresome merge conflicts etc.

The initial reason I finished this up was because I had a WIP patch to
add a "sort assertion" for these lists, per the discussion here:
https://lore.kernel.org/git/87mtv2dk18.fsf@xxxxxxxxxxxxxxxxxxx/

But I realized instead of doing that we could just use $(wildcard)
instead.

>> So you don't want to install "make" on Windows, but how about if we had
>> a script in contrib/ that generated these extractions of lists from the
>> Makefile instead of doing it on the fly, we could even commit those to
>> the repo.
>
> If I understand there would be some make rule that generates a list of
> dependencies and we'd commit that list to the repo and consume it in 
> CMakeLists.txt. I'd be fine with that

Ok that certainly helps & is a viable workaround.

>> Then I'd effectively get what I'm aiming for here, and cmake users could
>> just re-run that script, and if one of them did they could push the
>> result somewhere, and others could just fetch the generated assets.
>> 
>>> Overall I'm don't think that moving from a known set of dependencies
>>> to "build whatever C files are lying around in this directory" is an
>>> improvement.
>> The caveat you note above with "foo.safe.c" is something we've got
>> already, see various "$(wildcard)", "find" and "git ls-files" in the
>> Makefile. So this way we'll at least be consistent. Now we'll add stray
>> files to TAGS, apply "coccicheck" to them etc.
>
> I'm not so worried about those other targets, but being able to
> reliably build and test git with some cruft lying around is useful
> though. I'm still not entirely sure what the motivation for this
> change is (adding new files is not that common) but I think using the
> established "git ls-files || find" pattern would be a good way of
> globbing without picking up rubbish if there is a compelling reason to
> drop the lists.

I would like to get rid of those ls-files or whatever globs entirely,
whether that's by moving everything to wildcards or having them consume
the hardcoded lists doesn't really matter.

But it's a a wart that we're e.g. running coccicheck on one globbed set
of files, and compile a hardcoded list of files. Partially it's because
we conflate "list of known files" with "here's what we'd like to compile
on this platform".




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux