Branch libreoffice-5-0-4
[LibreOffice.git] / solenv / bin / bin_library_info.sh
blobbb93773492d7a886d3d319d1c5db352aeb68464d
1 #!/usr/bin/env bash
3 # Copyright (C) 2013 Norbert Thiebaud
4 # License: GPLv3
7 do_help()
9 cat <<EOF
10 bin_library_info.sh is a tool that create a unique filename for a binary tar file that
11 contain the build of the given source tarfile. the unicity is based on the source tarfile which contains
12 a md5 already and the calculated sha1 of config_host_.mk and of the tree object associated with the top_level_module
13 in git.
15 syntax: bin_library_info.sh -m|--module <top_level_module> -l|--location <TARFILE_LOCATION> -s|--srcdir <SRCDIR> -b <BUILDDIR> -r|--tarfile <LIBRARY_TARFILE> [ -m|--mode verify|name ]
17 the default mode is 'name' which just print the assocaited binary tarfile name.
18 in 'verify' mode the programe print the name if the assocaited binary tarfile exist
19 and print nothing and return an error code if the file does not exist
21 Note: --location --builddir and --srcdir are optional if they are already in the env in the form of TARFILE_LOCATION and BUILDDIR SRCDIR respectively
22 EOF
24 exit 0;
27 die()
29 [ $V ] && echo "Error:" "$@"
30 exit -1;
34 get_config_sha()
36 pushd ${SRCDIR?} > /dev/null
37 cat ${BUILDDIR?}/config_host.mk | git hash-object --stdin
38 popd > /dev/null
41 get_library_gbuild_sha()
43 local module="$1"
45 pushd ${SRCDIR?} > /dev/null
46 if [ -d "${SRCDIR}/external/${module?}" ] ; then
47 git ls-tree -d HEAD "external/${module?}" | cut -f 1 | cut -d " " -f 3
48 else
49 git ls-tree -d HEAD | "{module?}" | cut -f 1 | cut -d " " -f 3
51 popd > /dev/null
55 determine_binary_package_name()
57 local module="$1"
58 local tarball="$2"
59 local csha=""
60 local gsha=""
61 local binfile=""
63 csha=$(get_config_sha)
64 gsha=$(get_library_gbuild_sha "${module?}")
65 if [ -n "${csha?}" -a -n "${gsha}" ] ; then
66 binfile="${csha?}_${gsha?}_${tarball?}.${PLATFORM?}.tar.gz"
68 echo "${binfile}"
72 MODULE=""
73 SOURCE_TARFILE=""
74 MODE="name"
75 V=1
77 while [ "${1}" != "" ]; do
78 parm=${1%%=*}
79 arg=${1#*=}
80 has_arg=
81 if [ "${1}" != "${parm?}" ] ; then
82 has_arg=1
83 else
84 arg=""
87 case "${parm}" in
88 -h|--help) # display help
89 do_help
90 exit
92 -b|--builddir)
93 if [ -z "${has_arg}" ] ; then
94 shift;
95 arg="$1"
97 BUILDDIR="${arg}"
99 -o|--module)
100 if [ -z "${has_arg}" ] ; then
101 shift;
102 arg="$1"
104 MODULE="${arg}"
107 -l|--location)
108 if [ -z "${has_arg}" ] ; then
109 shift;
110 arg="$1"
112 TARFILE_LOCATION="${arg}"
114 -m|--mode)
115 # test if the binary package exist
116 if [ -z "${has_arg}" ] ; then
117 shift;
118 arg="$1"
120 MODE="$arg"
122 -p|--platform)
123 # test if the binary package exist
124 if [ -z "${has_arg}" ] ; then
125 shift;
126 arg="$1"
128 PLATFORM="$arg"
133 -s|--srcdir) # do not override the local autogen.lastrun if present
134 if [ -z "${has_arg}" ] ; then
135 shift;
136 arg="$1"
138 SRCDIR="${arg}"
141 -t|--tarfile)
142 if [ -z "${has_arg}" ] ; then
143 shift;
144 arg="$1"
146 SOURCE_TARFILE="${arg}"
149 die "Invalid option $1"
152 die "Invalid argument $1"
154 esac
155 shift
156 done
158 if [ -z "${MODULE?}" ] ; then
159 die "Missing --module"
161 if [ -z "${TARFILE_LOCATION}" ] ; then
162 die "Missing --location"
164 if [ -z "${SOURCE_TARFILE}" ] ; then
165 die "Missing --tarfile"
167 if [ -z "${SRCDIR}" ] ; then
168 die "Missing --srcdir"
172 BINARY_TARFILE="$(determine_binary_package_name ${MODULE?} ${SOURCE_TARFILE?})"
174 if [ -z "${BINARY_TARFILE}" ] ; then
175 exit 2
178 if [ "${MODE?}" = "verify" ] ; then
179 if [ -f "${TARFILE_LOCATION?}/${BINARY_TARFILE?}" ] ; then
180 echo "${BINARY_TARFILE?}"
181 else
182 exit 1
184 else
185 echo "${BINARY_TARFILE?}"
188 exit 0