diff options
author | 2015-07-08 17:05:43 +0000 | |
---|---|---|
committer | 2015-07-10 17:15:18 +0000 | |
commit | 525019b7bd8810ef8401ecb80247fa4226eba8c2 (patch) | |
tree | b2002fade0c442cd1ac0eb0f0197926d8c0b5bab /src/main/java/com/google | |
parent | a5e5532dd3418a0c8018e7524efecdfc4402eee4 (diff) |
Tolerate "..." as the base filename for the fdo profile.
This is fragile, and there might be other places in the codebase this issue occurs.
--
MOS_MIGRATED_REVID=97784977
Diffstat (limited to 'src/main/java/com/google')
3 files changed, 21 insertions, 5 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java index 9d4818ef24..23ee8f9e94 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java @@ -34,6 +34,7 @@ import com.google.devtools.build.lib.packages.Target; import com.google.devtools.build.lib.packages.Type; import com.google.devtools.build.lib.syntax.Label; import com.google.devtools.build.lib.syntax.Label.SyntaxException; +import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig; @@ -150,6 +151,12 @@ public class CppConfigurationLoader implements ConfigurationFragmentFactory { } } else { fdoZip = directories.getWorkspace().getRelative(cppOptions.fdoOptimize); + try { + // We don't check for file existence, but at least the filename should be well-formed. + FileSystemUtils.checkBaseName(fdoZip.getBaseName()); + } catch (IllegalArgumentException e) { + throw new InvalidConfigurationException(e); + } } Label ccToolchainLabel; diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java index c960ef8912..a2339c2b2a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java @@ -222,12 +222,12 @@ public class FdoSupport { : Root.asDerivedRoot(execRoot, execRoot.getRelative("blaze-fdo")); this.fdoRootExecPath = fdoProfile == null ? null - : fdoRoot.getExecPath().getRelative(new PathFragment("_fdo").getChild( - FileSystemUtils.removeExtension(fdoProfile.getBaseName()))); + : fdoRoot.getExecPath().getRelative(FileSystemUtils.removeExtension( + new PathFragment("_fdo").getChild(fdoProfile.getBaseName()))); this.fdoPath = fdoProfile == null ? null - : new PathFragment("_fdo").getChild( - FileSystemUtils.removeExtension(fdoProfile.getBaseName())); + : FileSystemUtils.removeExtension(new PathFragment("_fdo").getChild( + fdoProfile.getBaseName())); this.lipoMode = lipoMode; this.useAutoFdo = fdoProfile != null && isAutoFdo(fdoProfile.getBaseName()); this.useLLVMFdo = fdoProfile != null && isLLVMFdo(fdoProfile.getBaseName()); diff --git a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java index 796d8286e2..6ce67aeac2 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java @@ -157,7 +157,10 @@ public class FileSystemUtils { * filename string. If the basename contains no '.', the filename is returned * unchanged. * - * e.g. "foo/bar.x" -> "foo/bar" + * <p>e.g. "foo/bar.x" -> "foo/bar" + * + * <p>Note that if the filename is composed entirely of ".", this method will return the string + * with one fewer ".", which may have surprising effects. */ @ThreadSafe public static String removeExtension(String filename) { @@ -176,6 +179,9 @@ public class FileSystemUtils { * unchanged. * * <p>e.g. "foo/bar.x" -> "foo/bar" + * + * <p>Note that if the base filename is composed entirely of ".", this method will return the + * filename with one fewer "." in the base filename, which may have surprising effects. */ @ThreadSafe public static PathFragment removeExtension(PathFragment path) { @@ -188,6 +194,9 @@ public class FileSystemUtils { * unchanged. * * <p>e.g. "foo/bar.x" -> "foo/bar" + * + * <p>Note that if the base filename is composed entirely of ".", this method will return the + * filename with one fewer "." in the base filename, which may have surprising effects. */ @ThreadSafe public static Path removeExtension(Path path) { |