Example #1
0
        public Library( Configuration.Library libConfig, Assembly assembly )
        {
            m_Name = libConfig.Name;
            m_Assembly = assembly;

            m_Assembly.GetTypes();

            List<Type> typeList = new List<Type>();

            foreach ( Type type in m_Assembly.GetTypes() )
            {
                if ( libConfig == null || !libConfig.GetIgnoreType( type ) )
                    typeList.Add( type );
            }

            m_Types = typeList.ToArray();

            m_TypesByName = new TypeTable( m_Types.Length );
            m_TypesByFullName = new TypeTable( m_Types.Length );

            foreach ( Type type in m_Types )
            {
                m_TypesByName.Add( type.Name, type );
                m_TypesByFullName.Add( type.FullName, type );

                if ( type.IsDefined( typeof( TypeAliasAttribute ), false ) )
                {
                    object[] attrs = type.GetCustomAttributes( typeof( TypeAliasAttribute ), false );

                    if ( attrs != null && attrs.Length > 0 && attrs[0] != null )
                    {
                        TypeAliasAttribute attr = attrs[0] as TypeAliasAttribute;

                        foreach ( string alias in attr.Aliases )
                            m_TypesByFullName.Add( alias, type );
                    }
                }
            }

            m_TypeCache = new TypeCache( m_Types, m_TypesByName, m_TypesByFullName );
        }
Example #2
0
        private static Dictionary<string, DateTime> GetScripts( Configuration.Library libConfig, string type )
        {
            var sourceCodeFileProvider = new SourceCodeFileProvider( libConfig, type );

            var files = sourceCodeFileProvider.ProvideSources();

            return files;
        }
Example #3
0
        /// <summary>
        /// Enqueue a library for compilation, resolving all dependencies first.
        /// </summary>
        /// <param name="dst">This array will receive the libraries in the correct order.</param>
        /// <param name="libs">Source libraries.</param>
        /// <param name="queue">Somewhat like a stack of libraries currently waiting.</param>
        /// <param name="libConfig">The library to be added.</param>
        private static void EnqueueLibrary( List<Configuration.Library> dst, List<Configuration.Library> libs, ISet<string> queue, Configuration.Library libConfig )
        {
            var depends = libConfig.Depends;

            if ( libConfig.Name == "core" || libConfig.Disabled )
            {
                libs.Remove( libConfig );
                return;
            }

            if ( !libConfig.Exists )
            {
                libs.Remove( libConfig );
                Console.WriteLine( "Warning: library {0} does not exist", libConfig.Name );
                return;
            }

            // First resolve dependencies.
            if ( depends != null )
            {
                queue.Add( libConfig.Name );

                foreach ( string depend in depends )
                {
                    // If the depended library is already in the queue, there is a circular dependency.
                    if ( queue.Contains( depend ) )
                    {
                        Console.WriteLine( "Error: Circular library dependency {0} on {1}", libConfig.Name, depend );
                        throw new ApplicationException();
                    }

                    var next = Environment.Config.GetLibrary( depend );
                    if ( next == null || !next.Exists )
                    {
                        Console.WriteLine( "Error: Unresolved library dependency: {0} depends on {1}, which does not exist", libConfig.Name, depend );
                        throw new ApplicationException();
                    }

                    if ( next.Disabled )
                    {
                        Console.WriteLine( "Error: Unresolved library dependency: {0} depends on {1}, which is disabled", libConfig.Name, depend );
                        throw new ApplicationException();
                    }

                    if ( !dst.Contains( next ) )
                        EnqueueLibrary( dst, libs, queue, next );
                }

                queue.Remove( libConfig.Name );
            }

            // Then add it to 'dst'.
            dst.Add( libConfig );
            libs.Remove( libConfig );
        }
Example #4
0
        private static CompilerResults CompileCSScripts( ICollection<string> fileColl, string assemblyFile, Configuration.Library libConfig, bool debug )
        {
            var provider = new CSharpCodeProvider();
            #pragma warning disable 618
            var compiler = provider.CreateCompiler();
            #pragma warning restore 618

            string[] files;

            Console.WriteLine( "Scripts: Compiling library {0}, {1} C# sources", libConfig.Name, fileColl.Count );

            string tempFile = compiler.GetType().FullName == "Mono.CSharp.CSharpCodeCompiler"
                ? Path.GetTempFileName()
                : null;

            if ( tempFile == String.Empty )
                tempFile = null;

            if ( tempFile == null )
            {
                files = new string[fileColl.Count];
                fileColl.CopyTo( files, 0 );
            }
            else
            {
                /* to prevent an "argument list too long" error, we
                   write a list of file names to a temporary file
                   and add them with @filename */
                var w = new StreamWriter( tempFile, false );
                foreach ( string file in fileColl )
                {
                    w.Write( "\"" + file + "\" " );
                }
                w.Close();

                files = new string[0];
            }

            var parms = new CompilerParameters( GetReferenceAssemblies(), assemblyFile, debug );
            if ( tempFile != null )
                parms.CompilerOptions += "@" + tempFile;

            if ( libConfig.WarningLevel >= 0 )
                parms.WarningLevel = libConfig.WarningLevel;

            CompilerResults results = null;
            try
            {
                results = compiler.CompileAssemblyFromFileBatch( parms, files );
            }
            catch ( System.ComponentModel.Win32Exception e )
            {
                /* from WinError.h:
                 * #define ERROR_FILE_NOT_FOUND 2L
                 * #define ERROR_PATH_NOT_FOUND 3L
                 */
                if ( e.NativeErrorCode == 2 || e.NativeErrorCode == 3 )
                {
                    Console.WriteLine( "Fatal: Could not find the compiler - are you sure MCS is installed?" );
                    Console.WriteLine( "       (on Debian, try: apt-get install mono-mcs)" );
                    System.Environment.Exit( 2 );
                }
                else
                {
                    throw e;
                }
            }

            if ( tempFile != null )
                File.Delete( tempFile );

            m_AdditionalReferences.Add( assemblyFile );

            Display( results );

            return results;
        }
Example #5
0
        private static bool Compile( Configuration.Library libConfig, bool debug )
        {
            // Check if there is source code for this library.
            if ( libConfig.SourcePath == null )
            {
                if ( libConfig.BinaryPath == null )
                {
                    Console.WriteLine( "Warning: library {0} does not exist", libConfig.Name );
                    return true;
                }
                else if ( !libConfig.BinaryPath.Exists )
                {
                    Console.WriteLine( "Warning: library {0} does not exist: {1}", libConfig.Name, libConfig.BinaryPath );
                    return false;
                }

                Console.WriteLine( "Libraries: Loading library {0}", libConfig.Name );

                m_Libraries.Add( new Library( libConfig, Assembly.LoadFrom( libConfig.BinaryPath.FullName ) ) );
                m_AdditionalReferences.Add( libConfig.BinaryPath.FullName );

                return true;
            }
            else if ( !libConfig.SourcePath.Exists )
            {
                Console.WriteLine( "Warning: library {0} does not exist", libConfig.Name );
                return true;
            }

            var cache = new DirectoryInfo( Environment.Config.CacheDirectory ).CreateSubdirectory( libConfig.Name );

            if ( !cache.Exists )
            {
                Console.WriteLine( "Scripts: Failed to create directory {0}", cache.FullName );
                return false;
            }

            var csFile = Path.Combine( cache.FullName, libConfig.Name + ".dll" );
            var files = GetScripts( libConfig, "*.cs" );

            if ( files.Count > 0 )
            {
                string stampFile = Path.Combine( cache.FullName, libConfig.Name + ".stm" );

                if ( File.Exists( csFile ) && CheckStamps( files, stampFile ) )
                {
                    m_Libraries.Add( new Library( libConfig, Assembly.LoadFrom( csFile ) ) );
                    m_AdditionalReferences.Add( csFile );
                    Console.WriteLine( "Libraries: Loaded binary library {0}", libConfig.Name );
                }
                else
                {
                    var sorted = new List<string>( files.Keys );
                    sorted.Sort();

                    var results = CompileCSScripts( sorted, csFile, libConfig, debug );

                    if ( results != null )
                    {
                        if ( results.Errors.HasErrors )
                            return false;

                        m_Libraries.Add( new Library( libConfig, results.CompiledAssembly ) );
                        WriteStampFile( stampFile, files );
                    }
                }
            }

            return true;
        }
Example #6
0
        private static void GetScripts( Configuration.Library libConfig, Hashtable list, string path, string type )
        {
            foreach ( string dir in Directory.GetDirectories( path ) )
            {
                string baseName = Path.GetFileName( dir ).ToLower();

                for ( int i = 0; i < m_IgnoreNames.Length; i++ )
                {
                    if ( baseName == m_IgnoreNames[i] )
                        continue;
                }

                GetScripts( libConfig, list, dir, type );
            }

            foreach ( string filename in Directory.GetFiles( path, type ) )
            {
                // Pass relative filename only.
                if ( libConfig == null || !libConfig.GetIgnoreSource( filename ) )
                    list[filename] = File.GetLastWriteTime( filename );
            }
        }
Example #7
0
        private static Hashtable GetScripts( Configuration.Library libConfig, string type )
        {
            Hashtable list = new Hashtable();

            GetScripts( libConfig, list, libConfig.SourcePath.FullName, type );

            return list;
        }
Example #8
0
        private static Hashtable GetScripts( Configuration.Library libConfig, IEnumerable overlays, string type )
        {
            Hashtable files = GetScripts( libConfig, type );

            if ( overlays != null )
            {
                foreach ( Configuration.Library overlay in overlays )
                {
                    Hashtable files2 = GetScripts( overlay, type );

                    Overlay( libConfig.SourcePath.FullName, files, overlay.SourcePath.FullName, files2 );
                }
            }

            return files;
        }
Example #9
0
        /// <summary>
        /// Enqueue a library for compilation, resolving all dependencies first.
        /// </summary>
        /// <param name="dst">This array will receive the libraries in the correct order.</param>
        /// <param name="libs">Source libraries.</param>
        /// <param name="queue">Somewhat like a stack of libraries currently waiting.</param>
        /// <param name="libConfig">The library to be added.</param>
        private static void EnqueueLibrary( ArrayList dst, ArrayList libs, Hashtable queue, Configuration.Library libConfig )
        {
            string[] depends = libConfig.Depends;

            if ( libConfig.Name == "core" || libConfig.Disabled )
            {
                libs.Remove( libConfig );
                return;
            }

            if ( !libConfig.Exists )
            {
                libs.Remove( libConfig );
                Console.WriteLine( "Warning: library {0} does not exist", libConfig.Name );
                return;
            }

            /* first resolve dependencies */
            if ( depends != null )
            {
                queue[libConfig.Name] = 1;

                foreach ( string depend in depends )
                {
                    /* if the depended library is already in the
                     * queue, there is a circular dependency */
                    if ( queue.ContainsKey( depend ) )
                    {
                        Console.WriteLine( "Error: Circular library dependency {0} on {1}",
                                        libConfig.Name, depend );
                        throw new ApplicationException();
                    }

                    Configuration.Library next = Environment.Config.GetLibrary( depend );
                    if ( next == null || !next.Exists )
                    {
                        Console.WriteLine( "Error: Unresolved library dependency: {0} depends on {1}, which does not exist",
                                        libConfig.Name, depend );
                        throw new ApplicationException();
                    }

                    if ( next.Disabled )
                    {
                        Console.WriteLine( "Error: Unresolved library dependency: {0} depends on {1}, which is disabled",
                                        libConfig.Name, depend );
                        throw new ApplicationException();
                    }

                    if ( !dst.Contains( next ) )
                        EnqueueLibrary( dst, libs, queue, next );
                }

                queue.Remove( libConfig.Name );
            }

            /* then add it to 'dst' */
            dst.Add( libConfig );
            libs.Remove( libConfig );
        }