forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If globbing throws an IOException, fail to construct the package inst…
…ead of constructing the package with an error. Prior to this change, if a Package.Builder object was constructed, it was guaranteed that a Package (possibly with errors) would be created. This is no longer true: if an IOException is set on the Package.Builder object, it will throw a NoSuchPackageException during #build(). PiperOrigin-RevId: 161832111
- Loading branch information
1 parent
5abf4ed
commit 28adce5
Showing
12 changed files
with
166 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/test/java/com/google/devtools/build/lib/analysis/AnalysisWithIOExceptionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2017 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package com.google.devtools.build.lib.analysis; | ||
|
||
import static org.junit.Assert.fail; | ||
|
||
import com.google.devtools.build.lib.analysis.util.AnalysisTestCase; | ||
import com.google.devtools.build.lib.util.BlazeClock; | ||
import com.google.devtools.build.lib.vfs.FileStatus; | ||
import com.google.devtools.build.lib.vfs.FileSystem; | ||
import com.google.devtools.build.lib.vfs.Path; | ||
import com.google.devtools.build.lib.vfs.PathFragment; | ||
import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; | ||
import java.io.IOException; | ||
import java.util.function.Function; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
/** {@link AnalysisTestCase} with custom filesystem that can throw on stat if desired. */ | ||
@RunWith(JUnit4.class) | ||
public class AnalysisWithIOExceptionsTest extends AnalysisTestCase { | ||
private static final String FS_ROOT = "/fsg"; | ||
|
||
private static final Function<Path, String> NULL_FUNCTION = (path) -> null; | ||
|
||
private Function<Path, String> crashMessage = NULL_FUNCTION; | ||
|
||
@Override | ||
protected FileSystem createFileSystem() { | ||
return new InMemoryFileSystem(BlazeClock.instance(), PathFragment.create(FS_ROOT)) { | ||
@Override | ||
public FileStatus stat(Path path, boolean followSymlinks) throws IOException { | ||
String crash = crashMessage.apply(path); | ||
if (crash != null) { | ||
throw new IOException(crash); | ||
} | ||
return super.stat(path, followSymlinks); | ||
} | ||
}; | ||
} | ||
|
||
@Test | ||
public void testGlobIOException() throws Exception { | ||
scratch.file("b/BUILD", "sh_library(name = 'b', deps= ['//a:a'])"); | ||
scratch.file("a/BUILD", "sh_library(name = 'a', srcs = glob(['a.sh']))"); | ||
crashMessage = path -> path.toString().contains("a.sh") ? "bork" : null; | ||
reporter.removeHandler(failFastHandler); | ||
try { | ||
update("//b:b"); | ||
fail("Expected failure"); | ||
} catch (ViewCreationFailedException expected) { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.