Remove destination before copying file

If there's a symlink as the destination to one of these macros,
currently we'll write to the destination of that symlink instead of
overwriting the symlink. We've run into this a few times when a module
is added to replace a symlink that used to exist via
LOCAL_POST_INSTALL_CMD. These have required manual discovery, and
additions to CleanSpec.mk files:
http://android-review.googlesource.com/143334

Use `rm -f` for single-file targets to remove the destination before
copying. On Linux, `cp --remove-destination` can work, but is not
supported by Darwin or acp.

There may still be problems with dependencies when symlinks are
involved, since ninja will use the destination of the symlink to check
whether it is up to date. But at least with this change, if any
dependency gets regenerated, we'll properly reset the file.

Change-Id: I6d3ac0bd9ced5e21a0ff9dad0eaff012a7bc9c75
This commit is contained in:
Dan Willemsen 2016-02-29 12:45:18 -08:00
parent b044f082e6
commit 3545eeb6c1
1 changed files with 10 additions and 4 deletions

View File

@ -2404,19 +2404,22 @@ endef
# Therefore copy-file-to-target is the same as copy-file-to-new-target. # Therefore copy-file-to-target is the same as copy-file-to-new-target.
define copy-file-to-target define copy-file-to-target
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
$(hide) $(ACP) -fp $< $@ $(hide) rm -f $@
$(hide) $(ACP) -p $< $@
endef endef
# The same as copy-file-to-target, but use the local # The same as copy-file-to-target, but use the local
# cp command instead of acp. # cp command instead of acp.
define copy-file-to-target-with-cp define copy-file-to-target-with-cp
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
$(hide) cp -fp $< $@ $(hide) rm -f $@
$(hide) cp -p $< $@
endef endef
# The same as copy-file-to-target, but use the zipalign tool to do so. # The same as copy-file-to-target, but use the zipalign tool to do so.
define copy-file-to-target-with-zipalign define copy-file-to-target-with-zipalign
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
$(hide) rm -f $@
$(hide) $(ZIPALIGN) -f 4 $< $@ $(hide) $(ZIPALIGN) -f 4 $< $@
endef endef
@ -2424,6 +2427,7 @@ endef
# comments (for config files and such). # comments (for config files and such).
define copy-file-to-target-strip-comments define copy-file-to-target-strip-comments
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
$(hide) rm -f $@
$(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@ $(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@
endef endef
@ -2431,14 +2435,16 @@ endef
# the old modification time. # the old modification time.
define copy-file-to-new-target define copy-file-to-new-target
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
$(hide) $(ACP) -fp $< $@ $(hide) rm -f $@
$(hide) $(ACP) -p $< $@
endef endef
# The same as copy-file-to-new-target, but use the local # The same as copy-file-to-new-target, but use the local
# cp command instead of acp. # cp command instead of acp.
define copy-file-to-new-target-with-cp define copy-file-to-new-target-with-cp
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
$(hide) cp -f $< $@ $(hide) rm -f $@
$(hide) cp $< $@
endef endef
# Copy a prebuilt file to a target location. # Copy a prebuilt file to a target location.