@@ -415,13 +415,17 @@ public struct Driver {
415
415
compilerMode: compilerMode,
416
416
outputFileMap: self . outputFileMap,
417
417
moduleName: moduleOutputInfo. name)
418
+ let projectDirectory = Self . computeProjectDirectoryPath (
419
+ moduleOutputPath: self . moduleOutputInfo. output? . outputPath,
420
+ fileSystem: self . fileSystem)
418
421
self . moduleSourceInfoPath = try Self . computeModuleSourceInfoOutputPath (
419
422
& parsedOptions,
420
423
moduleOutputPath: self . moduleOutputInfo. output? . outputPath,
421
424
compilerOutputType: compilerOutputType,
422
425
compilerMode: compilerMode,
423
426
outputFileMap: self . outputFileMap,
424
- moduleName: moduleOutputInfo. name)
427
+ moduleName: moduleOutputInfo. name,
428
+ projectDirectory: projectDirectory)
425
429
self . swiftInterfacePath = try Self . computeSupplementaryOutputPath (
426
430
& parsedOptions, type: . swiftInterface, isOutputOptions: [ . emitModuleInterface] ,
427
431
outputPath: . emitModuleInterfacePath,
@@ -1719,6 +1723,19 @@ extension Driver {
1719
1723
return try VirtualPath ( path: moduleName. appendingFileTypeExtension ( type) )
1720
1724
}
1721
1725
1726
+ /// Determine if the build system has created a Project/ directory for auxilary outputs.
1727
+ static func computeProjectDirectoryPath( moduleOutputPath: VirtualPath ? ,
1728
+ fileSystem: FileSystem ) -> VirtualPath ? {
1729
+ let potentialProjectDirectory = moduleOutputPath?
1730
+ . parentDirectory
1731
+ . appending ( component: " Project " )
1732
+ . absolutePath
1733
+ guard let projectDirectory = potentialProjectDirectory, fileSystem. exists ( projectDirectory) else {
1734
+ return nil
1735
+ }
1736
+ return . absolute( projectDirectory)
1737
+ }
1738
+
1722
1739
/// Determine the output path for a module documentation.
1723
1740
static func computeModuleDocOutputPath(
1724
1741
_ parsedOptions: inout ParsedOptions ,
@@ -1746,7 +1763,8 @@ extension Driver {
1746
1763
compilerOutputType: FileType ? ,
1747
1764
compilerMode: CompilerMode ,
1748
1765
outputFileMap: OutputFileMap ? ,
1749
- moduleName: String
1766
+ moduleName: String ,
1767
+ projectDirectory: VirtualPath ?
1750
1768
) throws -> VirtualPath ? {
1751
1769
guard !parsedOptions. hasArgument ( . avoidEmitModuleSourceInfo) else { return nil }
1752
1770
return try computeModuleAuxiliaryOutputPath ( & parsedOptions,
@@ -1757,7 +1775,8 @@ extension Driver {
1757
1775
compilerOutputType: compilerOutputType,
1758
1776
compilerMode: compilerMode,
1759
1777
outputFileMap: outputFileMap,
1760
- moduleName: moduleName)
1778
+ moduleName: moduleName,
1779
+ projectDirectory: projectDirectory)
1761
1780
}
1762
1781
1763
1782
@@ -1771,7 +1790,8 @@ extension Driver {
1771
1790
compilerOutputType: FileType ? ,
1772
1791
compilerMode: CompilerMode ,
1773
1792
outputFileMap: OutputFileMap ? ,
1774
- moduleName: String
1793
+ moduleName: String ,
1794
+ projectDirectory: VirtualPath ? = nil
1775
1795
) throws -> VirtualPath ? {
1776
1796
// If there is an explicit argument for the output path, use that
1777
1797
if let outputPathArg = parsedOptions. getLastArgument ( outputPath) {
@@ -1796,26 +1816,22 @@ extension Driver {
1796
1816
_ = parsedOptions. hasArgument ( isOutput)
1797
1817
}
1798
1818
1799
- return try moduleOutputPath. replacingExtension ( with: type)
1819
+ var parentPath : VirtualPath
1820
+ if let projectDirectory = projectDirectory {
1821
+ // If the build system has created a Project dir for us to include the file, use it.
1822
+ parentPath = projectDirectory
1823
+ } else {
1824
+ parentPath = moduleOutputPath. parentDirectory
1825
+ }
1826
+
1827
+ return try parentPath. appending ( component: moduleName) . replacingExtension ( with: type)
1800
1828
}
1801
1829
1802
1830
// If the output option was not provided, don't produce this output at all.
1803
1831
guard let isOutput = isOutput, parsedOptions. hasArgument ( isOutput) else {
1804
1832
return nil
1805
1833
}
1806
1834
1807
- // If there is an output argument, derive the name from there.
1808
- if let outputPathArg = parsedOptions. getLastArgument ( . o) {
1809
- let path = try VirtualPath ( path: outputPathArg. asSingle)
1810
-
1811
- // If the compiler output is of this type, use the argument directly.
1812
- if type == compilerOutputType {
1813
- return path
1814
- }
1815
-
1816
- return try path. replacingExtension ( with: type)
1817
- }
1818
-
1819
1835
return try VirtualPath ( path: moduleName. appendingFileTypeExtension ( type) )
1820
1836
}
1821
1837
}
0 commit comments