blob: f5f7e866b2f05a6380964063506c5efc87379320 [file] [log] [blame]
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01001// 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.
14package com.google.devtools.build.lib.skyframe;
15
16import com.google.devtools.build.lib.vfs.ModifiedFileSet;
17import com.google.devtools.build.lib.vfs.Path;
18
19import java.io.Closeable;
20
21import 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 */
32public 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 Matijkiw0b09d282015-05-15 20:46:13 +000076 /** @return the name of this implementation */
77 String name();
78
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010079 /**
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}