Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 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 | |
Kristina Chodorow | 73fa203 | 2015-08-28 17:57:46 +0000 | [diff] [blame] | 16 | import com.google.devtools.build.lib.cmdline.PackageIdentifier; |
John Cater | 4593296 | 2017-09-06 21:57:46 +0200 | [diff] [blame] | 17 | import com.google.devtools.build.lib.skyframe.PackageLookupValue.IncorrectRepositoryReferencePackageLookupValue; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 18 | import com.google.devtools.build.lib.vfs.PathFragment; |
| 19 | import com.google.devtools.build.skyframe.SkyFunction; |
| 20 | import com.google.devtools.build.skyframe.SkyKey; |
| 21 | import com.google.devtools.build.skyframe.SkyValue; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 22 | import javax.annotation.Nullable; |
| 23 | |
| 24 | /** |
| 25 | * SkyFunction for {@link ContainingPackageLookupValue}s. |
| 26 | */ |
| 27 | public class ContainingPackageLookupFunction implements SkyFunction { |
| 28 | |
| 29 | @Override |
Janak Ramakrishnan | 3c0adb2 | 2016-08-15 21:54:55 +0000 | [diff] [blame] | 30 | public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 31 | PackageIdentifier dir = (PackageIdentifier) skyKey.argument(); |
Ulf Adams | 07dba94 | 2015-03-05 14:47:37 +0000 | [diff] [blame] | 32 | PackageLookupValue pkgLookupValue = |
| 33 | (PackageLookupValue) env.getValue(PackageLookupValue.key(dir)); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 34 | if (pkgLookupValue == null) { |
| 35 | return null; |
| 36 | } |
| 37 | |
| 38 | if (pkgLookupValue.packageExists()) { |
| 39 | return ContainingPackageLookupValue.withContainingPackage(dir, pkgLookupValue.getRoot()); |
| 40 | } |
| 41 | |
John Cater | 4593296 | 2017-09-06 21:57:46 +0200 | [diff] [blame] | 42 | // Does the requested package cross into a sub-repository, which we should report via the |
| 43 | // correct package identifier? |
| 44 | if (pkgLookupValue instanceof IncorrectRepositoryReferencePackageLookupValue) { |
| 45 | IncorrectRepositoryReferencePackageLookupValue incorrectPackageLookupValue = |
| 46 | (IncorrectRepositoryReferencePackageLookupValue) pkgLookupValue; |
| 47 | PackageIdentifier correctPackageIdentifier = |
| 48 | incorrectPackageLookupValue.getCorrectedPackageIdentifier(); |
| 49 | return env.getValue(ContainingPackageLookupValue.key(correctPackageIdentifier)); |
| 50 | } |
| 51 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 52 | PathFragment parentDir = dir.getPackageFragment().getParentDirectory(); |
| 53 | if (parentDir == null) { |
Michajlo Matijkiw | 1118459 | 2015-10-16 19:00:45 +0000 | [diff] [blame] | 54 | return ContainingPackageLookupValue.NONE; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 55 | } |
Miguel Alcon Pinto | 2627b9f | 2015-10-01 16:02:53 +0000 | [diff] [blame] | 56 | PackageIdentifier parentId = PackageIdentifier.create(dir.getRepository(), parentDir); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 57 | return env.getValue(ContainingPackageLookupValue.key(parentId)); |
| 58 | } |
| 59 | |
| 60 | @Nullable |
| 61 | @Override |
| 62 | public String extractTag(SkyKey skyKey) { |
| 63 | return null; |
| 64 | } |
| 65 | } |