@@ -421,13 +421,17 @@ public struct Driver {
421
421
compilerMode: compilerMode,
422
422
outputFileMap: self . outputFileMap,
423
423
moduleName: moduleOutputInfo. name)
424
+ let projectDirectory = Self . computeProjectDirectoryPath (
425
+ moduleOutputPath: self . moduleOutputInfo. output? . outputPath,
426
+ fileSystem: self . fileSystem)
424
427
self . moduleSourceInfoPath = try Self . computeModuleSourceInfoOutputPath (
425
428
& parsedOptions,
426
429
moduleOutputPath: self . moduleOutputInfo. output? . outputPath,
427
430
compilerOutputType: compilerOutputType,
428
431
compilerMode: compilerMode,
429
432
outputFileMap: self . outputFileMap,
430
- moduleName: moduleOutputInfo. name)
433
+ moduleName: moduleOutputInfo. name,
434
+ projectDirectory: projectDirectory)
431
435
self . swiftInterfacePath = try Self . computeSupplementaryOutputPath (
432
436
& parsedOptions, type: . swiftInterface, isOutputOptions: [ . emitModuleInterface] ,
433
437
outputPath: . emitModuleInterfacePath,
@@ -1732,6 +1736,19 @@ extension Driver {
1732
1736
return try VirtualPath ( path: moduleName. appendingFileTypeExtension ( type) )
1733
1737
}
1734
1738
1739
+ /// Determine if the build system has created a Project/ directory for auxilary outputs.
1740
+ static func computeProjectDirectoryPath( moduleOutputPath: VirtualPath ? ,
1741
+ fileSystem: FileSystem ) -> VirtualPath ? {
1742
+ let potentialProjectDirectory = moduleOutputPath?
1743
+ . parentDirectory
1744
+ . appending ( component: " Project " )
1745
+ . absolutePath
1746
+ guard let projectDirectory = potentialProjectDirectory, fileSystem. exists ( projectDirectory) else {
1747
+ return nil
1748
+ }
1749
+ return . absolute( projectDirectory)
1750
+ }
1751
+
1735
1752
/// Determine the output path for a module documentation.
1736
1753
static func computeModuleDocOutputPath(
1737
1754
_ parsedOptions: inout ParsedOptions ,
@@ -1759,7 +1776,8 @@ extension Driver {
1759
1776
compilerOutputType: FileType ? ,
1760
1777
compilerMode: CompilerMode ,
1761
1778
outputFileMap: OutputFileMap ? ,
1762
- moduleName: String
1779
+ moduleName: String ,
1780
+ projectDirectory: VirtualPath ?
1763
1781
) throws -> VirtualPath ? {
1764
1782
guard !parsedOptions. hasArgument ( . avoidEmitModuleSourceInfo) else { return nil }
1765
1783
return try computeModuleAuxiliaryOutputPath ( & parsedOptions,
@@ -1770,7 +1788,8 @@ extension Driver {
1770
1788
compilerOutputType: compilerOutputType,
1771
1789
compilerMode: compilerMode,
1772
1790
outputFileMap: outputFileMap,
1773
- moduleName: moduleName)
1791
+ moduleName: moduleName,
1792
+ projectDirectory: projectDirectory)
1774
1793
}
1775
1794
1776
1795
@@ -1784,7 +1803,8 @@ extension Driver {
1784
1803
compilerOutputType: FileType ? ,
1785
1804
compilerMode: CompilerMode ,
1786
1805
outputFileMap: OutputFileMap ? ,
1787
- moduleName: String
1806
+ moduleName: String ,
1807
+ projectDirectory: VirtualPath ? = nil
1788
1808
) throws -> VirtualPath ? {
1789
1809
// If there is an explicit argument for the output path, use that
1790
1810
if let outputPathArg = parsedOptions. getLastArgument ( outputPath) {
@@ -1809,26 +1829,22 @@ extension Driver {
1809
1829
_ = parsedOptions. hasArgument ( isOutput)
1810
1830
}
1811
1831
1812
- return try moduleOutputPath. replacingExtension ( with: type)
1832
+ var parentPath : VirtualPath
1833
+ if let projectDirectory = projectDirectory {
1834
+ // If the build system has created a Project dir for us to include the file, use it.
1835
+ parentPath = projectDirectory
1836
+ } else {
1837
+ parentPath = moduleOutputPath. parentDirectory
1838
+ }
1839
+
1840
+ return try parentPath. appending ( component: moduleName) . replacingExtension ( with: type)
1813
1841
}
1814
1842
1815
1843
// If the output option was not provided, don't produce this output at all.
1816
1844
guard let isOutput = isOutput, parsedOptions. hasArgument ( isOutput) else {
1817
1845
return nil
1818
1846
}
1819
1847
1820
- // If there is an output argument, derive the name from there.
1821
- if let outputPathArg = parsedOptions. getLastArgument ( . o) {
1822
- let path = try VirtualPath ( path: outputPathArg. asSingle)
1823
-
1824
- // If the compiler output is of this type, use the argument directly.
1825
- if type == compilerOutputType {
1826
- return path
1827
- }
1828
-
1829
- return try path. replacingExtension ( with: type)
1830
- }
1831
-
1832
1848
return try VirtualPath ( path: moduleName. appendingFileTypeExtension ( type) )
1833
1849
}
1834
1850
}
0 commit comments