ninja-build / ninja

a small build system with a focus on speed
https://ninja-build.org/
Apache License 2.0
10.82k stars 1.57k forks source link

DEPFILE can't handle paths with '#' characters #1825

Open rleigh-lumiradx opened 3 years ago

rleigh-lumiradx commented 3 years ago

Example:

path\to\main.o:
  path\to\x-cube-cryptolib\AccHw_Crypto\STM32F7\Middlewares\ST\STM32_Crypto_AccHw\Inc\RSA\AccHw_rsa.h \
  path\to\x-cube-cryptolib\AccHw_Crypto\STM32F7\Middlewares\ST\STM32_Crypto_AccHw\Inc\RSA\PKCS#1v15\AccHw_rsa_pkcs1v15.h \
  path\to\x-cube-cryptolib\AccHw_Crypto\STM32F7\Middlewares\ST\STM32_Crypto_AccHw\Inc\RSA\LowLevel\AccHw_rsa_low_level.h \
  path\to\x-cube-cryptolib\AccHw_Crypto\STM32F7\Middlewares\ST\STM32_Crypto_AccHw\Inc\ECC\AccHw_ecc.h \

Note the filename RSA\PKCS#1v15\AccHw_rsa_pkcs1v15.h. This is what will break:

In .ninja_deps:

00071a20: 696e 7465 726e 616c 2e68 d5f0 ffff 9400  internal.h......
00071a30: 0000 7061 7468 2f74 6f2f 782d 6375 6265  ..path/to/x-cube
00071a40: 2d63 7279 7074 6f6c 6962 2f41 6363 4877  -cryptolib/AccHw
00071a50: 5f43 7279 7074 6f2f 5354 4d33 3246 372f  _Crypto/STM32F7/
00071a60: 4d69 6464 6c65 7761 7265 732f 5354 2f53  Middlewares/ST/S
00071a70: 544d 3332 5f43 7279 7074 6f5f 4163 6348  TM32_Crypto_AccH
00071a80: 772f 496e 632f 5253 412f 4163 6348 775f  w/Inc/RSA/AccHw_
00071a90: 7273 612e 6800 00d4 f0ff ff8c 0000 0070  rsa.h..........p
00071aa0: 6174 682f 746f 2f78 2d63 7562 652d 6372  ath/to/x-cube-cr
00071ab0: 7970 746f 6c69 622f 4163 6348 775f 4372  yptolib/AccHw_Cr
00071ac0: 7970 746f 2f53 544d 3332 4637 2f4d 6964  ypto/STM32F7/Mid
00071ad0: 646c 6577 6172 6573 2f53 542f 5354 4d33  dlewares/ST/STM3
00071ae0: 325f 4372 7970 746f 5f41 6363 4877 2f49  2_Crypto_AccHw/I
00071af0: 6e63 2f52 5341 2f50 4b43 5300 d3f0 ffff  nc/RSA/PKCS.....
00071b00: 2000 0000 3176 3135 2f41 6363 4877 5f72   ...1v15/AccHw_r
00071b10: 7361 5f70 6b63 7331 7631 352e 6800 0000  sa_pkcs1v15.h...
00071b20: d2f0 ffff a800 0000 7061 7468 2f74 6f2f  ........path/to/
00071b30: 782d 6375 6265 2d63 7279 7074 6f6c 6962  x-cube-cryptolib
00071b40: 2f41 6363 4877 5f43 7279 7074 6f2f 5354  /AccHw_Crypto/ST
00071b50: 4d33 3246 372f 4d69 6464 6c65 7761 7265  M32F7/Middleware
00071b60: 732f 5354 2f53 544d 3332 5f43 7279 7074  s/ST/STM32_Crypt
00071b70: 6f5f 4163 6348 772f 496e 632f 5253 412f  o_AccHw/Inc/RSA/
00071b80: 4c6f 774c 6576 656c 2f41 6363 4877 5f72  LowLevel/AccHw_r
00071b90: 7361 5f6c 6f77 5f6c 6576 656c 2e68 0000  sa_low_level.h..
00071ba0: 00d1 f0ff ff94 0000 0070 6174 682f 746f  .........path/to
00071bb0: 2f78 2d63 7562 652d 6372 7970 746f 6c69  /x-cube-cryptoli
00071bc0: 622f 4163 6348 775f 4372 7970 746f 2f53  b/AccHw_Crypto/S
00071bd0: 544d 3332 4637 2f4d 6964 646c 6577 6172  TM32F7/Middlewar
00071be0: 6573 2f53 542f 5354 4d33 325f 4372 7970  es/ST/STM32_Cryp
00071bf0: 746f 5f41 6363 4877 2f49 6e63 2f45 4343  to_AccHw/Inc/ECC
00071c00: 2f41 6363 4877 5f65 6363 2e68 0000 d0f0  /AccHw_ecc.h....
00071c10: ffff 9c00 0000 7061 7468 2f74 6f2f 782d  ......path/to/x-

See that the path for AccHw_rsa_pkcs1v15.h got split in two. This results in:

ninja explain: output /path/to/x-cube-cryptolib/AccHw_Crypto/STM32F7/Middlewares/ST/STM32_Crypto_AccHw/Inc/RSA/PKCS of phony edge with no inputs doesn't exist
ninja explain: /path/to/x-cube-cryptolib/AccHw_Crypto/STM32F7/Middlewares/ST/STM32_Crypto_AccHw/Inc/RSA/PKCS is dirty
ninja explain: output 1v15/AccHw_rsa_pkcs1v15.h of phony edge with no inputs doesn't exist
ninja explain: 1v15/AccHw_rsa_pkcs1v15.h is dirty
ninja explain: stored deps info out of date for '/path/to/CMakeFiles/main.dir/main.o' (6183390380015602 vs 6183390963740657)
ninja explain: /path/to/CMakeFiles/main.dir/main.o is dirty

Since neither of these paths exist, it rebuilds the target unnecessarily because it treats these missing files as dirty, which is incorrect. It's chopped a valid path in half to create two bogus dependencies.

The deps output is from the IAR C compiler.

Would it be possible to look at handling the # character in the DEPFILE input files a bit more robustly?

Many thanks, Roger

jhasse commented 3 years ago

Shouldn't # be escaped?

Also see #525, #1342, #1542, and #1774.