Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 1 | // Copyright 2014 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | package com.google.devtools.build.lib.skyframe; |
| 15 | |
| 16 | import com.google.devtools.build.lib.vfs.ModifiedFileSet; |
| 17 | import com.google.devtools.build.lib.vfs.Path; |
| 18 | |
| 19 | import java.io.Closeable; |
| 20 | |
| 21 | import javax.annotation.Nullable; |
| 22 | |
| 23 | /** |
| 24 | * Interface for computing modifications of files under a package path entry. |
| 25 | * |
| 26 | * <p> Skyframe has a {@link DiffAwareness} instance per package-path entry, and each instance is |
| 27 | * responsible for all files under its path entry. At the beginning of each incremental build, |
| 28 | * skyframe queries for changes using {@link #getDiff}. Ideally, {@link #getDiff} should be |
| 29 | * constant-time; if it were linear in the number of files of interest, we might as well just |
| 30 | * detect modifications manually. |
| 31 | */ |
| 32 | public interface DiffAwareness extends Closeable { |
| 33 | |
| 34 | /** Factory for creating {@link DiffAwareness} instances. */ |
| 35 | public interface Factory { |
| 36 | /** |
| 37 | * Returns a {@link DiffAwareness} instance suitable for managing changes to files under the |
| 38 | * given package path entry, or {@code null} if this factory cannot create such an instance. |
| 39 | * |
| 40 | * <p> Skyframe has a collection of factories, and will create a {@link DiffAwareness} instance |
| 41 | * per package path entry using one of the factories that returns a non-null value. |
| 42 | */ |
| 43 | @Nullable |
| 44 | DiffAwareness maybeCreate(Path pathEntry); |
| 45 | } |
| 46 | |
| 47 | /** Opaque view of the filesystem under a package path entry at a specific point in time. */ |
| 48 | interface View { |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Returns the live view of the filesystem under the package path entry. |
| 53 | * |
| 54 | * @throws BrokenDiffAwarenessException if something is wrong and the caller should discard this |
| 55 | * {@link DiffAwareness} instance. The {@link DiffAwareness} is expected to close itself in |
| 56 | * this case. |
| 57 | */ |
| 58 | View getCurrentView() throws BrokenDiffAwarenessException; |
| 59 | |
| 60 | /** |
| 61 | * Returns the set of files of interest that have been modified between the given two views. |
| 62 | * |
| 63 | * <p>The given views must have come from previous calls to {@link #getCurrentView} on the |
| 64 | * {@link DiffAwareness} instance (i.e. using a {@link View} from another instance is not |
| 65 | * supported). |
| 66 | * |
| 67 | * @throws IncompatibleViewException if the given views are not compatible with this |
| 68 | * {@link DiffAwareness} instance. This probably indicates a bug. |
| 69 | * @throws BrokenDiffAwarenessException if something is wrong and the caller should discard this |
| 70 | * {@link DiffAwareness} instance. The {@link DiffAwareness} is expected to close itself in |
| 71 | * this case. |
| 72 | */ |
| 73 | ModifiedFileSet getDiff(View oldView, View newView) |
| 74 | throws IncompatibleViewException, BrokenDiffAwarenessException; |
| 75 | |
Michajlo Matijkiw | 0b09d28 | 2015-05-15 20:46:13 +0000 | [diff] [blame] | 76 | /** @return the name of this implementation */ |
| 77 | String name(); |
| 78 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 79 | /** |
| 80 | * Must be called whenever the {@link DiffAwareness} object is to be discarded. Using a |
| 81 | * {@link DiffAwareness} instance after calling {@link #close} on it is unspecified behavior. |
| 82 | */ |
| 83 | @Override |
| 84 | void close(); |
| 85 | } |