From 0540fdefe2c27605516a772c2a224d579db0a74d Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 27 May 2015 15:12:01 +0000 Subject: Extract version numbers that look like "..._1.2.3_..." from BUILD_EMBED_LABEL into Info.plist. -- MOS_MIGRATED_REVID=94572729 --- .../build/lib/rules/objc/ReleaseBundlingSupport.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/main/java/com/google/devtools/build/lib') diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java index 289b3b9379..975600f5ca 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java @@ -87,6 +87,18 @@ public final class ReleaseBundlingSupport { @VisibleForTesting static final String EXTENSION_BUNDLE_DIR_FORMAT = "PlugIns/%s.appex"; + /** + * Command string for "sed" that tries to extract the application version number from a larger + * string. For example, from "foo_1.2.3_RC00" this would extract "1.2.3". This regex looks for + * versions of the format "x.y" or "x.y.z", which may be preceded and/or followed by other text, + * such as a project name or release candidate number. + * + *

This command also preserves double quotes around the string, if any. + */ + private static final String EXTRACT_VERSION_NUMBER_SED_COMMAND = + "s#\\(\"\\)\\{0,1\\}\\(.*_\\)\\{0,1\\}\\([0-9][0-9]*\\(\\.[0-9][0-9]*\\)\\{1,2\\}\\)" + + "\\(_[^\"]*\\)\\{0,1\\}\\(\"\\)\\{0,1\\}#\\1\\3\\6#"; + private final Attributes attributes; private final BundleSupport bundleSupport; private final RuleContext ruleContext; @@ -224,7 +236,8 @@ public final class ReleaseBundlingSupport { .add( "VERSION=\"$(" + "grep \"^" + BuildInfo.BUILD_EMBED_LABEL + "\" " + buildInfo.getExecPathString() - + " | cut -d' ' -f2- | sed -e 's#\"#\\\"#g')\" && " + + " | cut -d' ' -f2- | sed -e '" + EXTRACT_VERSION_NUMBER_SED_COMMAND + "' | " + + "sed -e 's#\"#\\\"#g')\" && " + "cat >" + getGeneratedVersionPlist().getExecPathString() + " <\n" + "