Rework stripping binaries when copying to containers

We now only attempt to strip binaries, by detecting the
LINKFLAGS variable on the targets.

CopySetHaikuRevision now also forwards LINKFLAGS
to revisioned binaries.

Introduce separate AppendToContainerCopyFilesScriptStripFile actions
which are used for copying and stripping, and avoids many useless
shell tests.

When asked to strip binaries, they are detected and handled
individually for simplicity.

Note we still don't keep resources and attributes when stripping.
This commit is contained in:
François Revol
2013-10-12 01:41:46 +02:00
parent e986f5fce9
commit e2332987bc
2 changed files with 36 additions and 15 deletions
+5
View File
@@ -341,6 +341,11 @@ rule CopySetHaikuRevision target : source
PropagateContainerUpdateTargetFlags $(target) : $(source) ; PropagateContainerUpdateTargetFlags $(target) : $(source) ;
if [ on $(source) return $(LINKFLAGS) ] {
# hint the target as a (strippable) binary
LINKFLAGS on $(target) = [ on $(source) return $(LINKFLAGS) ] ;
}
local revisionFile = [ DetermineHaikuRevision ] ; local revisionFile = [ DetermineHaikuRevision ] ;
Depends $(target) Depends $(target)
+28 -12
View File
@@ -676,24 +676,32 @@ rule CreateContainerCopyFilesScript container : script
# concurrent writes to the script file when building with multiple # concurrent writes to the script file when building with multiple
# jobs. # jobs.
local needStrip = [ on $(container)
return $(HAIKU_CONTAINER_STRIP_BINARIES) ] ;
# We are asked to strip the binaries when copying them.
local dir ; local dir ;
for dir in [ on $(container) return $(HAIKU_INSTALL_DIRECTORIES) ] { for dir in [ on $(container) return $(HAIKU_INSTALL_DIRECTORIES) ] {
# filter the targets that shall be renamed; they have to be copied # filter the targets that shall be renamed; they have to be copied
# individually # individually
# we also handle binary separately when asked to strip them
local destTargets = [ on $(dir) return $(TARGETS_TO_INSTALL) ] ; local destTargets = [ on $(dir) return $(TARGETS_TO_INSTALL) ] ;
local remainingTargets ; local remainingTargets ;
local destTarget ; local destTarget ;
for destTarget in $(destTargets) { for destTarget in $(destTargets) {
local target = [ on $(destTarget) return $(TARGET) ] ; local target = [ on $(destTarget) return $(TARGET) ] ;
local name = $(destTarget:G=) ; local name = $(destTarget:G=) ;
if $(name) != $(target:BS) { local isBinary = [ on $(target) return $(LINKFLAGS) ] ;
local doStrip ;
if $(needStrip) && $(isBinary) {
doStrip = 1 ;
}
if $(name) != $(target:BS) || $(doStrip) {
# use a unique dummy target for this file, on which we # use a unique dummy target for this file, on which we
# can define the TARGET_DIR variable # can define the TARGET_DIR variable
local dummyTarget = $(script)-dummy-$(dir:G=)-$(target) ; local dummyTarget = $(script)-dummy-$(dir:G=)-$(target) ;
NotFile $(dummyTarget) ; NotFile $(dummyTarget) ;
TARGET_DIR on $(dummyTarget) = $(dir:G=) ; TARGET_DIR on $(dummyTarget) = $(dir:G=) ;
DO_STRIP on $(dummyTarget) = [ on $(container)
return $(HAIKU_CONTAINER_STRIP_BINARIES) ] ;
local nameFunction local nameFunction
= [ on $(destTarget) return $(NAME_FUNCTION) ] ; = [ on $(destTarget) return $(NAME_FUNCTION) ] ;
@@ -709,8 +717,13 @@ rule CreateContainerCopyFilesScript container : script
Depends $(script) : $(dummyTarget) ; Depends $(script) : $(dummyTarget) ;
serializationDependency = $(dummyTarget) ; serializationDependency = $(dummyTarget) ;
if $(doStrip) {
AppendToContainerCopyFilesScriptStripFile $(dummyTarget)
: $(initScript) $(target) ;
} else {
AppendToContainerCopyFilesScriptSingleFile $(dummyTarget) AppendToContainerCopyFilesScriptSingleFile $(dummyTarget)
: $(initScript) $(target) ; : $(initScript) $(target) ;
}
} else { } else {
remainingTargets += $(target) ; remainingTargets += $(target) ;
} }
@@ -723,8 +736,6 @@ rule CreateContainerCopyFilesScript container : script
local dummyTarget = $(script)-dummy-$(dir:G=) ; local dummyTarget = $(script)-dummy-$(dir:G=) ;
NotFile $(dummyTarget) ; NotFile $(dummyTarget) ;
TARGET_DIR on $(dummyTarget) = $(dir:G=) ; TARGET_DIR on $(dummyTarget) = $(dir:G=) ;
DO_STRIP on $(dummyTarget) = [ on $(container)
return $(HAIKU_CONTAINER_STRIP_BINARIES) ] ;
Depends $(dummyTarget) : $(initScript) $(targets) Depends $(dummyTarget) : $(initScript) $(targets)
$(serializationDependency) ; $(serializationDependency) ;
@@ -767,11 +778,6 @@ actions piecemeal AppendToContainerCopyFilesScript bind OUTPUT_SCRIPT
{ {
echo \$cp "\"\${sPrefix}$(2)\"" "\"\${tPrefix}$(TARGET_DIR)\"" \ echo \$cp "\"\${sPrefix}$(2)\"" "\"\${tPrefix}$(TARGET_DIR)\"" \
>> $(OUTPUT_SCRIPT) >> $(OUTPUT_SCRIPT)
if [ -n "$(DO_STRIP:E)" ]; then
echo \$strip "\"\${tPrefix}$(TARGET_DIR)/$(2:BS)\"" "2>/dev/null" \
"|| true" >> $(OUTPUT_SCRIPT)
fi
} }
@@ -782,13 +788,23 @@ actions AppendToContainerCopyFilesScriptSingleFile
>> $(2[1]) >> $(2[1])
fi fi
echo \$cp "\"\${sPrefix}$(2[2])\"" \
"\"\${tPrefix}$(TARGET_DIR)/$(INSTALL_TARGET_NAME)\"" >> $(2[1])
}
actions AppendToContainerCopyFilesScriptStripFile
{
if [ -n "$(NAME_FUNCTION:E)" ]; then
echo "name=\`$(NAME_FUNCTION:E) \"$(2[2])\" 2> /dev/null \` || exit 1" \
>> $(2[1])
fi
echo \$cp "\"\${sPrefix}$(2[2])\"" \ echo \$cp "\"\${sPrefix}$(2[2])\"" \
"\"\${tPrefix}$(TARGET_DIR)/$(INSTALL_TARGET_NAME)\"" >> $(2[1]) "\"\${tPrefix}$(TARGET_DIR)/$(INSTALL_TARGET_NAME)\"" >> $(2[1])
if [ -n "$(DO_STRIP:E)" ]; then
echo \$strip "\"\${tPrefix}$(TARGET_DIR)/$(INSTALL_TARGET_NAME)\"" \ echo \$strip "\"\${tPrefix}$(TARGET_DIR)/$(INSTALL_TARGET_NAME)\"" \
"2>/dev/null" "|| true" >> $(2[1]) "2>/dev/null" "|| true" >> $(2[1])
fi
} }