Skip to content

Commit

Permalink
SONAR-22427 Adapt Onboarding tutorials for CFamily Linux ARM64 (#11286)
Browse files Browse the repository at this point in the history
  • Loading branch information
enzo-pellegrini authored and sonartech committed Jun 20, 2024
1 parent 502827c commit ccddfde
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { Link } from '@sonarsource/echoes-react';
import { Dictionary } from 'lodash';
import * as React from 'react';
import { FormattedMessage } from 'react-intl';
import withAvailableFeatures, {
WithAvailableFeaturesProps,
} from '../../../app/components/available-features/withAvailableFeatures';
import { DocLink } from '../../../helpers/doc-links';
import { useDocUrl } from '../../../helpers/docs';
import { translate } from '../../../helpers/l10n';
import { Feature } from '../../../types/features';
import { Component } from '../../../types/types';
import { CompilationInfo } from '../components/CompilationInfo';
import CreateYmlFile from '../components/CreateYmlFile';
import { Arch, BuildTools, TutorialConfig } from '../types';
import { Arch, AutoConfig, BuildTools, TutorialConfig } from '../types';
import { isCFamily } from '../utils';
import { PreambuleYaml } from './PreambuleYaml';
import cFamilyExample from './commands/CFamily';
Expand Down Expand Up @@ -60,9 +65,20 @@ const YamlTemplate: Dictionary<BuildToolExampleBuilder> = {
[BuildTools.Other]: othersExample,
};

const showJreWarning = (config: TutorialConfig, arch: Arch) => {
if (!isCFamily(config.buildTool)) {
return false;
}
if (config.autoConfig === AutoConfig.Automatic) {
return false;
}
return arch === Arch.Arm64;
};

export function AnalysisCommand(props: Readonly<AnalysisCommandProps>) {
const { config, arch, mainBranchName, component } = props;
const branchesEnabled = props.hasFeature(Feature.BranchSupport);
const scannerRequirementsUrl = useDocUrl(DocLink.SonarScannerRequirements);

if (!config.buildTool) {
return null;
Expand All @@ -77,10 +93,30 @@ export function AnalysisCommand(props: Readonly<AnalysisCommandProps>) {
projectName: component.name,
});

const warning = showJreWarning(config, arch) && (
<p className="sw-mb-2">
<FormattedMessage
defaultMessage={translate('onboarding.analysis.sq_scanner.jre_required_warning')}
id="onboarding.analysis.sq_scanner.jre_required_warning"
values={{
link: (
<Link to={scannerRequirementsUrl}>
{translate('onboarding.analysis.sq_scanner.jre_required_warning.link')}
</Link>
),
}}
/>
</p>
);

return (
<>
<PreambuleYaml buildTool={config.buildTool} component={component} />
<CreateYmlFile yamlFileName="bitbucket-pipelines.yml" yamlTemplate={yamlTemplate} />
<CreateYmlFile
yamlFileName="bitbucket-pipelines.yml"
yamlTemplate={yamlTemplate}
warning={warning}
/>
{isCFamily(config.buildTool) && <CompilationInfo />}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ definitions:
- mkdir $HOME/.sonar
- curl -sSLo $HOME/.sonar/build-wrapper-linux-aarch64.zip \${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-aarch64.zip
- unzip -o $HOME/.sonar/build-wrapper-linux-aarch64.zip -d $HOME/.sonar/
- curl -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-\${SONAR_SCANNER_VERSION}-linux.zip
- curl -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-\${SONAR_SCANNER_VERSION}.zip
- unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
- export PATH="$PATH:$HOME/.sonar/sonar-scanner-\${SONAR_SCANNER_VERSION}-linux/bin"
- export PATH="$PATH:$HOME/.sonar/sonar-scanner-\${SONAR_SCANNER_VERSION}/bin"
- <any step required before running your build, like ./configure>
- $HOME/.sonar/build-wrapper-linux-aarch64/build-wrapper-linux-aarch64 --out-dir bw-output <your clean build command>
- sonar-scanner -Dsonar.cfamily.compile-commands=bw-output/compile_commands.json
Expand Down Expand Up @@ -143,9 +143,9 @@ definitions:
- mkdir $HOME/.sonar
- curl -sSLo $HOME/.sonar/build-wrapper-linux-aarch64.zip \${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-aarch64.zip
- unzip -o $HOME/.sonar/build-wrapper-linux-aarch64.zip -d $HOME/.sonar/
- curl -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-\${SONAR_SCANNER_VERSION}-linux.zip
- curl -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-\${SONAR_SCANNER_VERSION}.zip
- unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
- export PATH="$PATH:$HOME/.sonar/sonar-scanner-\${SONAR_SCANNER_VERSION}-linux/bin"
- export PATH="$PATH:$HOME/.sonar/sonar-scanner-\${SONAR_SCANNER_VERSION}/bin"
- <any step required before running your build, like ./configure>
- $HOME/.sonar/build-wrapper-linux-aarch64/build-wrapper-linux-aarch64 --out-dir bw-output <your clean build command>
- sonar-scanner -Dsonar.cfamily.compile-commands=bw-output/compile_commands.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { AutoConfig, BuildTools } from '../../types';
import { getBuildWrapperExecutableLinux, getBuildWrapperFolderLinux } from '../../utils';
import { AutoConfig, BuildTools, OSs } from '../../types';
import {
getBuildWrapperExecutableLinux,
getBuildWrapperFolderLinux,
getScannerUrlSuffix,
} from '../../utils';
import { BuildToolExampleBuilder } from '../AnalysisCommand';
import othersExample from './Others';

Expand All @@ -33,6 +37,7 @@ const cFamilyExample: BuildToolExampleBuilder = ({
}
const buildWrapperExecutable = getBuildWrapperExecutableLinux(arch);
const buildWrapperFolder = getBuildWrapperFolderLinux(arch);
const scannerSuffix = getScannerUrlSuffix(OSs.Linux, arch);
return `image: <image ready for your build toolchain>
definitions:
Expand All @@ -44,9 +49,9 @@ definitions:
- mkdir $HOME/.sonar
- curl -sSLo $HOME/.sonar/${buildWrapperFolder}.zip \${SONAR_HOST_URL}/static/cpp/${buildWrapperFolder}.zip
- unzip -o $HOME/.sonar/${buildWrapperFolder}.zip -d $HOME/.sonar/
- curl -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-\${SONAR_SCANNER_VERSION}-linux.zip
- curl -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-\${SONAR_SCANNER_VERSION}${scannerSuffix}.zip
- unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
- export PATH="$PATH:$HOME/.sonar/sonar-scanner-\${SONAR_SCANNER_VERSION}-linux/bin"
- export PATH="$PATH:$HOME/.sonar/sonar-scanner-\${SONAR_SCANNER_VERSION}${scannerSuffix}/bin"
- <any step required before running your build, like ./configure>
- $HOME/.sonar/${buildWrapperFolder}/${buildWrapperExecutable} --out-dir bw-output <your clean build command>
- sonar-scanner -Dsonar.cfamily.compile-commands=bw-output/compile_commands.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { ClipboardIconButton, CodeSnippet, NumberedListItem } from 'design-system';
import { ClipboardIconButton, CodeSnippet, FlagMessage, NumberedListItem } from 'design-system';
import * as React from 'react';
import { FormattedMessage } from 'react-intl';
import { translate } from '../../../helpers/l10n';
import { InlineSnippet } from './InlineSnippet';

export interface CreateYmlFileProps {
warning?: React.ReactNode;
yamlFileName: string;
yamlTemplate: string;
}

export default function CreateYmlFile(props: CreateYmlFileProps) {
const { yamlTemplate, yamlFileName } = props;
export default function CreateYmlFile(props: Readonly<CreateYmlFileProps>) {
const { yamlTemplate, yamlFileName, warning } = props;
return (
<NumberedListItem>
<FormattedMessage
Expand All @@ -44,6 +45,13 @@ export default function CreateYmlFile(props: CreateYmlFileProps) {
),
}}
/>
{warning && (
<div>
<FlagMessage className="sw-mt-2 sw-w-abs-600" variant="warning">
{warning}
</FlagMessage>
</div>
)}
<CodeSnippet className="sw-p-6 sw-overflow-auto" snippet={yamlTemplate} language="yml" />
</NumberedListItem>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ interface Props {
arch?: Arch;
config: TutorialConfig;
hasCLanguageFeature: boolean;
isLocal: boolean;
os?: OSs;
setArch: (arch: Arch) => void;
setConfig: (config: TutorialConfig) => void;
setOs: (os: OSs) => void;
}

export function BuildToolForm(props: Readonly<Props>) {
const { config, setConfig, os, setOs, arch, setArch, hasCLanguageFeature } = props;
const { config, setConfig, os, setOs, arch, setArch, isLocal, hasCLanguageFeature } = props;

function handleConfigChange(newConfig: TutorialConfig) {
const selectOsByDefault = (newConfig.buildTool === BuildTools.Cpp ||
Expand Down Expand Up @@ -75,7 +76,7 @@ export function BuildToolForm(props: Readonly<Props>) {
titleLabelKey="onboarding.build.other.os"
/>
)}
{shouldShowArchSelector(os, config) && (
{shouldShowArchSelector(os, config, !isLocal) && (
<RenderOptions
label={translate('onboarding.build.other.architecture')}
checked={arch}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default function ProjectAnalysisStep(props: Readonly<Props>) {
<div className="sw-pb-4">
<BuildToolForm
config={config}
isLocal={isLocal}
setConfig={setConfig}
os={os}
setOs={setOs}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,19 @@ it('can choose build tools and copy provided settings', async () => {
// C++ - Automatic
await user.click(ui.cppBuildButton.get());
await user.click(ui.linuxButton.get());
expect(getCopyToClipboardValue(0, 'Copy')).toMatchSnapshot(
'c++ (automatic) and other linux: download scanner',
);
expect(getCopyToClipboardValue(1, 'Copy')).toMatchSnapshot(
'c++ (automatic) and other linux: execute scanner',
);
await user.click(ui.arm64Button.get());
expect(getCopyToClipboardValue(0, 'Copy')).toMatchSnapshot(
'c++ (automatic) and other linux arm64: download scanner',
);
expect(getCopyToClipboardValue(1, 'Copy')).toMatchSnapshot(
'c++ (automatic) and other linux arm64: execute scanner',
);
await user.click(ui.windowsButton.get());
expect(getCopyToClipboardValue(1, 'Copy')).toMatchSnapshot(
'c++ (automatic) and other windows: execute scanner',
Expand All @@ -139,6 +149,7 @@ it('can choose build tools and copy provided settings', async () => {
// C++ - Linux (x86_64)
await user.click(ui.autoConfigManual.get());
await user.click(ui.linuxButton.get());
await user.click(ui.x86_64Button.get());
expect(getCopyToClipboardValue(0, 'Copy')).toMatchSnapshot(
'c++ (manual) linux: download build wrapper',
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`can choose build tools and copy provided settings: c++ (automatic) and other linux arm64: download scanner 1`] = `
"export SONAR_SCANNER_VERSION=5.0.1.3006
export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION
curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION.zip
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
export PATH=$SONAR_SCANNER_HOME/bin:$PATH
export SONAR_SCANNER_OPTS="-server"
"
`;

exports[`can choose build tools and copy provided settings: c++ (automatic) and other linux arm64: execute scanner 1`] = `
"sonar-scanner \\
-Dsonar.projectKey=my-project \\
-Dsonar.sources=. \\
-Dsonar.host.url=http://localhost:9000"
`;

exports[`can choose build tools and copy provided settings: c++ (automatic) and other linux: download scanner 1`] = `
"export SONAR_SCANNER_VERSION=5.0.1.3006
export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux
curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
export PATH=$SONAR_SCANNER_HOME/bin:$PATH
export SONAR_SCANNER_OPTS="-server"
"
`;

exports[`can choose build tools and copy provided settings: c++ (automatic) and other linux: execute scanner 1`] = `
"sonar-scanner \\
-Dsonar.projectKey=my-project \\
Expand Down Expand Up @@ -60,8 +87,8 @@ export PATH=$HOME/.sonar/build-wrapper-linux-aarch64:$PATH

exports[`can choose build tools and copy provided settings: c++ (manual) linux arm64: download scanner 1`] = `
"export SONAR_SCANNER_VERSION=5.0.1.3006
export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux
curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION
curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION.zip
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
export PATH=$SONAR_SCANNER_HOME/bin:$PATH
export SONAR_SCANNER_OPTS="-server"
Expand Down Expand Up @@ -207,8 +234,8 @@ export PATH=$HOME/.sonar/build-wrapper-linux-aarch64:$PATH

exports[`can choose build tools and copy provided settings: objective-c linux arm64: download scanner 1`] = `
"export SONAR_SCANNER_VERSION=5.0.1.3006
export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux
curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION
curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION.zip
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
export PATH=$SONAR_SCANNER_HOME/bin:$PATH
export SONAR_SCANNER_OPTS="-server"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,28 @@ export default function AnalysisCommand(props: Readonly<AnalysisCommandProps>) {

case BuildTools.Other:
return (
<Other baseUrl={baseUrl} os={os} component={component} isLocal={isLocal} token={token} />
<Other
arch={Arch.X86_64}
baseUrl={baseUrl}
os={os}
component={component}
isLocal={isLocal}
token={token}
/>
);

case BuildTools.Cpp:
case BuildTools.ObjectiveC:
if (config.buildTool === BuildTools.Cpp && config.autoConfig === AutoConfig.Automatic) {
return (
<Other os={os} baseUrl={baseUrl} component={component} isLocal={isLocal} token={token} />
<Other
arch={arch}
os={os}
baseUrl={baseUrl}
component={component}
isLocal={isLocal}
token={token}
/>
);
}
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export interface ClangGCCCustomProps {
token: string;
}

export default function ClangGCCCustom(props: ClangGCCCustomProps) {
export default function ClangGCCCustom(props: Readonly<ClangGCCCustomProps>) {
const { os, arch, baseUrl, component, isLocal, token } = props;

return (
<div>
<DownloadBuildWrapper isLocal={isLocal} baseUrl={baseUrl} os={os} arch={arch} />
<DownloadScanner isLocal={isLocal} os={os} token={token} />
<DownloadScanner arch={arch} isLocal={isLocal} os={os} token={token} />
<ExecBuildWrapper os={os} arch={arch} />
<CompilationInfo />
<ExecScanner
Expand Down
Loading

0 comments on commit ccddfde

Please sign in to comment.