help-make
[Top][All Lists]
Advanced

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

Re: Get a target's prerequisites from an external script?


From: Sean Hammond
Subject: Re: Get a target's prerequisites from an external script?
Date: Sat, 16 Jul 2022 12:41:55 +0100
User-agent: Cyrus-JMAP/3.7.0-alpha0-755-g3e1da8b93f-fm-20220708.002-g3e1da8b9

On Fri, 15 Jul 2022, at 10:07 PM, Paul Smith wrote:
> There are multiple ways to work around this.  One way is to use
> secondary expansion[2], which would mean doing something like this:

Thanks! Yes, secondary expansion was what I needed. And thanks for the 
$(addprefix ...) tip as well.

This is what I ended up with, which seems to work for me:

```
find_prerequisites = $(addprefix requirements/,$(shell grep 
'^[[:blank:]]*\(-r\|-c\)[[:blank:]]*' "requirements/$*.in" | sed 
's/^[[:blank:]]*\(-r\|-c\)[[:blank:]]*//'))

.SECONDEXPANSION:
requirements/%.txt: requirements/%.in $$(find_prerequisites)
>   @touch -a $(subst requirements.txt,dev.txt,$@)
>   @tox -qe $(subst requirements,dev,$(basename $(notdir $@))) --run-command 
> 'pip-compile --allow-unsafe --quiet $(args) $<'

.PHONY: requirements requirements/
requirements requirements/: $(foreach file,$(wildcard 
requirements/*.in),$(basename $(file)).txt)
```

The recipe for compiling a requirements/%.txt file has to do with our 
particular setup. See the real thing here: 
https://github.com/hypothesis/lms/pull/4231

Usage:

If you've edited one or more requirements/*.in's just run `make requirements` 
to recompile the *.txt's that need to be recompiled.

To upgrade all packages in all *.txt's to their latest versions: make 
--always-make requirements args=--upgrade

To upgrade one package to its latest version in all *.txt's where that package 
appears: make --always-make requirements args='--upgrade-package foo'

To upgrade or downgrade a package to a particular version in all *.txt's where 
that package appears: make --always-make requirements args='--upgrade-package 
foo==1.2.3'

You can also ask it to compile particular requirements files with `make 
requirements/foo.txt` or `make requirements/foo.txt requirements/bar.txt`.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]