From 743ca4750ce81fe2cd2f541d00f1d9042ef6364c Mon Sep 17 00:00:00 2001 From: Alice Trifu Date: Mon, 12 Feb 2024 10:58:58 -0500 Subject: [PATCH] Created JSON Compilation Database Generator preference page and set file generation on false by default. Added JUnit test to test the generation of the file --- .../regressions/helloworldCPP.zip | Bin 0 -> 3999 bytes .../CompilationDatabaseGenerationTest.java | 187 ++++++++++++++++++ ...ompilationDatabaseContributionManager.java | 20 +- .../internal/core/CommonBuilder.java | 21 +- .../plugin.xml | 9 + .../JsonCdbGeneratorPreferencePage.java | 70 +++++++ .../ui/compilationdatabase/Messages.java | 26 +++ .../compilationdatabase/messages.properties | 11 ++ 8 files changed, 333 insertions(+), 11 deletions(-) create mode 100644 build/org.eclipse.cdt.managedbuilder.core.tests/resources/builderTests/regressions/helloworldCPP.zip create mode 100644 build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/CompilationDatabaseGenerationTest.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/compilationdatabase/JsonCdbGeneratorPreferencePage.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/compilationdatabase/Messages.java create mode 100644 build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/compilationdatabase/messages.properties diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/resources/builderTests/regressions/helloworldCPP.zip b/build/org.eclipse.cdt.managedbuilder.core.tests/resources/builderTests/regressions/helloworldCPP.zip new file mode 100644 index 0000000000000000000000000000000000000000..b6fe5bbf499d9cf7af99cd7c48c0e5983eaad0a7 GIT binary patch literal 3999 zcmb7H1z1#DyBYC}yY{p9UbWwE?e}@V?_0}A7Z0Bn003MCa0VG#+UExo>JkC~ zIAQ<*5w;iTW~_0U8eiKV>3oxg{v^H)v3z2rz{7hStYd&1 zVQ8>o$!^C`%xJ8jY=MfQUQ(xJ$s!@wULI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5PKTNm;7Rr~x4pCMGqs ze{EkE@vcgkKN0J{@{p<5-jSQ@kDi?d2UpT1Dx8qPnTz1|(VXRPDaQm!8(w}Zk-Tf9 zi-W5S_`CBA7nY8T!uIdyrPB@Zk1iYl1K_NF<|>8#6qdbT%YQ=u8n`b*L$C*^pJDtm zGJa6QKOp~AZ2O5!iCs=9Hj4eXns zxonV) loadedInstances; - private final Map factoryExtensions; + private final Map loadedInstances = new HashMap<>(); + /** + * Map of tool chain IDs (see {@link IToolChain#getId()} to + * extension point information for the compilationDatabaseContributor extension. + */ + private final Map factoryExtensions = new HashMap<>(); private class EmptyCompilationDatabaseContributor implements ICompilationDatabaseContributor { @@ -47,8 +55,6 @@ private class EmptyCompilationDatabaseContributor implements ICompilationDatabas private static CompilationDatabaseContributionManager instance; private CompilationDatabaseContributionManager() { - this.factoryExtensions = new HashMap<>(); - this.loadedInstances = new HashMap<>(); initalise(); } @@ -60,8 +66,6 @@ public static synchronized CompilationDatabaseContributionManager getInstance() } private void initalise() { - Map loadedExtension = new HashMap<>(); - IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint( "org.eclipse.cdt.managedbuilder.core", CompilationDatabaseContributionManager.EXTENSION_ID); //$NON-NLS-1$ if (extension != null) { @@ -75,14 +79,12 @@ private void initalise() { String className = configElement .getAttribute(CompilationDatabaseContributionManager.ATTRIB_RUNNER); if (toolchainId != null && className != null) { - loadedExtension.put(toolchainId, configElement); + factoryExtensions.put(toolchainId, configElement); } } } } } - - this.factoryExtensions.putAll(loadedExtension); } /** diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java index e470b70ab08..54bdc2d7115 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java @@ -86,6 +86,9 @@ import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.ui.preferences.ScopedPreferenceStore; public class CommonBuilder extends ACBuilder implements IIncrementalProjectBuilder2 { @@ -94,6 +97,7 @@ public class CommonBuilder extends ACBuilder implements IIncrementalProjectBuild private static final String NEWLINE = System.getProperty("line.separator"); //$NON-NLS-1$ private static final String TRACE_FOOTER = "]: "; //$NON-NLS-1$ private static final String TRACE_HEADER = "GeneratedmakefileBuilder trace ["; //$NON-NLS-1$ + private static final String COMPILATION_DATABASE_ENABLEMENT = "generateFile"; //$NON-NLS-1$ public static boolean VERBOSE = false; private static final int PROGRESS_MONITOR_SCALE = 100; @@ -506,8 +510,10 @@ private IProject[] build(int kind, IProject project, IBuilder[] builders, boolea } for (int i = 0; i < num; i++) { - CompilationDatabaseGenerator generator = new CompilationDatabaseGenerator(getProject(), activeCfg); - generator.generate(); + if (isGenerateFileOptionEnabled()) { + CompilationDatabaseGenerator generator = new CompilationDatabaseGenerator(getProject(), activeCfg); + generator.generate(); + } //bug 219337 if (kind == INCREMENTAL_BUILD || kind == AUTO_BUILD) { if (buildConfigResourceChanges()) { //only build projects with project resource changes @@ -1378,4 +1384,15 @@ public ISchedulingRule getRule(int trigger, Map args) { // Success! return null; } + + public static boolean isGenerateFileOptionEnabled() { + try { + IPreferenceStore preferenceStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, + "org.eclipse.cdt.managedbuilder.ui"); //$NON-NLS-1$ + return preferenceStore.getBoolean(COMPILATION_DATABASE_ENABLEMENT); + } catch (Exception e) { + ManagedBuilderCorePlugin.log(e); + } + return false; + } } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml index 198bcea8041..75b6d44df51 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml @@ -917,5 +917,14 @@ label="%CDTToolchainProperty.keyword.toolchain2"> + + + + diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/compilationdatabase/JsonCdbGeneratorPreferencePage.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/compilationdatabase/JsonCdbGeneratorPreferencePage.java new file mode 100644 index 00000000000..02d1db6f22a --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/compilationdatabase/JsonCdbGeneratorPreferencePage.java @@ -0,0 +1,70 @@ +/******************************************************************************** + * Copyright (c) 2023, 2024 Renesas Electronics Corp. and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + ********************************************************************************/ +package org.eclipse.cdt.managedbuilder.ui.compilationdatabase; + +import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +/** + * Preference page for JSON Compilation Database Generator. + */ +public class JsonCdbGeneratorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { + private static final String ENABLE_FILE_GENERATION = "generateFile"; //$NON-NLS-1$ + private Button generateFileCheckbox; + private IPreferenceStore preferenceStore; + + public JsonCdbGeneratorPreferencePage() { + preferenceStore = ManagedBuilderUIPlugin.getDefault().getPreferenceStore(); + } + + @Override + protected Control createContents(Composite parent) { + final Composite composite = new Composite(parent, SWT.NONE); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + composite.setLayout(new GridLayout(1, false)); + Group cdbGeneratorOptions = new Group(composite, SWT.NONE); + cdbGeneratorOptions.setLayout(new FillLayout(SWT.HORIZONTAL)); + cdbGeneratorOptions.setText(Messages.JsonCdbGeneratorPreferencePage_description); + cdbGeneratorOptions.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + generateFileCheckbox = new Button(cdbGeneratorOptions, SWT.CHECK); + generateFileCheckbox.setSelection(preferenceStore.getBoolean(ENABLE_FILE_GENERATION)); + generateFileCheckbox.setText(Messages.JsonCdbGeneratorPreferencePage_generateCompilationdatabase); + generateFileCheckbox.addListener(SWT.Selection, e -> { + boolean newValue = generateFileCheckbox.getSelection(); + preferenceStore.setValue(ENABLE_FILE_GENERATION, newValue); + }); + return composite; + } + + /** + * Initializes the default values of this page in the preference bundle. + */ + @Override + protected void performDefaults() { + super.performDefaults(); + preferenceStore.setDefault(ENABLE_FILE_GENERATION, false); + } + + @Override + public void init(IWorkbench workbench) { + } + +} \ No newline at end of file diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/compilationdatabase/Messages.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/compilationdatabase/Messages.java new file mode 100644 index 00000000000..d4f3574ba56 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/compilationdatabase/Messages.java @@ -0,0 +1,26 @@ +/******************************************************************************** + * Copyright (c) 2023, 2024 Renesas Electronics Corp. and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + ********************************************************************************/ + +package org.eclipse.cdt.managedbuilder.ui.compilationdatabase; + +import org.eclipse.osgi.util.NLS; + +class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.cdt.managedbuilder.ui.compilationdatabase.messages"; //$NON-NLS-1$ + public static String JsonCdbGeneratorPreferencePage_description; + public static String JsonCdbGeneratorPreferencePage_generateCompilationdatabase; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/compilationdatabase/messages.properties b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/compilationdatabase/messages.properties new file mode 100644 index 00000000000..e9d671ea720 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/compilationdatabase/messages.properties @@ -0,0 +1,11 @@ +############################################################################### +# Copyright (c) 2023, 2024 Renesas Electronics Corp. and others. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License 2.0 which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# SPDX-License-Identifier: EPL-2.0 +############################################################################### +JsonCdbGeneratorPreferencePage_description=Enables default generation of compile_commands.json file on build process +JsonCdbGeneratorPreferencePage_generateCompilationdatabase=Generate compile_commands.json file \ No newline at end of file