Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The 'path' member of 'target' or 'source' could be relative #1628

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/drivers/cmakefileapi/api_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ function convertToAbsolutePath(input_path: string, base_path: string) {
return path.normalize(absolute_path);
}

function convertToExtCodeModelFileGroup(targetObject: index_api.CodeModelKind.TargetObject): CodeModelFileGroup[] {
function convertToExtCodeModelFileGroup(
root_paths: index_api.CodeModelKind.PathInfo,
targetObject: index_api.CodeModelKind.TargetObject): CodeModelFileGroup[] {
const fileGroup: CodeModelFileGroup[] = !targetObject.compileGroups ? [] : targetObject.compileGroups.map(group => {
const compileFlags
= group.compileCommandFragments ? group.compileCommandFragments.map(frag => frag.fragment).join(' ') : '';
Expand All @@ -205,8 +207,10 @@ function convertToExtCodeModelFileGroup(targetObject: index_api.CodeModelKind.Ta
const defaultIndex = fileGroup.push({sources: [], isGenerated: false} as CodeModelFileGroup) - 1;


const src_path = convertToAbsolutePath(targetObject.paths.source, root_paths.source);
targetObject.sources.forEach(sourcefile => {
const file_path = path.relative(targetObject.paths.source, sourcefile.path).replace('\\', '/');
const file_abs_path = convertToAbsolutePath(sourcefile.path, root_paths.source);
const file_path = path.relative(src_path, file_abs_path).replace(/\\/g, '/');
if (sourcefile.compileGroupIndex !== undefined) {
fileGroup[sourcefile.compileGroupIndex].sources.push(file_path);
} else {
Expand All @@ -222,7 +226,7 @@ function convertToExtCodeModelFileGroup(targetObject: index_api.CodeModelKind.Ta
async function loadCodeModelTarget(root_paths: index_api.CodeModelKind.PathInfo, jsonfile: string) {
const targetObject = await loadTargetObject(jsonfile);

const fileGroups = convertToExtCodeModelFileGroup(targetObject);
const fileGroups = convertToExtCodeModelFileGroup(root_paths, targetObject);

// This implementation expects that there is only one sysroot in a target.
// The ServerAPI only has provided one sysroot. In the FileAPI,
Expand Down
43 changes: 38 additions & 5 deletions test/unit-tests/driver/driver-codemodel-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function makeCodeModelDriverTestsuite(
const workspacePath: string = 'test/unit-tests/driver/workspace';
const root = getTestRootFilePath(workspacePath);
const defaultWorkspaceFolder = getTestRootFilePath('test/unit-tests/driver/workspace/test_project');
const notInRootWorksapceFolder = getTestRootFilePath('test/unit-tests/driver/workspace/not_in_root_project/cmake');
const emptyWorkspaceFolder = getTestRootFilePath('test/unit-tests/driver/workspace/empty_project');

let kitDefault: Kit;
Expand All @@ -63,6 +64,10 @@ export function makeCodeModelDriverTestsuite(
done('Default build folder still exists');
}

if (!cleanupBuildDir(path.join(notInRootWorksapceFolder, 'build'))) {
done('Default build folder still exists');
}

if (!cleanupBuildDir(path.join(emptyWorkspaceFolder, 'build'))) {
done('Empty project build folder still exists');
}
Expand All @@ -77,12 +82,14 @@ export function makeCodeModelDriverTestsuite(
});


async function generateCodeModelForConfiguredDriver(args: string[] =
[]): Promise<null|codemodel_api.CodeModelContent> {
async function generateCodeModelForConfiguredDriver(
args: string[] = [],
worksapce: string = defaultWorkspaceFolder
): Promise<null|codemodel_api.CodeModelContent> {
const config = ConfigurationReader.create();
const executable = await getCMakeExecutableInformation(cmakePath);

driver = await driver_generator(executable, config, kitDefault, defaultWorkspaceFolder, async () => {}, []);
driver = await driver_generator(executable, config, kitDefault, worksapce, async () => {}, []);
let code_model: null|codemodel_api.CodeModelContent = null;
if (driver instanceof codemodel_api.CodeModelDriver) {
driver.onCodeModelChanged(cm => { code_model = cm; });
Expand Down Expand Up @@ -180,7 +187,7 @@ export function makeCodeModelDriverTestsuite(

// compile flags for file groups
if (process.platform === 'win32') {
expect(compile_information!.compileFlags).to.eq('/DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 ');
expect(compile_information!.compileFlags?.trim()).to.eq('/DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1');
}
}).timeout(90000);

Expand Down Expand Up @@ -216,7 +223,7 @@ export function makeCodeModelDriverTestsuite(

// compile flags for file groups
if (process.platform === 'win32') {
expect(target!.fileGroups![0].compileFlags).to.eq('/DWIN32 /D_WINDOWS /W3 /MDd /Zi /Ob0 /Od /RTC1 ');
expect(target!.fileGroups![0].compileFlags?.trim()).to.eq('/DWIN32 /D_WINDOWS /W3 /MDd /Zi /Ob0 /Od /RTC1');
}
}).timeout(90000);

Expand Down Expand Up @@ -246,5 +253,31 @@ export function makeCodeModelDriverTestsuite(
expect(target).to.be.not.undefined;
expect(target!.sysroot).to.be.eq('/tmp');
}).timeout(90000);

test('Test CMakeList.txt not in root executable target information', async () => {
const codemodel_data = await generateCodeModelForConfiguredDriver([], notInRootWorksapceFolder);
expect(codemodel_data).to.be.not.null;

const target = codemodel_data!.configurations[0].projects[0].targets.find(t => t.type == 'EXECUTABLE' && t.name == 'NotInRoot');
expect(target).to.be.not.undefined;

// Test target name used for node label
expect(target!.name).to.be.eq('NotInRoot');
const executableName = process.platform === 'win32' ? 'NotInRoot.exe' : 'NotInRoot';
expect(target!.fullName).to.be.eq(executableName);
expect(target!.type).to.be.eq('EXECUTABLE');

// Test location of project source directory
// used by tree view to make paths relative
expect(path.normalize(target!.sourceDirectory!).toLowerCase())
.to.eq(path.normalize(path.join(root, 'not_in_root_project', 'cmake')).toLowerCase());

// Test main source file used in by tree view
expect(target!.fileGroups).to.be.not.undefined;
const compile_information = target!.fileGroups!.find(t => !!t.language);

expect(compile_information).to.be.not.undefined;
expect(compile_information!.sources).to.include('../main.cpp');
}).timeout(90000);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cmake_minimum_required(VERSION 3.0.0)
project(NotInRoot VERSION 0.1.0)

add_executable(NotInRoot ../main.cpp)
3 changes: 3 additions & 0 deletions test/unit-tests/driver/workspace/not_in_root_project/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main(int, char**) {
return 0;
}