Skip to content

Commit 781f4b2

Browse files
authored
[build] make dist-compatible log packages (#1993)
The "log packages" produced by `make package-build-status` (a2a970f) and `make package-test-errors` (0435a91) have one usability problem: they aren't compatible with [`make dist`][make-dist]. Specifically, `make dist`-style packages are packages which have a root directory that is the same as the basename of the package name. For example, if a package is named `foo.zip`, then the contents of `foo.zip` would all be within a `foo` directory. Additionally, `make dist`-style files usually have a "version number" of some form encoded in the filename, with `foo-1.zip` having all files within it nested under the `foo-1` directory. This has two wonderful benefits: 1. When downloading such files, they won't "collide" with each other, because they have unique values within the filename. 2. When extracting such files, the extracted contents won't collide with each other, as they're extracted into unique "toplevel" dirs. Compare to e.g. `make package-build-status`, which creates a `build-status-$(GIT_COMMIT).zip` file (thus fulfilling benefit (1)), but when you *extract* `build-status-$(GIT_COMMIT).zip`, it extracts "on top of" a previous extraction: $ unzip build-status-0636fcc.zip Archive: build-status-0636fcc.zip inflating: Configuration.OperatingSystem.props inflating: bin/BuildDebug/msbuild-20180716T144550-prepare-deps.binlog ... $ unzip build-status-0d81a6b7.zip Archive: build-status-0d81a6b7.zip replace Configuration.OperatingSystem.props? [y]es, [n]o, [A]ll, [N]one, [r]ename: # ARGH! This Is Madness™! Update the `make package-build-status` and `make package-test-errors` targets so that the files they produce are consistent with `make dist` convention, e.g. `make package-build-status` will create a file named `xa-build-status-vVERSION_OS-OS_ARCH_BRANCH_HASH.zip` -- which is consistent with the `make package-oss` filename -- and the *contents* of `xa-build-status-vVERSION_OS-OS_ARCH_BRANCH_HASH.zip` are within a `xa-build-status-vVERSION_OS-OS_ARCH_BRANCH_HASH` path. This allows these files to be extracted without overwriting previous extractions. Similarly, `make package-test-errors` will now create a file named `xa-test-errors-vVERSION_OS-OS_ARCH_BRANCH_HASH.zip`. [make-dist]: https://www.gnu.org/prep/standards/html_node/Standard-Targets.html
1 parent 90e3155 commit 781f4b2

File tree

2 files changed

+92
-6
lines changed

2 files changed

+92
-6
lines changed

build-tools/scripts/Packaging.mk

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ package-deb: $(ZIP_OUTPUT)
6363
cd $(ZIP_OUTPUT_BASENAME) && DEBEMAIL="Xamarin Public Jenkins (auto-signing) <[email protected]>" dch --create -v $(PRODUCT_VERSION).$(-num-commits-since-version-change) --package xamarin.android-oss --force-distribution --distribution alpha "New release - please see git log for $(GIT_COMMIT)"
6464
cd $(ZIP_OUTPUT_BASENAME) && dpkg-buildpackage -us -uc -rfakeroot
6565

66-
package-test-errors:
66+
_TEST_ERRORS_BASENAME = xa-test-errors-v$(PRODUCT_VERSION).$(-num-commits-since-version-change)_$(OS_NAME)-$(OS_ARCH)_$(GIT_BRANCH)_$(GIT_COMMIT)
67+
68+
"$(_TEST_ERRORS_BASENAME).zip" package-test-errors:
6769
ifneq ($(wildcard bin/Test*/temp),)
68-
zip -r test-errors.zip bin/Test*/temp
70+
build-tools/scripts/ln-to.sh -r . -o "$(_TEST_ERRORS_BASENAME)" bin/Test*/temp
71+
zip -r "$(_TEST_ERRORS_BASENAME).zip" "$(_TEST_ERRORS_BASENAME)"
6972
endif # We have test error output
7073

7174
_BUILD_STATUS_BUNDLE_INCLUDE = \
@@ -79,16 +82,18 @@ _BUILD_STATUS_BUNDLE_INCLUDE = \
7982
$(shell find . -name '.ninja_log') \
8083
$(shell find . -name 'android-*.config.cache')
8184

82-
_BUILD_STATUS_ZIP_OUTPUT = build-status-$(GIT_COMMIT).$(ZIP_EXTENSION)
85+
_BUILD_STATUS_BASENAME = xa-build-status-v$(PRODUCT_VERSION).$(-num-commits-since-version-change)_$(OS_NAME)-$(OS_ARCH)_$(GIT_BRANCH)_$(GIT_COMMIT)
86+
_BUILD_STATUS_ZIP_OUTPUT = $(_BUILD_STATUS_BASENAME).$(ZIP_EXTENSION)
8387

8488
ifneq ($(wildcard Configuration.Override.props),)
8589
_BUILD_STATUS_BUNDLE_INCLUDE += \
8690
Configuration.Override.props
8791
endif
8892

89-
package-build-status:
93+
"$(_BUILD_STATUS_ZIP_OUTPUT)" package-build-status:
94+
build-tools/scripts/ln-to.sh -r . -o "$(_BUILD_STATUS_BASENAME)" $(_BUILD_STATUS_BUNDLE_INCLUDE)
9095
ifeq ($(ZIP_EXTENSION),zip)
91-
zip -r "$(_BUILD_STATUS_ZIP_OUTPUT)" $(_BUILD_STATUS_BUNDLE_INCLUDE)
96+
zip -r "$(_BUILD_STATUS_ZIP_OUTPUT)" "$(_BUILD_STATUS_BASENAME)"
9297
else ifeq ($(ZIP_EXTENSION),tar.bz2)
93-
tar -cjhvf "$(_BUILD_STATUS_ZIP_OUTPUT)" $(_BUILD_STATUS_BUNDLE_INCLUDE)
98+
tar -cjhvf "$(_BUILD_STATUS_ZIP_OUTPUT)" "$(_BUILD_STATUS_BASENAME)"
9499
endif

build-tools/scripts/ln-to.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash -e
2+
3+
function Help()
4+
{
5+
echo "$0: usage: $0 -r ROOT_DIR -o OUT_DIR [FILE]+"
6+
exit 1
7+
}
8+
9+
function FullPath()
10+
{
11+
local p="$1"
12+
if [ -d "$p" ]; then
13+
echo "$(cd "$p" && pwd)"
14+
else
15+
d="`dirname "$p"`"
16+
echo "$(cd "$d" && pwd)/$(basename "$p")"
17+
fi
18+
}
19+
20+
function SubdirPath()
21+
{
22+
local root path subdir
23+
root="$1"
24+
path="$2"
25+
26+
if [ -d "$path" ]; then
27+
path="$(cd "$path" && pwd)"
28+
subdir="${path#$root}"
29+
echo "${subdir:-.}"
30+
else
31+
local b d
32+
d="$(dirname "$path")"
33+
b="$(basename "$path")"
34+
path="$(cd $d && pwd)"
35+
subdir="${path#$root}"
36+
echo "${subdir:-.}/$b"
37+
fi
38+
}
39+
40+
while getopts "o:r:" option ; do
41+
case "$option" in
42+
o)
43+
TARGET_DIR="$OPTARG"
44+
;;
45+
r)
46+
ROOT_DIR="$OPTARG"
47+
;;
48+
esac
49+
done
50+
51+
shift $(($OPTIND-1))
52+
53+
if [ -z "$TARGET_DIR" -o -z "$ROOT_DIR" ]; then
54+
echo "$0: missing required argument -o or -r" >&2
55+
Help
56+
fi
57+
58+
if [ ! -d "$ROOT_DIR" ]; then
59+
echo "$0: \"-r '$ROOT_DIR'\" must refer to a valid directory" 2>&2
60+
Help
61+
fi
62+
63+
mkdir -p "$TARGET_DIR"
64+
TARGET_DIR="$(cd "$TARGET_DIR" && pwd)"
65+
ROOT_DIR="$(cd "$ROOT_DIR" && pwd)"
66+
67+
for p in "$@" ; do
68+
if [ ! -e "$p" ]; then
69+
echo "$0: Skipping non-existent file '$p'" >&2
70+
continue
71+
fi
72+
full_path="$(FullPath "$p")"
73+
sub_path="$(SubdirPath "$ROOT_DIR" "$full_path")"
74+
target_sub="$TARGET_DIR/$(dirname "$sub_path")"
75+
target_path="$target_sub/$(basename "$p")"
76+
mkdir -p "$target_sub"
77+
if [ -f "$target_path" ]; then
78+
rm "$target_path"
79+
fi
80+
ln -s "$full_path" "$target_path"
81+
done

0 commit comments

Comments
 (0)