Skip to content

Commit

Permalink
build versions that aren't me making up numbers? via https://blog.twi…
Browse files Browse the repository at this point in the history
  • Loading branch information
mtigas committed Oct 11, 2018
1 parent 909c9ed commit 2a40c0d
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -18,6 +18,7 @@ fabric.apikey
fabric.buildsecret
Endless/DonationViewController.h
Endless/DonationViewController.m
OnionBrowser/version.h

geoip
geoip6
Expand Down
4 changes: 2 additions & 2 deletions Endless/Info.plist
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.1.990</string>
<string>OBBundleShortVersionString</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand All @@ -33,7 +33,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>20181010.01</string>
<string>OBBundleVersion</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationQueriesSchemes</key>
Expand Down
31 changes: 31 additions & 0 deletions OnionBrowser/build-util/decimalize_git_hash.bash
@@ -0,0 +1,31 @@
#!/bin/bash -euo pipefail
# https://blog.twitch.tv/ios-versioning-89e02f0a5146

if [ ${#} -eq 0 ]
then
# read from STDIN
MAYBE_GIT_HASH=$( cat )
else
MAYBE_GIT_HASH="${1}"
fi

LEGAL_GIT_HASH_CHARACTERS="0123456789ABCDEFabcdef"
# grep regex doesn't allow + metacharacter :(
HASH_GREP_REGEX='^['"${LEGAL_GIT_HASH_CHARACTERS}"']['"${LEGAL_GIT_HASH_CHARACTERS}"']*$'
GIT_HASH=$( echo "${MAYBE_GIT_HASH}" | grep "${HASH_GREP_REGEX}" ) || {
echo "\"${MAYBE_GIT_HASH}\" doesnt look like a git hash. A git hash should have only: \"${LEGAL_GIT_HASH_CHARACTERS}\"" >&2
exit 1
}

# We must prefix the git hash with a 1
# If it starts with a zero, when we decimalize it,
# and later hexify it, we'll lose the zero.
ONE_PREFIXED_GIT_HASH=1"${GIT_HASH}"

# bc requires hex to be uppercase because
# lowercase letters are reserved for bc variables
UPPERCASE_ONE_PREFIXED_GIT_HASH=$( echo "${ONE_PREFIXED_GIT_HASH}" | tr "[:lower:]" "[:upper:]" )

# convert to decimal
# See "with bc": http://stackoverflow.com/a/13280173/9636
echo "ibase=16;obase=A;${UPPERCASE_ONE_PREFIXED_GIT_HASH}" | bc
43 changes: 43 additions & 0 deletions OnionBrowser/build-util/decode_bundle_version.sh
@@ -0,0 +1,43 @@
#!/bin/bash -euo pipefail
# https://blog.twitch.tv/ios-versioning-89e02f0a5146

if [ ${#} -eq 0 ]
then
# read from STDIN
MAYBE_CFBUNDLEVERSION=$( cat )
else
MAYBE_CFBUNDLEVERSION="${1}"
fi

MAYBE_DECIMALIZED_MAYBE_ONE_PREFIXED_GIT_HASH=$( echo "${MAYBE_CFBUNDLEVERSION}" | sed 's/[0-9][0-9]*\.\([0-9][0-9]*\)/\1/' )

LEGAL_DECIMALIZED_GIT_HASH_CHARACTERS="0123456789"
# grep regex doesn't allow + metacharacter :(
DECIMALIZED_GREP_REGEX='^['"${LEGAL_DECIMALIZED_GIT_HASH_CHARACTERS}"']['"${LEGAL_DECIMALIZED_GIT_HASH_CHARACTERS}"']*$'
DECIMALIZED_MAYBE_ONE_PREFIXED_GIT_HASH=$( echo "${MAYBE_DECIMALIZED_MAYBE_ONE_PREFIXED_GIT_HASH}" | grep "${DECIMALIZED_GREP_REGEX}" ) || {
echo "\"${MAYBE_CFBUNDLEVERSION}\" doesnt look like a CFBundleVersion we expect. It should contain two dot-separated numbers." >&2
exit 1
}

# convert to hex
# http://stackoverflow.com/a/379422/9636
MAYBE_ONE_PREFIXED_GIT_HASH=$( echo "ibase=10;obase=16;${DECIMALIZED_MAYBE_ONE_PREFIXED_GIT_HASH}" | bc )

#grep doesn't allow + metacharacter. Thus match any one: (.) then any zero or more: (.*)
ONE_PREFIXED_GIT_HASH=$( echo "${MAYBE_ONE_PREFIXED_GIT_HASH}" | grep '^1..*$' ) || {
echo "\"${MAYBE_CFBUNDLEVERSION}\"'s second number, \"${MAYBE_DECIMALIZED_MAYBE_ONE_PREFIXED_GIT_HASH}\", is \"${MAYBE_ONE_PREFIXED_GIT_HASH}\" in hex, which didnt start with a \"1\"." >&2
exit 2
}

# Read ${ONE_PREFIXED_GIT_HASH} starting at position 1.
# See "Variable expansion / Substring replacement" in
# http://www.tldp.org/LDP/abs/html/parameter-substitution.html
UPPERCASED_GIT_HASH="${ONE_PREFIXED_GIT_HASH:1}"

# bc uses uppercase letters for hex because
# it reserves lowercase letters for variables
# but git hashes are written with lowercase letters
# so convert to lowercase to look more git-like
GIT_HASH=$( echo "${UPPERCASED_GIT_HASH}" | tr "[:upper:]" "[:lower:]" )

echo "${GIT_HASH}"
17 changes: 17 additions & 0 deletions OnionBrowser/build-util/minutes_since_date.bash
@@ -0,0 +1,17 @@
#!/bin/bash -euo pipefail
# https://blog.twitch.tv/ios-versioning-89e02f0a5146

if [ ${#} -eq 0 ]
then
# read from STDIN
DATE=$( cat )
else
DATE="${1}"
fi

SECONDS_FROM_EPOCH_TO_NOW=$( date "+%s" )
SECONDS_FROM_EPOCH_TO_DATE=$( date -j -f "%b %d %Y %T %Z" "${DATE}" "+%s" )

MINUTES_SINCE_DATE=$(( $(( ${SECONDS_FROM_EPOCH_TO_NOW}-${SECONDS_FROM_EPOCH_TO_DATE} ))/60 ))

echo "${MINUTES_SINCE_DATE}"
35 changes: 35 additions & 0 deletions OnionBrowser/build-util/mk_build_versions.sh
@@ -0,0 +1,35 @@
#!/bin/bash -euo pipefail
# https://blog.twitch.tv/ios-versioning-89e02f0a5146

# When we increment OB_BUNDLE_SHORT_VERSION_STRING
# also update OB_BUNDLE_SHORT_VERSION_DATE to the current date/time
# we don't have to be very exact, but it should be updated at least
# once every 18 months because iTunes requires that a CFBundleVersion
# be at most 18 characters long, and DECIMALIZED_GIT_HASH will be
# at most 10 characters long. Thus, MINUTES_SINCE_DATE needs to be
# at most 7 characters long so we can use the format:
# ${MINUTES_SINCE_DATE}.${DECIMALIZED_GIT_HASH}
#
OB_BUNDLE_SHORT_VERSION_DATE="October 9 2018 00:00:00 GMT"
OB_BUNDLE_SHORT_VERSION_STRING=2.1.990

BASH_SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

MINUTES_SINCE_DATE="$( cd "${BASH_SOURCE_DIR}" && ./minutes_since_date.bash "${OB_BUNDLE_SHORT_VERSION_DATE}" )"

# decimalized git hash is guaranteed to be 10 characters or fewer because
# the biggest short=7 git hash we can get is FFFFFFF and
# $ ./decimalize_git_hash.bash FFFFFFF | wc -c
# > 10
DECIMALIZED_GIT_HASH="$( cd "${BASH_SOURCE_DIR}"; ./decimalize_git_hash.bash $( git rev-parse --short=7 HEAD ) )"
echo "Decimalized: \"${DECIMALIZED_GIT_HASH}\""

OB_BUNDLE_VERSION="${MINUTES_SINCE_DATE}"."${DECIMALIZED_GIT_HASH}"

echo $OB_BUNDLE_SHORT_VERSION_STRING
echo $OB_BUNDLE_VERSION

cat <<EOF > "${SRCROOT}"/OnionBrowser/version.h
#define OBBundleShortVersionString ${OB_BUNDLE_SHORT_VERSION_STRING}
#define OBBundleVersion ${OB_BUNDLE_VERSION}
EOF
78 changes: 78 additions & 0 deletions OnionBrowser2.xcodeproj/project.pbxproj
Expand Up @@ -6,6 +6,20 @@
objectVersion = 46;
objects = {

/* Begin PBXAggregateTarget section */
8AC3B3A721700AD300E0CB4A /* OBVersion */ = {
isa = PBXAggregateTarget;
buildConfigurationList = 8AC3B3A821700AD300E0CB4A /* Build configuration list for PBXAggregateTarget "OBVersion" */;
buildPhases = (
8A3EBA9221700AE80054A9FF /* ShellScript */,
);
dependencies = (
);
name = OBVersion;
productName = OBVersion;
};
/* End PBXAggregateTarget section */

/* Begin PBXBuildFile section */
010EEA661A43A536001E8B65 /* CookieController.m in Sources */ = {isa = PBXBuildFile; fileRef = 010EEA651A43A536001E8B65 /* CookieController.m */; };
010EEA691A43C8CF001E8B65 /* CookieJar.m in Sources */ = {isa = PBXBuildFile; fileRef = 010EEA681A43C8CF001E8B65 /* CookieJar.m */; };
Expand Down Expand Up @@ -93,6 +107,13 @@
remoteGlobalIDString = 01801E911A32CA2A002B4718;
remoteInfo = Endless;
};
8A3EBA9321700B0A0054A9FF /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 01801E8A1A32CA2A002B4718 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 8AC3B3A721700AD300E0CB4A;
remoteInfo = OBVersion;
};
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -214,6 +235,7 @@
8A3F82F2201904100088F205 /* fa */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fa; path = Endless/fa.lproj/OnePasswordExtension.strings; sourceTree = "<group>"; };
8A3F82F3201904170088F205 /* is */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = is; path = Endless/is.lproj/OnePasswordExtension.strings; sourceTree = "<group>"; };
8A3F82F42019041E0088F205 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "Endless/zh-Hans.lproj/OnePasswordExtension.strings"; sourceTree = "<group>"; };
8AC3B3A621700A9D00E0CB4A /* version.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = version.h; path = OnionBrowser/version.h; sourceTree = "<group>"; };
8ACB70CE1FA1369A001E5588 /* Iobfs4proxy.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Iobfs4proxy.framework; path = Carthage/Build/iOS/Iobfs4proxy.framework; sourceTree = "<group>"; };
8ACB70D01FA136F0001E5588 /* geoip */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = geoip; sourceTree = "<group>"; };
8ACB70D11FA136F0001E5588 /* geoip6 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = geoip6; sourceTree = "<group>"; };
Expand Down Expand Up @@ -592,6 +614,7 @@
8AD5FFB91EB3DFE30066E7E3 /* ObfsThread.m */,
8AD1283B1ED61812005C43E4 /* Ipv6Tester.h */,
8AD1283C1ED61812005C43E4 /* Ipv6Tester.m */,
8AC3B3A621700A9D00E0CB4A /* version.h */,
8AD128411ED6182A005C43E4 /* ThirdParty */,
8ACB70CE1FA1369A001E5588 /* Iobfs4proxy.framework */,
);
Expand Down Expand Up @@ -916,6 +939,7 @@
buildRules = (
);
dependencies = (
8A3EBA9421700B0A0054A9FF /* PBXTargetDependency */,
);
name = OnionBrowser2;
productName = Endless;
Expand Down Expand Up @@ -968,6 +992,10 @@
CreatedOnToolsVersion = 6.1.1;
TestTargetID = 01801E911A32CA2A002B4718;
};
8AC3B3A721700AD300E0CB4A = {
CreatedOnToolsVersion = 10.0;
ProvisioningStyle = Automatic;
};
};
};
buildConfigurationList = 01801E8D1A32CA2A002B4718 /* Build configuration list for PBXProject "OnionBrowser2" */;
Expand Down Expand Up @@ -1008,6 +1036,7 @@
targets = (
01801E911A32CA2A002B4718 /* OnionBrowser2 */,
018333D61A35727C00670CD1 /* OnionBrowser2 Tests */,
8AC3B3A721700AD300E0CB4A /* OBVersion */,
);
};
/* End PBXProject section */
Expand Down Expand Up @@ -1171,6 +1200,23 @@
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-OnionBrowser2/Pods-OnionBrowser2-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
8A3EBA9221700AE80054A9FF /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"$SRCROOT\"/OnionBrowser/build-util/mk_build_versions.sh\n";
};
8ACB70CD1FA13676001E5588 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -1275,6 +1321,11 @@
target = 01801E911A32CA2A002B4718 /* OnionBrowser2 */;
targetProxy = 018333DD1A35727C00670CD1 /* PBXContainerItemProxy */;
};
8A3EBA9421700B0A0054A9FF /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 8AC3B3A721700AD300E0CB4A /* OBVersion */;
targetProxy = 8A3EBA9321700B0A0054A9FF /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
Expand Down Expand Up @@ -1422,6 +1473,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_PREPROCESS = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -1470,6 +1522,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_PREPROCESS = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -1596,6 +1649,22 @@
};
name = Release;
};
8AC3B3A921700AD300E0CB4A /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
};
8AC3B3AA21700AD300E0CB4A /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
Expand Down Expand Up @@ -1626,6 +1695,15 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
8AC3B3A821700AD300E0CB4A /* Build configuration list for PBXAggregateTarget "OBVersion" */ = {
isa = XCConfigurationList;
buildConfigurations = (
8AC3B3A921700AD300E0CB4A /* Debug */,
8AC3B3AA21700AD300E0CB4A /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 01801E8A1A32CA2A002B4718 /* Project object */;
Expand Down

0 comments on commit 2a40c0d

Please sign in to comment.