Exemplo n.º 1
0
 void fetchIndex() {
     #ifdef DBG_GPROJLIBTOOL
         cerr << "COMMAND: " << "fetchIndex" << endl;
         cerr << "FOLDER:  " << this->projectFolder() << endl;
         cerr << "Name:    " << this->projectName() << endl;
     #endif
     Ginger::MnxBuilder b;
     b.start( "project" );
     b.put( "name", this->projectName() );
     this->addAllPackages( b );
     b.end();
     b.build()->render();
     cout << endl;
 }
Exemplo n.º 2
0
Valof * OrdinaryPackage::absoluteAutoload( const std::string & c ) {
	syslog( LOG_INFO, "Autoloading is_absolute_ref %s", c.c_str() );
	
	Ginger::Command cmd( FETCHGNX );
	cmd.addArg( "-X" );
	{
		list< string > & folders = this->getMachine()->getAppContext().getProjectFolderList();
		for ( 
			list< string >::iterator it = folders.begin();
			it != folders.end();
			++it
		) {
			cmd.addArg( "-j" );
			cmd.addArg( *it );
		}
	}
	
	#ifdef DBG_PACKAGE_AUTOLOAD
		cerr << "Autoloading" << endl;
		cerr << "  Package 	: " << this->title << endl;
		cerr << "  Variable : " << c << endl;
		list< string > & folders = this->getMachine()->getAppContext().getProjectFolderList();
		for ( 
			list< string >::iterator it = folders.begin();
			it != folders.end();
			++it
		) {
			cerr << "  Folder  : " << *it << endl;
		}
		cerr << "  Command  : " << cmd.asPrintString() << endl;
	#endif

	Ginger::MnxBuilder qb;
	qb.start( "fetch.definition" );
	qb.put( "pkg.name", this->title );
	qb.put( "var.name", c );
	qb.end();
	shared< Ginger::Mnx > query( qb.build() );

	#ifdef DBG_PACKAGE_AUTOLOAD
		cerr << "appginger asking for definition, using fetchgnx -X" << endl;
		cerr << "  [[";
		query->render( cerr );
		cerr << "]]" << endl;
	#endif	

	cmd.runWithInputAndOutput();
	int fd = cmd.getInputFD();   
	FILE * foutd = fdopen( cmd.getOutputFD(), "w" );
	fRenderMnx( foutd, query );
	
	stringstream prog;
	for (;;) {
		static char buffer[ 1024 ];
		int n = read( fd, buffer, sizeof( buffer ) );
		if ( n == 0 ) break;
		if ( n == -1 ) {
			if ( errno != EINTR ) {
				perror( "PACKAGE AUTOLOAD" );
				throw Ginger::Mishap( "Failed to read" );
			}
		} else if ( n > 0 ) {
			prog.write( buffer, n );
		}
	}
		
	fclose( foutd );
	
	#ifdef DBG_PACKAGE_AUTOLOAD
		cerr << "appginger/package autoloading, reply from fetchgnx -X" << endl;
		cerr << "  [[" << prog.str() << "]]" << endl;
		cerr << "ok" << endl;
	#endif
	
		
	//	Now we establish a forward declaration - to be justified by the success.
	#ifdef DBG_PACKAGE_AUTOLOAD
		cerr << "appginger/package doing a forward declaration" << endl;
	#endif
	Valof * id = this->forwardDeclare( c );

	try {
		//	And we load the stream.
		RCEP rcep( this );
		rcep.setPrinting( false );	//	Turn off result printing.
		#ifdef DBG_PACKAGE_AUTOLOAD
			cerr << "appginger/package loading into RCEP" << endl;
			cerr << "  [[" << prog.str() << "]]" << endl;
		#endif	
		rcep.unsafe_read_comp_exec_print( prog, cout );		
		return id;		
	} catch ( Ginger::Mishap & e ) {
		//	Undo the forward declaration.
		if ( id->valof == SYS_UNASSIGNED ) {
			//	The autoloading failed. Undo the declaration.
			this->retractForwardDeclare( c );
		}
		syslog( LOG_ERR, "Autoloading %s failed due to an exception", c.c_str() );
		throw Ginger::Mishap( "Autoloading failed (rethrowing)" ).culprit( "Name", c ).cause( e );
	}
	
	//	No autoloading implemented yet - just fail.
	return NULL;
}