Example #1
0
File: Task.cs Project: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////
		
		private bool ProcessFiles( NmpEvaluator nmp )
		{
			// ******
			string [] fileList = SourceFiles.Split( ';' );
			if( 0 == fileList.Length ) {
				Log.LogError( "SourceFiles is empty", null );
				return false;
			}
			
			// ******
			int fileCount = 0;

			foreach( string fileName in fileList ) {
				if( ! File.Exists(fileName) ) {
					Log.LogError( "the source file \"{0}\" could not be located", fileName );
					return false;
				}
				
				// ******
				try {
					string result = nmp.Evaluate( nmp.GetFileContext( fileName ), true );

					// ******
					if( ! Errors && result.Length > 0 ) {
						if( 0 == fileCount++ ) {
							File.WriteAllText( OutputFile, result );
						}
						else {
							File.AppendAllText( OutputFile, result );
						}
					}
				}
				catch ( Exception ex ) {
	//
	// report error here
	//
	#if EXREPORTING
	// ref dll
	#endif
					Log.LogErrorFromException( ex );
					return false;
				}
			}

			// ******
			return true;
		}
Example #2
0
File: Host.cs Project: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////

		protected Tuple<string, string, bool, string> EvaluateFile( string fileName, NmpStringArray defines )
		{
			// ******
			if( null != macroTracer ) {
				macroTracer.BeginSession( Path.GetFileName( fileName ), Path.GetDirectoryName( fileName ) );
			}

			// ******
			try {
				if( ! File.Exists(fileName) ) {
					Die( "input file does not exist: {0}", fileName );
				}

				// ******
				using( var mp = new NmpEvaluator(this) ) {

					foreach( var kvp in defines ) {
						var key = kvp.Key;
						if( !string.IsNullOrEmpty( key ) && '-' == key [ 0 ] ) {
							//
							// v3 have not added undef back to evaluator
							//
							continue;
						}

						// ******
						mp.AddTextMacro( key, kvp.Value, null );
					}

					// ******
					string result = mp.Evaluate( mp.GetFileContext(fileName), true );
					return new Tuple<string,string, bool, string>(result, mp.FileExt, mp.NoOutputFile, mp.OutputEncoding);
				}
			}

	//
	// catch error and report here
	//
#if EXREPORTING
			// ref dll
#endif

			finally {
				// ******
				if( null != macroTracer ) {
					macroTracer.EndSession();
				}

			}
		}
Example #3
0
File: Task.cs Project: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////

		public override bool Execute()
		{
			// ******
			try {
				////nmp = new NmpHostHelper( this );
				//nmp = new NmpEvaluator( new NmpHostHelper(this) );

				// ******
				using( var nmp = new NmpEvaluator(new NmpHostHelper(this)) ) {
					if( !SetDefines(nmp) ) {
						return false;
					}

					// ******
					if( !SetOutput() ) {
						return false;
					}

					// ******
					return ProcessFiles( nmp );
				}
			}
			
			catch ( Exception ex ) {
				Log.LogErrorFromException( ex );
				return false;
			}
			
			finally {
				//if( null != outFile ) {
				//	outFile.Close();
				//}
			}
		}
Example #4
0
File: Task.cs Project: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////
		
		private bool SetDefines( NmpEvaluator nmp )
		{
			// ******
			string startDir = Directory.GetCurrentDirectory();
			nmp.AddTextMacro( RESPONSE_PATH, startDir, null );


			// ******
			if( string.IsNullOrEmpty(Defines) ) {
				return true;
			}
		
			// ******
			NmpStringList defines = Utility.SplitDefines( Defines );
			
			foreach( string define in defines ) {
				string	key;
				string	value;
				
				if( Utility.GetValuePair(define, out key, out value) ) {
					nmp.AddTextMacro( key, value, null );
				}
				else {
					Log.LogError( "error in Defines argument: {0}", Defines );
					return false;
				}
			}
			
			// ******
			return true;
		}
Example #5
0
		/////////////////////////////////////////////////////////////////////////////

		public NmpResult Evaluate( IDictionary vsBuildPaths, IDictionary projProperties, string text, string inputFileName )
		{
			// ******
			string inputFullPath = Path.GetFullPath( inputFileName ).ToLower();

			// ******
			NmpResult evalResult = new NmpResult();

			evalResult.InputText = text;
			evalResult.FileName = inputFullPath;

			// ******
			var host = new CustomToolHost( evalResult.Messages );

			using( var nmp = new NmpEvaluator(host) ) {
				if( ! string.IsNullOrEmpty(inputFullPath) ) {
					nmp.ChangeRootDirectory( inputFileName );
				}

				// ******
				if( null != vsBuildPaths ) {
					AddObjectMacro( VSBUILD_PATHS_MACRO_NAME, new NmpArray(vsBuildPaths) );
				}

				if( null != projProperties ) {
					AddObjectMacro( VSPROJECT_PROPERTIES, new NmpArray(projProperties) );
			
					AddMacros( nmp, vsBuildPaths );
				}

				// ******
				var evx = nmp.GetStringContext( text );
				evx.SetFileInfo( inputFullPath );

				// ******
				bool errors = false;
				string result = string.Empty;
				try {
					evalResult.MacroResult = nmp.Evaluate( evx, true );
					evalResult.FileExt = nmp.FileExt;
				}
				catch ( CustomToolEvaluatorDieException ) {
					//
					// this is an exception we've created for as a generic terminal error
					// which simply causes us to return
					//
					errors = true;
				}
		
		//
		// catch error and report here
		//
	#if EXREPORTING
				// ref dll
	#endif
				//catch ( Exception ex ) {
				//	throw;
				//}

				// ******
				evalResult.Errors = errors;
				return evalResult;

			}
		}
Example #6
0
		/////////////////////////////////////////////////////////////////////////////

		private void AddMacros( NmpEvaluator nmp, IDictionary vsBuildPaths )
		{
			// ******
			foreach( KeyValuePair<string, object> kvp in ObjectMacros ) {
				nmp.AddObjectMacro( kvp.Key, kvp.Value );
			}

			// ******
			foreach( var tmd in TextMacros ) {
				nmp.AddTextMacro( tmd.Name, tmd.Text, new NmpStringList(tmd.ArgNames) );
			}

			// ******
			//nmp.AddObjectMacro( VSBUILD_PATHS_MACRO_NAME, new NmpArray(vsBuildPaths) );
		}