Skip to content

Commit 3ecd35a

Browse files
committed
Fix out-of-tree builds
out-of-tree builds allow multiple configurations to be built simultaneously from one source tree. Each build configuration exists in a separate builddir, and the srcdir contains no configuration, object files or build artifacts. The builddir need not be a subdirectory of srcdir, and typically it is on another filesystem than the sources. In an autotools project which uses automake, the Makefiles are object files, ie they are generated specifically for a particular configuration, therefore they reside in the builddir. When building an autotools project out-of-tree, the workspace is the srcdir, and does not contain a Makefile. instead, the Makefile is in $makeDirectory which is the builddir. This commit cleans up the detection of makefile location that is done in the extension so that the correct makefile is found, even if it lives out-of-tree/out-of-workspace, has a name other than Makefile/makefile, an whether or not a file named Makefile also exists in the srcdir. The activationEvent is changed to "*" because when building out of tree, there are no makefiles in the workspace. "*" is the better activation because it means activate whenever the user enabled the extension; don't second guess. OTOH, the extension does nothing if a makefile is not found and not configured, so it's safe to have it activated on workspaces without makefiles, because of the cleaned-up detection/configuration of makefiles.
1 parent ba69555 commit 3ecd35a

2 files changed

Lines changed: 65 additions & 75 deletions

File tree

package.json

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,44 +37,7 @@
3737
"Other"
3838
],
3939
"activationEvents": [
40-
"onCommand:makefile.setBuildConfiguration",
41-
"onCommand:makefile.getConfiguration",
42-
"onCommand:makefile.setBuildTarget",
43-
"onCommand:makefile.getBuildTarget",
44-
"onCommand:makefile.buildTarget",
45-
"onCommand:makefile.buildCleanTarget",
46-
"onCommand:makefile.buildAll",
47-
"onCommand:makefile.buildCleanAll",
48-
"onCommand:makefile.setLaunchConfiguration",
49-
"onCommand:makefile.launchDebug",
50-
"onCommand:makefile.launchRun",
51-
"onCommand:makefile.launchTargetPath",
52-
"onCommand:makefile.getLaunchTargetPath",
53-
"onCommand:makefile.launchTargetFileName",
54-
"onCommand:makefile.getLaunchTargetFileName",
55-
"onCommand:makefile.getLaunchTargetDirectory",
56-
"onCommand:makefile.getLaunchTargetArgs",
57-
"onCommand:makefile.getLaunchTargetArgsConcat",
58-
"onCommand:makefile.makeBaseDirectory",
59-
"onCommand:makefile.configure",
60-
"onCommand:makefile.cleanConfigure",
61-
"onCommand:makefile.preConfigure",
62-
"onCommand:makefile.postConfigure",
63-
"onCommand:makefile.outline.setBuildConfiguration",
64-
"onCommand:makefile.outline.setBuildTarget",
65-
"onCommand:makefile.outline.buildTarget",
66-
"onCommand:makefile.outline.buildCleanTarget",
67-
"onCommand:makefile.outline.setLaunchConfiguration",
68-
"onCommand:makefile.outline.launchDebug",
69-
"onCommand:makefile.outline.launchRun",
70-
"onCommand:makefile.outline.configure",
71-
"onCommand:makefile.outline.cleanConfigure",
72-
"onCommand:makefile.outline.preConfigure",
73-
"onCommand:makefile.outline.postConfigure",
74-
"onCommand:makefile.resetState",
75-
"workspaceContains:**/makefile",
76-
"workspaceContains:**/Makefile",
77-
"workspaceContains:**/GNUmakefile"
40+
"*"
7841
],
7942
"main": "./out/src/extension.js",
8043
"contributes": {

src/configuration.ts

Lines changed: 64 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -699,39 +699,82 @@ export async function getCommandForConfiguration(configuration: string | undefin
699699
configurationMakeCommand += ".exe";
700700
}
701701

702+
// Add the working directory path via the -C switch.
703+
// makefile.configurations.makeDirectory overwrites makefile.makeDirectory.
704+
let makeDirectoryUsed: string | undefined = makefileConfiguration?.makeDirectory ? util.resolvePathToRoot(makefileConfiguration?.makeDirectory) : makeDirectory;
705+
if (makeDirectoryUsed) {
706+
configurationMakeArgs.push("-C");
707+
configurationMakeArgs.push(`${makeDirectoryUsed}`);
708+
configurationMakefile = makeDirectoryUsed;
709+
}
710+
702711
// Add the makefile path via the -f make switch.
712+
// The make file is in makeDirectory or in the workspace directory,
713+
// and is named "Makefile" or "makefile".
703714
// makefile.configurations.makefilePath overwrites makefile.makefilePath.
704-
configurationMakefile = makefileConfiguration?.makefilePath ? util.resolvePathToRoot(makefileConfiguration?.makefilePath) : makefilePath;
705-
if (configurationMakefile) {
706-
// check if the makefile path is a directory. If so, try adding `Makefile` or `makefile`
707-
if (util.checkDirectoryExistsSync(configurationMakefile)) {
708-
let makeFileTest: string = path.join(configurationMakefile, "Makefile");
709-
if (!util.checkFileExistsSync(makeFileTest)) {
710-
makeFileTest = path.join(configurationMakefile, "makefile");
715+
let makeFileTest: string | undefined;
716+
// filename of makefile relative to makeDirectory
717+
let relativeMakefile: string | undefined;
718+
let makefileExists : boolean = false;
719+
if (makeDirectoryUsed) {
720+
// check if the makefile path is a directory. If so, try adding
721+
// the configuration makefilePath, then the makefilePath, then `Makefile` or `makefile`
722+
if (util.checkDirectoryExistsSync(makeDirectoryUsed)) {
723+
if (makefileConfiguration?.makefilePath) {
724+
makeFileTest = path.join(makeDirectoryUsed, makefileConfiguration?.makefilePath);
725+
relativeMakefile = makefileConfiguration?.makefilePath;
726+
makefileExists = util.checkFileExistsSync(util.resolvePathToRoot(makeFileTest));
727+
if (!makefileExists) {
728+
makeFileTest = makefilePath;
729+
relativeMakefile = util.resolvePathToRoot(makeFileTest);
730+
makefileExists = util.checkFileExistsSync(util.resolvePathToRoot(makeFileTest));
731+
}
711732
}
712-
713-
// if we found the makefile in the directory, set the `configurationMakefile` to the found file path.
714-
if (util.checkFileExistsSync(makeFileTest)) {
715-
configurationMakefile = makeFileTest;
733+
if (!makefileExists) {
734+
makeFileTest = path.join(makeDirectoryUsed, makefilePath);
735+
relativeMakefile = makefilePath;
736+
makefileExists = util.checkFileExistsSync(util.resolvePathToRoot(makeFileTest));
737+
if (!makefileExists) {
738+
if (makefilePath != "Makefile") {
739+
relativeMakefile = "Makefile";
740+
makeFileTest = path.join(makeDirectoryUsed, relativeMakefile);
741+
makefileExists = util.checkFileExistsSync(util.resolvePathToRoot(makeFileTest));
742+
}
743+
if (!makefileExists) {
744+
relativeMakefile = "makefile";
745+
makeFileTest = path.join(makeDirectoryUsed, relativeMakefile);
746+
makefileExists = util.checkFileExistsSync(util.resolvePathToRoot(makeFileTest));
747+
}
748+
}
716749
}
717750
}
751+
}
752+
if (!makefileExists) {
753+
if (!makeDirectoryUsed && makefileConfiguration?.makefilePath) {
754+
relativeMakefile = makefileConfiguration?.makefilePath;
755+
makeFileTest = makefileConfiguration?.makefilePath;
756+
makefileExists = util.checkFileExistsSync(util.resolvePathToRoot(makeFileTest));
757+
}
758+
}
759+
if (!makefileExists) {
760+
makeFileTest = makefilePath;
761+
relativeMakefile = makefilePath;
762+
makefileExists = util.checkFileExistsSync(util.resolvePathToRoot(makeFileTest));
763+
}
718764

765+
// if we found the makefile in the directory, set the `configurationMakefile` to the found file path.
766+
if (makefileExists) {
767+
configurationMakefile = relativeMakefile;
719768
configurationMakeArgs.push("-f");
720-
configurationMakeArgs.push(`${configurationMakefile}`);
769+
configurationMakeArgs.push(`${relativeMakefile}`);
770+
setMakefilePath(relativeMakefile);
771+
setConfigurationMakefile(makeFileTest);
721772
// Need to rethink this (GitHub 59).
722773
// Some repos don't work when we automatically add -C, others don't work when we don't.
723774
// configurationMakeArgs.push("-C");
724775
// configurationMakeArgs.push(path.parse(configurationMakefile).dir);
725776
}
726777

727-
// Add the working directory path via the -C switch.
728-
// makefile.configurations.makeDirectory overwrites makefile.makeDirectory.
729-
let makeDirectoryUsed: string | undefined = makefileConfiguration?.makeDirectory ? util.resolvePathToRoot(makefileConfiguration?.makeDirectory) : makeDirectory;
730-
if (makeDirectoryUsed) {
731-
configurationMakeArgs.push("-C");
732-
configurationMakeArgs.push(`${makeDirectoryUsed}`);
733-
}
734-
735778
// Make sure we append "makefile.configurations[].makeArgs" last, in case the developer wants to overwrite any arguments that the extension
736779
// deduces from the settings. Additionally, for -f/-C, resolve path to root.
737780
if (makefileConfiguration?.makeArgs) {
@@ -755,22 +798,6 @@ export async function getCommandForConfiguration(configuration: string | undefin
755798
logger.message(`Deduced command '${configurationMakeCommand} ${configurationMakeArgs.join(" ")}' for configuration "${configuration}"`);
756799
}
757800

758-
// Check for makefile path on disk: we search first for any makefile specified via the makefilePath setting,
759-
// then via the makeDirectory setting and then in the root of the workspace. On linux/mac, it often is 'Makefile', so verify that we default to the right filename.
760-
if (!configurationMakefile) {
761-
if (makeDirectoryUsed) {
762-
configurationMakefile = util.resolvePathToRoot(path.join(makeDirectoryUsed, "Makefile"));
763-
if (!util.checkFileExistsSync(configurationMakefile)) {
764-
configurationMakefile = util.resolvePathToRoot(path.join(makeDirectoryUsed, "makefile"));
765-
}
766-
} else {
767-
configurationMakefile = util.resolvePathToRoot("./Makefile");
768-
if (!util.checkFileExistsSync(configurationMakefile)) {
769-
configurationMakefile = util.resolvePathToRoot("./makefile");
770-
}
771-
}
772-
}
773-
774801
// Validation and warnings about properly defining the makefile and make tool.
775802
// These are not needed if the current configuration reads from a build log instead of dry-run output.
776803
let buildLog: string | undefined = getConfigurationBuildLog();
@@ -808,7 +835,7 @@ export async function getCommandForConfiguration(configuration: string | undefin
808835
}
809836
}
810837

811-
if (!util.checkFileExistsSync(util.resolvePathToRoot(configurationMakefile))) {
838+
if (!makefileExists) {
812839
logger.message("The makefile entry point was not found. " +
813840
"Make sure it exists at the location defined by makefile.makefilePath, makefile.configurations[].makefilePath, " +
814841
"makefile.makeDirectory, makefile.configurations[].makeDirectory" +

0 commit comments

Comments
 (0)