mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Support URL sources in StandardCompiler
This commit is contained in:
		
							parent
							
								
									c5f182df01
								
							
						
					
					
						commit
						8de02c7778
					
				| @ -162,11 +162,43 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input) | ||||
| 	if (!sources) | ||||
| 		return formatFatalError("JSONError", "No input sources specified."); | ||||
| 
 | ||||
| 	Json::Value errors = Json::arrayValue; | ||||
| 
 | ||||
| 	for (auto const& sourceName: sources.getMemberNames()) | ||||
| 		if (sources[sourceName]["content"].isString()) | ||||
| 			m_compilerStack.addSource(sourceName, sources[sourceName]["content"].asString()); | ||||
| 		else if (sources[sourceName]["urls"].isArray()) | ||||
| 			return formatFatalError("UnimplementedFeatureError", "Input URLs not supported yet."); | ||||
| 		{ | ||||
| 			if (!m_readFile) | ||||
| 				return formatFatalError("JSONError", "No import callback supplied, but URL is requested."); | ||||
| 
 | ||||
| 			bool found = false; | ||||
| 			vector<string> failures; | ||||
| 
 | ||||
| 			for (auto const& url: sources[sourceName]["urls"]) | ||||
| 			{ | ||||
| 				ReadFile::Result result = m_readFile(url.asString()); | ||||
| 				if (result.success) | ||||
| 				{ | ||||
| 					m_compilerStack.addSource(sourceName, result.contentsOrErrorMessage); | ||||
| 					found = true; | ||||
| 					break; | ||||
| 				} | ||||
| 				else | ||||
| 					failures.push_back("Cannot import url (\"" + url.asString() + "\"): " + result.contentsOrErrorMessage); | ||||
| 			} | ||||
| 
 | ||||
| 			for (auto const& failure: failures) | ||||
| 			{ | ||||
| 				/// If the import succeeded, let mark all the others as warnings, otherwise all of them are errors.
 | ||||
| 				errors.append(formatError( | ||||
| 					found ? true : false, | ||||
| 					"IOError", | ||||
| 					"general", | ||||
| 					failure | ||||
| 				)); | ||||
| 			} | ||||
| 		} | ||||
| 		else | ||||
| 			return formatFatalError("JSONError", "Invalid input source specified."); | ||||
| 
 | ||||
| @ -196,7 +228,6 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input) | ||||
| 
 | ||||
| 	auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return m_compilerStack.scanner(_sourceName); }; | ||||
| 
 | ||||
| 	Json::Value errors = Json::arrayValue; | ||||
| 	bool success = false; | ||||
| 
 | ||||
| 	try | ||||
|  | ||||
| @ -40,7 +40,7 @@ public: | ||||
| 	/// Creates a new StandardCompiler.
 | ||||
| 	/// @param _readFile callback to used to read files for import statements. Should return
 | ||||
| 	StandardCompiler(ReadFile::Callback const& _readFile = ReadFile::Callback()) | ||||
| 		: m_compilerStack(_readFile) | ||||
| 		: m_compilerStack(_readFile), m_readFile(_readFile) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| @ -55,6 +55,7 @@ private: | ||||
| 	Json::Value compileInternal(Json::Value const& _input); | ||||
| 
 | ||||
| 	CompilerStack m_compilerStack; | ||||
| 	ReadFile::Callback const& m_readFile; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user