Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ninja clean fails when a target is defined with the same name as a directory #1644

Closed
keszybz opened this issue Apr 19, 2017 · 9 comments
Closed

Comments

@keszybz
Copy link
Contributor

keszybz commented Apr 19, 2017

I get the following error:

$ ninja-build clean
[2/2] 'Cleaning'
FAILED: clean 
'ninja-build' '-t' 'clean'
ninja: error: remove(man): Directory not empty
Cleaning... 1 files.
ninja: build stopped: subcommand failed.
$ ls -lG man/
total 8
-rw-rw-r--. 1 zbyszek  404 Apr 19 11:13 custom-entities.ent
drwxrwxr-x. 2 zbyszek 4096 Apr 19 11:13 rules/

So the man directory should not be removed at all, for two reasons: 1. there's a subdir, 2. there's a generated file. I don't know why clean tries to remove it.

I tried to make simple test case, but I couldn't reproduce the error. So it's something in the way that man is defined...

@keszybz keszybz changed the title meson clean fails because configure_file prevents a directory from being removed meson clean fails when run_target with the same name as a directory is used Apr 19, 2017
@keszybz
Copy link
Contributor Author

keszybz commented Apr 19, 2017

OK, now I get it:

==> meson.build <==
project('clean1', 'c')
conf = configuration_data()
subdir('sub1')

==> sub1/meson.build <==
configure_file(
        output : 'config.h',
        configuration : conf)
run_target('sub1',
           command : ['echo'])
$ nj clean
[1/1] 'Cleaning'
FAILED: clean 
'ninja-build' '-t' 'clean'
ninja: error: remove(sub1): Directory not empty
Cleaning... 0 files.
ninja: build stopped: subcommand failed.

@keszybz keszybz changed the title meson clean fails when run_target with the same name as a directory is used ninja-build clean fails when run_target with the same name as a directory is used Apr 19, 2017
@QuLogic
Copy link
Member

QuLogic commented Apr 21, 2017

The name of the run target is the "output" of the build statement and ninja cleans things based on build outputs, so... I'm not sure how to express this in ninja.

@QuLogic
Copy link
Member

QuLogic commented Apr 21, 2017

Maybe run targets should depend on the phony rule instead of the made-up CUSTOM_COMMAND, since they aren't producing any outputs?

@nirbheek nirbheek added the bug label Apr 21, 2017
@nirbheek nirbheek changed the title ninja-build clean fails when run_target with the same name as a directory is used ninja clean fails when a target is defined with the same name as a directory Aug 13, 2017
@nirbheek
Copy link
Member

This is also a problem for libgxps and nautilus which have a directory called test. The same problem also happens if you define a directory called benchmark.

@nirbheek
Copy link
Member

nirbheek commented Aug 13, 2017

Maybe run targets should depend on the phony rule instead of the made-up CUSTOM_COMMAND, since they aren't producing any outputs?

Can't use phony because that means the target is an alias for some other target and if you don't specify some other target it means that it does nothing. The COMMAND = line will get ignored in either case.

What we could do, to work around this Ninja bug, is to define targets called meson-test, meson-benchmark, and meson-RUN_TARGET_NAME which do the actual work, and have test, benchmark, RUN_TARGET_NAME as aliases for that with phony. I've tested it and it does work:

build meson-test: CUSTOM_COMMAND all PHONY
 COMMAND = /usr/bin/python3 -u /home/nirbheek/projects/repositories/github/meson.git/mesontest.py --no-rebuild --print-errorlogs
 DESC = Running$ all$ tests.
 pool = console

build test: phony meson-test

However, simultaneously we should try to fix this in Ninja too.

@nirbheek nirbheek added this to the 0.42.0 milestone Aug 13, 2017
@jpakkane
Copy link
Member

The test target is tagged phony and it works just fine (just runs a command). Marking run targets with PHONY should work.

I just tested by creating a directory called test in a build dir and running ninja test. It works as it should.

@nirbheek
Copy link
Member

I just tested by creating a directory called test in a build dir and running ninja test. It works as it should.

That's not the problem. The problem is that ninja clean fails if you define any targets inside a directory called test (or benchmark or any other CUSTOM_COMMAND target).

@nirbheek
Copy link
Member

FWIW, the upstream bug for the general problem of not recursively deleting directories on non-Windows platforms is ninja-build/ninja#828.

@jpakkane
Copy link
Member

Okay, let's put in the workaround with a link to that bug.

keszybz added a commit to keszybz/systemd that referenced this issue Jul 24, 2018
keszybz added a commit to keszybz/systemd that referenced this issue Oct 11, 2018
keszybz added a commit to keszybz/systemd that referenced this issue Oct 28, 2018
mesonbuild/meson#1644 was resolved in 0.42:
mesonbuild/meson@be44280,
but still no-go.

(cherry picked from commit 6939fb9)
keszybz added a commit to keszybz/systemd-stable that referenced this issue Oct 29, 2018
mesonbuild/meson#1644 was resolved in 0.42:
mesonbuild/meson@be44280,
but still no-go.

(cherry picked from commit 6939fb9)
keszybz added a commit to systemd/systemd-stable that referenced this issue Oct 29, 2018
mesonbuild/meson#1644 was resolved in 0.42:
mesonbuild/meson@be44280,
but still no-go.

(cherry picked from commit 6939fb9)
Yamakuzure pushed a commit to elogind/elogind that referenced this issue Nov 8, 2018
mesonbuild/meson#1644 was resolved in 0.42:
mesonbuild/meson@be44280,
but still no-go.

(cherry picked from commit 6939fb9eb4c76de630b71f6b2ad98686d7fbd1bf)
Yamakuzure pushed a commit to elogind/elogind that referenced this issue Feb 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants