dart-lang / sdk

The Dart SDK, including the VM, dart2js, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
9.95k stars 1.53k forks source link

[analyzer] custom analyze-plugin do not support modifying the pub host #49265

Open mengdouer opened 2 years ago

mengdouer commented 2 years ago

when i customize the analyze-plugin,bootstrap package.The yaml file in the bootstrap package needs to contain the host package.The company maintains a pub internally. The PUB_HOSTED_URL environment variable is modified, but it is found that bootstrap still only reads dependencies from the outside.The error stack is below, I want to know if there is something wrong with my usage

Failed to run pub upgrade pluginFolder = /Users/zzm/.dartServer/.plugin_manager/31278c5bbbb86f9fef098954e641b96f/analyzer_plugin exitCode = 69 stdout = Resolving dependencies...

stderr = Because test_plugin_bootstrap depends on bd_test_plugin any which doesn't exist (could not find package bd_test_plugin at https://pub.dartlang.org), version solving failed.

#0      PluginManager._computeFiles (package:analysis_server/src/plugin/plugin_manager.dart:670:7)
#1      PluginManager.filesFor (package:analysis_server/src/plugin/plugin_manager.dart:462:14)
#2      PluginManager.addPluginToContextRoot (package:analysis_server/src/plugin/plugin_manager.dart:328:23)
#3      PluginWatcher.addedDriver (package:analysis_server/src/plugin/plugin_watcher.dart:68:19)
#4      AnalysisDriver.configure (package:analyzer/src/dart/analysis/driver.dart:558:33)
#5      ContextBuilderImpl.createContext (package:analyzer/src/dart/analysis/context_builder.dart:141:12)
#6      new AnalysisContextCollectionImpl (package:analyzer/src/dart/analysis/analysis_context_collection.dart:75:36)
#7      ContextManagerImpl._createAnalysisContexts.performContextRebuildGuarded.performContextRebuild (package:analysis_server/src/context_manager.dart:447:40)
#8      ContextManagerImpl._createAnalysisContexts.performContextRebuildGuarded.performContextRebuild (package:analysis_server/src/context_manager.dart:442:41)
#9      ContextManagerImpl._createAnalysisContexts.performContextRebuildGuarded (package:analysis_server/src/context_manager.dart:566:17)
#10     ContextManagerImpl.setRoots (package:analysis_server/src/context_manager.dart:278:5)
#11     AnalysisServer.setAnalysisRoots (package:analysis_server/src/analysis_server.dart:603:7)
#12     AnalysisSetAnalysisRootsHandler.handle (package:analysis_server/src/handler/legacy/analysis_set_analysis_roots.dart:47:7)
bwilkerson commented 2 years ago

@jonasfj At first glance, this sounds more like a pub issue.

In case it helps, the invocation of pub is here: https://github.com/dart-lang/sdk/blob/main/pkg/analysis_server/lib/src/plugin/plugin_manager.dart#L636.

pq commented 2 years ago

@bwilkerson: do you feel we could do better error-reporting here?

bwilkerson commented 2 years ago

I don't know because I don't understand the cause of the problem well enough to know whether we could have prevented it and or caught it early.

jonasfj commented 1 year ago

Sounds like someone is modifying PUB_HOSTED_URL (to override the default pub server), and that this might not be propagated to the analysis_server. This is not necessarily surprising, since the analysis_server might be started by an IDE and thus the PUB_HOSTED_URL might not be set. Or maybe it's that the invocation doesn't propagate PUB_HOSTED_URL (this is probably easy to fix).

A workaround might be to use the hosted: <url> syntax in pubspec.yaml: https://dart.dev/tools/pub/custom-package-repositories#using-multiple-package-repositories

@mengdouer, I'm not 100% sure I actually understand what it is you're trying to do.

mengdouer commented 1 year ago

@jonasfj Yes, you are right. Thans for your help. this error can be solved by this method. But ask if there is a follow-up plan to fix this or need me to submit a PR to fix this bug?

jonasfj commented 1 year ago

But ask if there is a follow-up plan to fix this or need me to submit a PR to fix this bug?

We should probably fix the analyzer plugin stuff to forward the PUB_HOSTED_URL. I don't review analyzer patches, but I think you'd be welcome to contribute a patch, see CONTRIBUTING.md.