Chromium Code Reviews| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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. |
| 121 */ | 121 */ |
| 122 final String genfiles; | 122 final String genfiles; |
| 123 | 123 |
| 124 /** | |
| 125 * Create a new Bazel workspace that contains the given [path]. | |
| 126 * | |
| 127 * The [symlinkPrefix] is the prefix for names of symlinks like `bazel-bin`, | |
| 128 * `bazel-genfiles`, etc. | |
| 129 */ | |
| 130 factory BazelWorkspace(ResourceProvider provider, String path, | |
| 131 {String symlinkPrefix: 'bazel', String readonlySuffix}) { | |
| 132 Context context = provider.pathContext; | |
| 133 | |
| 134 // Ensure that the path is absolute and normalized. | |
| 135 if (!context.isAbsolute(path)) { | |
| 136 throw new ArgumentError('not absolute: $path'); | |
| 137 } | |
| 138 path = context.normalize(path); | |
| 139 | |
| 140 Folder folder = provider.getFolder(path); | |
| 141 while (true) { | |
| 142 Folder parent = folder.parent; | |
| 143 | |
| 144 // Found the READONLY folder, must be a git-based workspace. | |
| 145 if (readonlySuffix != null && parent != null) { | |
| 146 Folder readonlyFolder = parent.getChildAssumingFolder(_READONLY); | |
| 147 if (readonlyFolder.exists) { | |
| 148 String root = folder.path; | |
| 149 String readonly = readonlyFolder.path; | |
| 150 return new BazelWorkspace._( | |
| 151 provider, | |
| 152 root, | |
| 153 context.join(readonly, readonlySuffix), | |
| 154 context.join(root, '$symlinkPrefix-bin'), | |
| 155 context.join(root, '$symlinkPrefix-genfiles')); | |
| 156 } | |
| 157 } | |
| 158 | |
| 159 // Found the WORKSPACE file, must be a non-git workspace. | |
| 160 if (folder.getChildAssumingFile(_WORKSPACE).exists) { | |
| 161 String root = folder.path; | |
| 162 return new BazelWorkspace._( | |
| 163 provider, | |
| 164 root, | |
| 165 null, | |
| 166 context.join(root, '$symlinkPrefix-bin'), | |
| 167 context.join(root, '$symlinkPrefix-genfiles')); | |
| 168 } | |
| 169 | |
| 170 // Go up the folder. | |
| 171 folder = parent; | |
| 172 if (folder == null) { | |
| 173 return new BazelWorkspace._(provider, path, null, null, null); | |
| 174 } | |
| 175 } | |
| 176 } | |
| 177 | |
| 178 BazelWorkspace._( | 124 BazelWorkspace._( |
| 179 this.provider, this.root, this.readonly, this.bin, this.genfiles); | 125 this.provider, this.root, this.readonly, this.bin, this.genfiles); |
| 180 | 126 |
| 181 /** | 127 /** |
| 182 * Return the file with the given [absolutePath], looking first into | 128 * Return the file with the given [absolutePath], looking first into |
| 183 * directories for generated files: `bazel-genfiles` and `bazel-bin`, and | 129 * directories for generated files: `bazel-bin` and `bazel-genfiles`, and |
| 184 * then into the workspace root. The file in the workspace root is returned | 130 * then into the workspace root. The file in the workspace root is returned |
| 185 * even if it does not exist. Return `null` if the given [absolutePath] is | 131 * even if it does not exist. Return `null` if the given [absolutePath] is |
| 186 * not in the workspace [root]. | 132 * not in the workspace [root]. |
| 187 */ | 133 */ |
| 188 File findFile(String absolutePath) { | 134 File findFile(String absolutePath) { |
| 189 Context context = provider.pathContext; | 135 Context context = provider.pathContext; |
| 190 try { | 136 try { |
| 191 String relative = context.relative(absolutePath, from: root); | 137 String relative = context.relative(absolutePath, from: root); |
| 192 // genfiles | 138 // genfiles |
| 193 if (genfiles != null) { | 139 if (genfiles != null) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 217 } | 163 } |
| 218 } | 164 } |
| 219 | 165 |
| 220 /** | 166 /** |
| 221 * Return the file for the given [pathInWorkspace]. The file is returned even | 167 * Return the file for the given [pathInWorkspace]. The file is returned even |
| 222 * if it does not exist. | 168 * if it does not exist. |
| 223 */ | 169 */ |
| 224 File getFile(String pathInWorkspace) { | 170 File getFile(String pathInWorkspace) { |
| 225 return provider.getFile(provider.pathContext.join(root, pathInWorkspace)); | 171 return provider.getFile(provider.pathContext.join(root, pathInWorkspace)); |
| 226 } | 172 } |
| 173 | |
| 174 /** | |
| 175 * Find the Bazel workspace that contains the given [path]. | |
| 176 * | |
| 177 * The [symlinkPrefix] is the prefix for names of symlinks like `bazel-bin`, | |
| 178 * `bazel-genfiles`, etc. | |
| 179 */ | |
|
Paul Berry
2016/10/07 17:08:36
Can you add a line to the doc comment explaining w
scheglov
2016/10/07 17:15:56
Done.
| |
| 180 static BazelWorkspace find(ResourceProvider provider, String path, | |
| 181 {String symlinkPrefix: 'bazel', String readonlySuffix}) { | |
| 182 Context context = provider.pathContext; | |
| 183 | |
| 184 // Ensure that the path is absolute and normalized. | |
| 185 if (!context.isAbsolute(path)) { | |
| 186 throw new ArgumentError('not absolute: $path'); | |
| 187 } | |
| 188 path = context.normalize(path); | |
| 189 | |
| 190 Folder folder = provider.getFolder(path); | |
| 191 while (true) { | |
| 192 Folder parent = folder.parent; | |
| 193 if (parent == null) { | |
| 194 return null; | |
| 195 } | |
| 196 | |
| 197 // Found the READONLY folder, must be a git-based workspace. | |
| 198 if (readonlySuffix != null && parent != null) { | |
|
Paul Berry
2016/10/07 17:08:36
You can drop `&& parent != null` from this line be
scheglov
2016/10/07 17:15:56
Done.
| |
| 199 Folder readonlyFolder = parent.getChildAssumingFolder(_READONLY); | |
| 200 if (readonlyFolder.exists) { | |
| 201 String root = folder.path; | |
| 202 String readonly = readonlyFolder.path; | |
| 203 return new BazelWorkspace._( | |
| 204 provider, | |
| 205 root, | |
| 206 context.join(readonly, readonlySuffix), | |
| 207 context.join(root, '$symlinkPrefix-bin'), | |
| 208 context.join(root, '$symlinkPrefix-genfiles')); | |
| 209 } | |
| 210 } | |
| 211 | |
| 212 // Found the WORKSPACE file, must be a non-git workspace. | |
| 213 if (folder.getChildAssumingFile(_WORKSPACE).exists) { | |
| 214 String root = folder.path; | |
| 215 return new BazelWorkspace._( | |
| 216 provider, | |
| 217 root, | |
| 218 null, | |
| 219 context.join(root, '$symlinkPrefix-bin'), | |
| 220 context.join(root, '$symlinkPrefix-genfiles')); | |
| 221 } | |
| 222 | |
| 223 // Go up the folder. | |
| 224 folder = parent; | |
| 225 } | |
| 226 } | |
| 227 } | 227 } |
| OLD | NEW |