| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.src.generated.bazel; | 5 library analyzer.src.generated.bazel; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:core'; | 8 import 'dart:core'; |
| 9 | 9 |
| 10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 99 |
| 100 /** | 100 /** |
| 101 * The absolute workspace root path. | 101 * The absolute workspace root path. |
| 102 * | 102 * |
| 103 * It contains the `WORKSPACE` file or its parent contains the `READONLY` | 103 * It contains the `WORKSPACE` file or its parent contains the `READONLY` |
| 104 * folder. | 104 * folder. |
| 105 */ | 105 */ |
| 106 final String root; | 106 final String root; |
| 107 | 107 |
| 108 /** | 108 /** |
| 109 * The absolute path to the optional `READONLY` folder if a git-based | 109 * The absolute path to the optional read only workspace root, in the |
| 110 * workspace, or `null`. | 110 * `READONLY` folder if a git-based workspace, or `null`. |
| 111 */ | 111 */ |
| 112 final String readonly; | 112 final String readonly; |
| 113 | 113 |
| 114 /** | 114 /** |
| 115 * The absolute path to the `bazel-bin` folder. | 115 * The absolute path to the `bazel-bin` folder. |
| 116 */ | 116 */ |
| 117 final String bin; | 117 final String bin; |
| 118 | 118 |
| 119 /** | 119 /** |
| 120 * The absolute path to the `bazel-genfiles` folder. | 120 * The absolute path to the `bazel-genfiles` folder. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 172 } |
| 173 | 173 |
| 174 /** | 174 /** |
| 175 * Find the Bazel workspace that contains the given [path]. | 175 * Find the Bazel workspace that contains the given [path]. |
| 176 * | 176 * |
| 177 * Return `null` if a workspace markers, such as the `WORKSPACE` file, or | 177 * Return `null` if a workspace markers, such as the `WORKSPACE` file, or |
| 178 * the sibling `READONLY` folder cannot be found. | 178 * the sibling `READONLY` folder cannot be found. |
| 179 * | 179 * |
| 180 * Return `null` if the workspace does not have `bazel-genfiles` or | 180 * Return `null` if the workspace does not have `bazel-genfiles` or |
| 181 * `blaze-genfiles` folders, so we don't know where to search generated files. | 181 * `blaze-genfiles` folders, so we don't know where to search generated files. |
| 182 * |
| 183 * Return `null` if there is a folder 'foo' with the sibling `READONLY` |
| 184 * folder, but there is corresponding folder 'foo' in `READONLY`, i.e. the |
| 185 * corresponding readonly workspace root. |
| 182 */ | 186 */ |
| 183 static BazelWorkspace find(ResourceProvider provider, String path, | 187 static BazelWorkspace find(ResourceProvider provider, String path) { |
| 184 {String readonlySuffix}) { | |
| 185 Context context = provider.pathContext; | 188 Context context = provider.pathContext; |
| 186 | 189 |
| 187 // Ensure that the path is absolute and normalized. | 190 // Ensure that the path is absolute and normalized. |
| 188 if (!context.isAbsolute(path)) { | 191 if (!context.isAbsolute(path)) { |
| 189 throw new ArgumentError('not absolute: $path'); | 192 throw new ArgumentError('not absolute: $path'); |
| 190 } | 193 } |
| 191 path = context.normalize(path); | 194 path = context.normalize(path); |
| 192 | 195 |
| 193 Folder folder = provider.getFolder(path); | 196 Folder folder = provider.getFolder(path); |
| 194 while (true) { | 197 while (true) { |
| 195 Folder parent = folder.parent; | 198 Folder parent = folder.parent; |
| 196 if (parent == null) { | 199 if (parent == null) { |
| 197 return null; | 200 return null; |
| 198 } | 201 } |
| 199 | 202 |
| 200 // Found the READONLY folder, must be a git-based workspace. | 203 // Found the READONLY folder, might be a git-based workspace. |
| 201 if (readonlySuffix != null) { | 204 Folder readonlyFolder = parent.getChildAssumingFolder(_READONLY); |
| 202 Folder readonlyFolder = parent.getChildAssumingFolder(_READONLY); | 205 if (readonlyFolder.exists) { |
| 203 if (readonlyFolder.exists) { | 206 String root = folder.path; |
| 204 String root = folder.path; | 207 String readonlyRoot = |
| 205 String readonly = readonlyFolder.path; | 208 context.join(readonlyFolder.path, folder.shortName); |
| 209 if (provider.getFolder(readonlyRoot).exists) { |
| 206 String symlinkPrefix = _findSymlinkPrefix(provider, root); | 210 String symlinkPrefix = _findSymlinkPrefix(provider, root); |
| 207 if (symlinkPrefix == null) { | 211 if (symlinkPrefix != null) { |
| 208 return null; | 212 return new BazelWorkspace._( |
| 213 provider, |
| 214 root, |
| 215 readonlyRoot, |
| 216 context.join(root, '$symlinkPrefix-bin'), |
| 217 context.join(root, '$symlinkPrefix-genfiles')); |
| 209 } | 218 } |
| 210 return new BazelWorkspace._( | |
| 211 provider, | |
| 212 root, | |
| 213 context.join(readonly, readonlySuffix), | |
| 214 context.join(root, '$symlinkPrefix-bin'), | |
| 215 context.join(root, '$symlinkPrefix-genfiles')); | |
| 216 } | 219 } |
| 217 } | 220 } |
| 218 | 221 |
| 219 // Found the WORKSPACE file, must be a non-git workspace. | 222 // Found the WORKSPACE file, must be a non-git workspace. |
| 220 if (folder.getChildAssumingFile(_WORKSPACE).exists) { | 223 if (folder.getChildAssumingFile(_WORKSPACE).exists) { |
| 221 String root = folder.path; | 224 String root = folder.path; |
| 222 String symlinkPrefix = _findSymlinkPrefix(provider, root); | 225 String symlinkPrefix = _findSymlinkPrefix(provider, root); |
| 223 if (symlinkPrefix == null) { | 226 if (symlinkPrefix == null) { |
| 224 return null; | 227 return null; |
| 225 } | 228 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 245 Context context = provider.pathContext; | 248 Context context = provider.pathContext; |
| 246 if (provider.getFolder(context.join(root, 'blaze-genfiles')).exists) { | 249 if (provider.getFolder(context.join(root, 'blaze-genfiles')).exists) { |
| 247 return 'blaze'; | 250 return 'blaze'; |
| 248 } | 251 } |
| 249 if (provider.getFolder(context.join(root, 'bazel-genfiles')).exists) { | 252 if (provider.getFolder(context.join(root, 'bazel-genfiles')).exists) { |
| 250 return 'bazel'; | 253 return 'bazel'; |
| 251 } | 254 } |
| 252 return null; | 255 return null; |
| 253 } | 256 } |
| 254 } | 257 } |
| OLD | NEW |