Skip to content

Commit 1f61ecf

Browse files
committed
Merge pull request microsoft#5590 from weswigham/compute-common-source-dir
Add case sensitivity-check to computeCommonSourceDirectory
2 parents 683ecc9 + a989595 commit 1f61ecf

16 files changed

Lines changed: 150 additions & 22 deletions

src/compiler/program.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ namespace ts {
904904

905905
function computeCommonSourceDirectory(sourceFiles: SourceFile[]): string {
906906
let commonPathComponents: string[];
907-
forEach(files, sourceFile => {
907+
const failed = forEach(files, sourceFile => {
908908
// Each file contributes into common source file path
909909
if (isDeclarationFile(sourceFile)) {
910910
return;
@@ -920,10 +920,10 @@ namespace ts {
920920
}
921921

922922
for (let i = 0, n = Math.min(commonPathComponents.length, sourcePathComponents.length); i < n; i++) {
923-
if (commonPathComponents[i] !== sourcePathComponents[i]) {
923+
if (getCanonicalFileName(commonPathComponents[i]) !== getCanonicalFileName(sourcePathComponents[i])) {
924924
if (i === 0) {
925-
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files));
926-
return;
925+
// Failed to find any common path component
926+
return true;
927927
}
928928

929929
// New common path found that is 0 -> i-1
@@ -938,6 +938,11 @@ namespace ts {
938938
}
939939
});
940940

941+
// A common path can not be found when paths span multiple drives on windows, for example
942+
if (failed) {
943+
return "";
944+
}
945+
941946
if (!commonPathComponents) { // Can happen when all input files are .d.ts files
942947
return currentDirectory;
943948
}
@@ -1059,6 +1064,10 @@ namespace ts {
10591064
else {
10601065
// Compute the commonSourceDirectory from the input files
10611066
commonSourceDirectory = computeCommonSourceDirectory(files);
1067+
// If we failed to find a good common directory, but outDir is specified and at least one of our files is on a windows drive/URL/other resource, add a failure
1068+
if (options.outDir && commonSourceDirectory === "" && forEach(files, file => getRootLength(file.fileName) > 1)) {
1069+
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files));
1070+
}
10621071
}
10631072

10641073
if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== directorySeparator) {

src/harness/compilerRunner.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,18 @@ class CompilerBaselineRunner extends RunnerBase {
4040
this.basePath += "/" + this.testSuiteName;
4141
}
4242

43+
private makeUnitName(name: string, root: string) {
44+
return ts.isRootedDiskPath(name) ? name : ts.combinePaths(root, name);
45+
};
46+
4347
public checkTestCodeOutput(fileName: string) {
4448
describe("compiler tests for " + fileName, () => {
4549
// Mocha holds onto the closure environment of the describe callback even after the test is done.
4650
// Everything declared here should be cleared out in the "after" callback.
4751
let justName: string;
48-
let content: string;
49-
let testCaseContent: { settings: Harness.TestCaseParser.CompilerSettings; testUnitData: Harness.TestCaseParser.TestUnitData[]; };
50-
51-
let units: Harness.TestCaseParser.TestUnitData[];
52-
let harnessSettings: Harness.TestCaseParser.CompilerSettings;
5352

5453
let lastUnit: Harness.TestCaseParser.TestUnitData;
55-
let rootDir: string;
54+
let harnessSettings: Harness.TestCaseParser.CompilerSettings;
5655

5756
let result: Harness.Compiler.CompilerResult;
5857
let options: ts.CompilerOptions;
@@ -63,28 +62,28 @@ class CompilerBaselineRunner extends RunnerBase {
6362

6463
before(() => {
6564
justName = fileName.replace(/^.*[\\\/]/, ""); // strips the fileName from the path.
66-
content = Harness.IO.readFile(fileName);
67-
testCaseContent = Harness.TestCaseParser.makeUnitsFromTest(content, fileName);
68-
units = testCaseContent.testUnitData;
65+
const content = Harness.IO.readFile(fileName);
66+
const testCaseContent = Harness.TestCaseParser.makeUnitsFromTest(content, fileName);
67+
const units = testCaseContent.testUnitData;
6968
harnessSettings = testCaseContent.settings;
7069
lastUnit = units[units.length - 1];
71-
rootDir = lastUnit.originalFilePath.indexOf("conformance") === -1 ? "tests/cases/compiler/" : lastUnit.originalFilePath.substring(0, lastUnit.originalFilePath.lastIndexOf("/")) + "/";
70+
const rootDir = lastUnit.originalFilePath.indexOf("conformance") === -1 ? "tests/cases/compiler/" : lastUnit.originalFilePath.substring(0, lastUnit.originalFilePath.lastIndexOf("/")) + "/";
7271
// We need to assemble the list of input files for the compiler and other related files on the 'filesystem' (ie in a multi-file test)
7372
// If the last file in a test uses require or a triple slash reference we'll assume all other files will be brought in via references,
7473
// otherwise, assume all files are just meant to be in the same compilation session without explicit references to one another.
7574
toBeCompiled = [];
7675
otherFiles = [];
7776
if (/require\(/.test(lastUnit.content) || /reference\spath/.test(lastUnit.content)) {
78-
toBeCompiled.push({ unitName: ts.combinePaths(rootDir, lastUnit.name), content: lastUnit.content });
77+
toBeCompiled.push({ unitName: this.makeUnitName(lastUnit.name, rootDir), content: lastUnit.content });
7978
units.forEach(unit => {
8079
if (unit.name !== lastUnit.name) {
81-
otherFiles.push({ unitName: ts.combinePaths(rootDir, unit.name), content: unit.content });
80+
otherFiles.push({ unitName: this.makeUnitName(unit.name, rootDir), content: unit.content });
8281
}
8382
});
8483
}
8584
else {
8685
toBeCompiled = units.map(unit => {
87-
return { unitName: ts.combinePaths(rootDir, unit.name), content: unit.content };
86+
return { unitName: this.makeUnitName(unit.name, rootDir), content: unit.content };
8887
});
8988
}
9089

@@ -99,12 +98,7 @@ class CompilerBaselineRunner extends RunnerBase {
9998
// Mocha holds onto the closure environment of the describe callback even after the test is done.
10099
// Therefore we have to clean out large objects after the test is done.
101100
justName = undefined;
102-
content = undefined;
103-
testCaseContent = undefined;
104-
units = undefined;
105-
harnessSettings = undefined;
106101
lastUnit = undefined;
107-
rootDir = undefined;
108102
result = undefined;
109103
options = undefined;
110104
toBeCompiled = undefined;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [tests/cases/compiler/commonSourceDir1.ts] ////
2+
3+
//// [bar.ts]
4+
var x: number;
5+
6+
//// [baz.ts]
7+
var y: number;
8+
9+
10+
//// [bar.js]
11+
var x;
12+
//// [baz.js]
13+
var y;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== A:/foo/bar.ts ===
2+
var x: number;
3+
>x : Symbol(x, Decl(bar.ts, 0, 3))
4+
5+
=== A:/foo/baz.ts ===
6+
var y: number;
7+
>y : Symbol(y, Decl(baz.ts, 0, 3))
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== A:/foo/bar.ts ===
2+
var x: number;
3+
>x : number
4+
5+
=== A:/foo/baz.ts ===
6+
var y: number;
7+
>y : number
8+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error TS5009: Cannot find the common subdirectory path for the input files.
2+
3+
4+
!!! error TS5009: Cannot find the common subdirectory path for the input files.
5+
==== A:/foo/bar.ts (0 errors) ====
6+
var x: number;
7+
8+
==== B:/foo/baz.ts (0 errors) ====
9+
var y: number;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [tests/cases/compiler/commonSourceDir2.ts] ////
2+
3+
//// [bar.ts]
4+
var x: number;
5+
6+
//// [baz.ts]
7+
var y: number;
8+
9+
//// [bar.js]
10+
var x;
11+
//// [baz.js]
12+
var y;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [tests/cases/compiler/commonSourceDir3.ts] ////
2+
3+
//// [bar.ts]
4+
var x: number;
5+
6+
//// [baz.ts]
7+
var y: number;
8+
9+
//// [bar.js]
10+
var x;
11+
//// [baz.js]
12+
var y;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== A:/foo/bar.ts ===
2+
var x: number;
3+
>x : Symbol(x, Decl(bar.ts, 0, 3))
4+
5+
=== a:/foo/baz.ts ===
6+
var y: number;
7+
>y : Symbol(y, Decl(baz.ts, 0, 3))
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== A:/foo/bar.ts ===
2+
var x: number;
3+
>x : number
4+
5+
=== a:/foo/baz.ts ===
6+
var y: number;
7+
>y : number
8+

0 commit comments

Comments
 (0)