private void resolvePackageDependencies ( ) throws IOException { // FIXME: should produce a wy.lock file? Configuration . Schema buildSchema = environment . getBuildSchema ( ) ; // Global root is where all dependencies will be stored Path . Root repository = getRepositoryRoot ( ) ; // Dig out all the defined dependencies List < Path . ID > deps = configuration . matchAll ( Trie . fromString ( "dependencies/**" ) ) ; // Resolve each dependencies and add to project roots for ( int i = 0 ; i != deps . size ( ) ; ++ i ) { Path . ID dep = deps . get ( i ) ; // Get dependency name String name = dep . get ( 1 ) ; // Get version string UTF8 version = configuration . get ( UTF8 . class , dep ) ; // Construct path to the config file Trie root = Trie . fromString ( name + "-v" + version ) ; // Attempt to resolve it. if ( ! repository . exists ( root , ZipFile . ContentType ) ) { // TODO: employ a package resolver here // FIXME: handle better error handling. throw new RuntimeException ( "missing dependency \"" + name + "-" + version + "\"" ) ; } else { // Extract entry for ZipFile Path . Entry < ZipFile > zipfile = repository . get ( root , ZipFile . ContentType ) ; // Construct root repesenting this ZipFile Path . Root pkgRoot = new ZipFileRoot ( zipfile , environment . getContentRegistry ( ) ) ; // Extract configuration from package Path . Entry < ConfigFile > entry = pkgRoot . get ( Trie . fromString ( "wy" ) , ConfigFile . ContentType ) ; if ( entry == null ) { throw new RuntimeException ( "corrupt package (missing wy.toml) \"" + name + "-" + version + "\"" ) ; } else { ConfigFile pkgcfg = pkgRoot . get ( Trie . fromString ( "wy" ) , ConfigFile . ContentType ) . read ( ) ; // Construct a package representation of this root. Build . Package pkg = new Package ( pkgRoot , pkgcfg . toConfiguration ( buildSchema ) ) ; // Add a relative ZipFile root project . getPackages ( ) . add ( pkg ) ; } } } }
Add any declared dependencies to the set of project roots . The challenge here is that we may need to download install and compile these dependencies if they are not currently installed .