1. rubenvb
  2. Ambrosia

Commits

rubenvb  committed 340b6da

Further deep down changes. Now I get a runtime crash, woohoo!

  • Participants
  • Parent commits 6557a47
  • Branches master

Comments (0)

Files changed (12)

File libAmbrosia/Include/Ambrosia/Configuration/build_config.h

View file
 
 libambrosia_namespace_begin
 
+// Forward declarations
+class ambrosia_config;
+
 class build_config : public config_base
 {
 public:
     build_config();
-    build_config( const config_base &config );
+    build_config( const std::string &subdirectory, const config_base &config );
 
     const string_map & user_options() const;
 

File libAmbrosia/Include/Ambrosia/Configuration/config_base.h

View file
     os m_target_os;
     toolchain m_target_toolchain;
 
+    std::string m_source_directory;
+
 private:
     string_set m_config; // mostly platform dependent stuff
-    std::string m_source_directory;
     std::string m_project_file;
     std::string m_build_directory; // if source and build dir are equal, this is ./build
     // Platform detection functions

File libAmbrosia/Include/Ambrosia/file_store.h

View file
 
 libambrosia_namespace_begin
 
+// Forward declarations
+class config_base;
+
 class file_store
 {
 public:
     const file_set & get_source_file_set( const std::string &directory );
 
     // Find the unique relative path to the filename, otherwise return all matching duplicates
-    const file_set find_source_file( const std::string &filename, const string_set &directories = string_set() );
+    const file_set find_source_file( const std::string &filename, const config_base &configuration,
+                                     const string_set &directories = string_set() );
     // Match filename with all directories and match wildcards
-    const file_set match_source_files( const std::string &filename, const string_set &directories = string_set() );
+    const file_set match_source_files( const std::string &filename, const config_base &configuration,
+                                       const string_set &directories = string_set() );
     // Read directory contents from disk (don't complain if already present).
     void add_source_directory( const std::string &directory = "" );
     void add_build_directory(const std::string &directory );

File libAmbrosia/Include/Ambrosia/target.h

View file
 class target : public node
 {
 public:
+    // 'global' target with subproject-wide dependencies
+    target( const std::string &subdirectory,
+            const dependency_list &dependencies, const ambrosia_config &config );
+    // other targets are based off of global
     target( const std::string &name, const target_type type,
-            const dependency_list &dependencies, const config_base &config = s_ambrosia_config );
+            const dependency_list &dependencies, const build_config &config );
 
     // Getters
     const std::string & name() const;

File libAmbrosia/Source/Ambrosia/Configuration/build_config.cpp

View file
     m_user_variables()
 {   }
 
-build_config::build_config( const config_base &config )
+build_config::build_config( const string &subdirectory, const config_base &config )
 :   config_base( config ),
     m_user_variables()
-{   }
+{
+    m_source_directory = m_source_directory + subdirectory;
+}
 
 /*
  * Setters

File libAmbrosia/Source/Ambrosia/Configuration/config_base.cpp

View file
     m_target_architecture( m_build_architecture ),
     m_target_os( m_build_os ),
     m_target_toolchain( detect_toolchain() ),
-    m_config(),
     m_source_directory(),
+    m_config(),
     m_project_file(),
     m_build_directory()
 {
     m_target_architecture( m_build_architecture ),
     m_target_os( m_build_os ),
     m_target_toolchain( detect_toolchain(requested_toolchain) ),
-    m_config(),
     m_source_directory(),
+    m_config(),
     m_project_file(),
     m_build_directory()
 {
     m_source_directory = source_directory;
     debug(5) << "config_base::set_source_directory::Adding " << m_source_directory << " to s_file_store.\n";
     s_file_store.add_source_directory( m_source_directory );
-    return true;
+    if( !error_status() )
+        return true;
+    else
+        return false;
 }
 void config_base::set_project_file( const string &project_file )
 {

File libAmbrosia/Source/Ambrosia/file_store.cpp

View file
     }
 }
 
-const file_set file_store::find_source_file( const string &filename, const string_set &directories )
+const file_set file_store::find_source_file( const string &filename, const config_base &configuration,
+                                             const string_set &directories )
 {
-    const string &source_directory = s_ambrosia_config.source_directory();
+    const string &source_directory = configuration.source_directory();
     // handle filename with directory prepended
     const string_pair directory_filename( split_preceding_directory(filename) );
     const string &preceding_directory = directory_filename.first;
         std::for_each( directories.begin(), directories.end(),
                        [&](const string & directory)
                        {
-                       directories_to_search.insert( full_directory_name(directory, preceding_directory) );
+                           const string full_dir = full_directory_name(directory, preceding_directory);
+                           if( directory_exists(full_dir))
+                           {
+                               debug(5) << "file_store::find_source_file::Adding deduced directory to search list: "
+                                           << full_dir << "\n";
+                               directories_to_search.insert( full_dir );
+                           }
+                           else
+                               debug(5) << "file_store::find_source_file::Not adding non-existing deduced directory to search list: "
+                                        << full_dir << ".\n";
                        } );
+        if( directories_to_search.empty() )
+            directories_to_search = { "" };
     }
     debug(4) << "file_store::find_source_file::Looking for " << filename
              << " in the following subdirectories of " << source_directory
     debug(4) << "file_store::find_source_file::Found " << result.size() << " match(es).\n";
     return result;
 }
-const file_set file_store::match_source_files( const string &filename, const string_set &directories )
+const file_set file_store::match_source_files( const string &filename, const config_base &configuration,
+                                               const string_set &directories )
 {
     debug(4) << "file_store::match_source_files::Matching " << filename << " to all files in the source directories.\n";
     file_set result;
     const auto directory_end = directories.end();
     for( auto directory_it = directories.begin(); directory_it != directory_end; ++directory_it )
     {
-        const string directory( *directory_it + preceding_directory );
+        const string directory( full_directory_name(configuration.source_directory(),
+                                                    *directory_it + preceding_directory) );
+        if( !directory_exists(directory) )
+        {
+            debug(5) << "file_store::match_source_files::Skipping nonexistent directory: " << directory << ".\n";
+        }
         debug(5) << "file_store::match_source_files::Looking in " << directory << " for matches.\n";
 
+
         const file_set &files_on_disk = get_source_file_set( directory );
         if( error_status() )
             return result;
 
 void file_store::add_source_directory( const std::string &directory )
 {
+#ifdef AMBROSIA_DEBUG
     if( !directory_exists(directory) )
-    {
-        debug(5) << "file_store::add_source_directory::Non-existing directory: " << directory << "\n";
-        return emit_error( "Directory does not exist: " + directory );
-    }
+        throw logic_error( "Directory does not exist: " + directory );
+#endif
 
     debug(5) << "file_store::add_source_directory::Scanning files in source directory: " << directory << ".\n";
     const auto result = m_source_files.insert( {directory, file_set()} );

File libAmbrosia/Source/Ambrosia/nectar.cpp

View file
 {
     debug(3) << "nectar::find_nectar_file called for: " << directory << ".\n";
     s_ambrosia_config.set_source_directory( directory );
-    file_set candidates = s_file_store.find_source_file( "*.nectar.txt" );
+    file_set candidates = s_file_store.find_source_file( "*.nectar.txt", s_ambrosia_config );
     switch( candidates.size() )
     {
         case 0:

File libAmbrosia/Source/Ambrosia/nectar_loader.cpp

View file
 
             if( next_token(token) && "{" == token )
             {
-                p_target = std::unique_ptr<target>( new target("global", target_type::global, dependency_list()) );
+                p_target = std::unique_ptr<target>( new target(m_subdirectory, dependency_list(), s_ambrosia_config) );
 
                 parse_target();
                 if( error_status() )
                     if( !next_token(token) && "{" == token )
                         return emit_error( "Expected '{' after " + map_value(target_type_map_inverse, type) + " target name." );
 
-                    p_target = std::unique_ptr<target>(new target(target_name, type, dependencies) );
+                    p_target = std::unique_ptr<target>(new target(target_name, type, dependencies, targets[0]->config()) );
 
                     parse_target();
                     if( error_status() )
 }
 bool nectar_loader::parse_source_directory_list( const file_type type )
 {
-    bool empty = true; // a list must not be empty
+    debug(4) << "parse_source_directory_list::Parsing full list, nonexistent directories are kept in error_list.\n";
+    bool empty_list = true; // a list must not be empty
     string token;
-    const string &source_directory = p_target->config().source_directory();
     // gather all list items
     while( next_list_token(token) )
     {
-        const string full_subdirectory_name = full_directory_name( source_directory, full_directory_name(m_subdirectory, token) );
-        debug(6) << "nectar_loader::parse_source_directory_list::Checking if directory exists: "
-                 << full_subdirectory_name << ".\n";
-        empty = false;
-        if( !p_target->add_source_directory(type, full_subdirectory_name) )
-            emit_error_list( {token + "(line " + to_string(m_line_number) + ")"} ); // add the bad directory to error_list
+        const string subdirectory_name = full_directory_name( m_subdirectory, token );
+
+        empty_list = false;
+        if( !p_target->add_source_directory(type, subdirectory_name) )
+            emit_error_list( {"line " + to_string(m_line_number) +": " + token} ); // add the bad directory to error_list
     }
-    if( empty )
+    if( empty_list )
         emit_syntax_error( "A list must not be empty" );
+    else if( error_list_status() )
+        emit_nectar_error( "Some source directories were not found:\n" );
 
     return !error_status();
 }

File libAmbrosia/Source/Ambrosia/status.cpp

View file
 }
 bool error_list_status()
 {
+#ifdef AMBROSIA_DEBUG
+    debug(0) << "status::error_list_status::Checking error status now.\n";
+    error_status_calls++;
+#endif
     return current_status == status::list;
 }
 
 void emit_error( const string &message )
 {
-    debug(0) << "status::emit_error:Emitting error here.\n";
+    debug(0) << "status::emit_error:Emitting error here:\n\t"
+             << message << "\n";
     current_status = status::error;
     error_messages += "\nError: " + message;
     std::for_each( error_list.begin(), error_list.end(),

File libAmbrosia/Source/Ambrosia/target.cpp

View file
 
 // Static variable initialization
 
+target::target( const string &subdirectory,
+                const dependency_list &dependencies, const ambrosia_config &config )
+:   node(subdirectory + "::global"),
+    m_type( target_type::global ),
+    m_dependencies( dependencies ),
+    m_build_config( subdirectory, config ),
+    m_source_directories(),
+    m_source_files(),
+    m_output_name( subdirectory + "::global" )
+{   }
 target::target( const string &name, const target_type type,
-                const dependency_list &dependencies, const config_base &config )
+                const dependency_list &dependencies, const build_config &config )
 :   node( name ),
     m_type( type ),
     m_dependencies( dependencies ),
 {
     if( contains(filename, "*?") )
     {
-        const file_set matches = s_file_store.match_source_files( filename, m_source_directories[type] );
+        const file_set matches = s_file_store.match_source_files( filename, m_build_config,
+                                                                  m_source_directories[type] );
         if( matches.empty() )
             return emit_nectar_error( "No files matching " + filename + " found.",
                                       nectar_file, line_number ); // error will be handled
     }
     else
     {
-        const file_set matches = s_file_store.find_source_file( filename, m_source_directories[type] );
+        const file_set matches = s_file_store.find_source_file( filename, m_build_config,
+                                                                m_source_directories[type] );
         switch( matches.size() )
         {
             case 0:
 }
 void target::remove_file( const file_type type, const string &filename )
 {
-    s_file_store.match_source_files( filename, m_source_directories[type] );
+    s_file_store.match_source_files( filename, m_build_config,
+                                     m_source_directories[type] );
     emit_error( "target::remove_file::Unimplementented." );
 }
 bool target::add_source_directory( const file_type type, const string &directory )
 {
-    s_file_store.add_source_directory( directory );
-    if( error_status() )
+    const string full_subdirectory_name = full_directory_name( m_build_config.source_directory(), directory );
+    debug(6) << "target::add_source_directory::Checking if directory " << full_subdirectory_name
+             << " exists.\n";
+    if( !directory_exists(full_subdirectory_name) )
         return false;
 
+    s_file_store.add_source_directory( full_subdirectory_name );
     m_source_directories[type].insert( directory );
     return true;
 }

File libAmbrosia/libAmbrosia.nectar.txt

View file
 lib libAmbrosia
 {
     HEADER_DIRS Include/Ambrosia
-    SOURCE_DIRS Source/Ambrosia
+    SOURCE_DIRS Source/Ambrosia \
+                Source/Ambrosia/Configuration
 
     SOURCES *.cpp
     # Platform files