DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • How to Build Real-Time BI Systems: Architecture, Code, and Best Practices
  • How To Build Resilient Microservices Using Circuit Breakers and Retries: A Developer’s Guide To Surviving
  • Accelerating Debugging in Integration Testing: An Efficient Search-Based Workflow for Impact Localization
  • MLOps: How to Build a Toolkit to Boost AI Project Performance

Trending

  • Efficient API Communication With Spring WebClient
  • How To Introduce a New API Quickly Using Quarkus and ChatGPT
  • Introducing Graph Concepts in Java With Eclipse JNoSQL
  • The Evolution of Scalable and Resilient Container Infrastructure

Linting Without a Plugin

By 
Erich Styger user avatar
Erich Styger
·
May. 07, 12 · Interview
Likes (0)
Comment
Save
Tweet
Share
9.6K Views

Join the DZone community and get the full member experience.

Join For Free

with “eclipse and pc-lint: linticator” i have a plugin to lint my sources in a comfortable way. but i can do this as well without a plugin. for this i use a batch file with a build configuration, plus settings to get the pc-lint messages into the problems view. yes, this does not sound easy, but is very doable and straight forward once i have set it up. it gives me complete control on every little detail. here is how i do it… pc-lint is like any other compiler: it compiles my source files. but, it is not producing object code: it is producing messages. so i need to set up the compiler to compile my sources, and to produce the messages so i can click and jump to the offending source files and lines. to run pc-lint with a project in eclipse means solving three problems:

  1. how to set up pc-lint as compiler for my project?
  2. how to pass options to the pc-lint compiler?
  3. how to configure the messages for the problems view?

i’m using a joint approach with eclipse build configuration , batch file and lint option files . the solution presented here is using the following steps:

  1. using a managed make build configuration
  2. setting up a batch file to call pc-lint
  3. defining the list of files
  4. specifying the options
  5. defining the message format
  6. lint it !

step 1: build configuration

to my existing project i add a managed make build configuration for pc-lint. the build configuration is set up to call a batch file. i select the project and use the menu project > build configuration > manage… and create a new configuration using the new button:

creating new build configuration

creating new build configuration

for the new configuration, i copy the settings from the existing configuration:

creating new configuration

creating new configuration

this new configuration would just use my normal compiler. instead, i want to use the lint compiler. in project > properties > c/c++ build > builder settings , i disable ‘ use default build command ‘ and use instead:

${projdirpath}\lint\do_lint.bat "${projdirpath}" "${mcutoolsbasedir}"

i’m pointing to a do_lint.bat file inside a lint folder of my project which i will create in the next step. additionally i disable ‘ generate makefiles automatically ‘:

builder settings for pc-lint batch file

builder settings for pc-lint batch file

codewarrior for mcu10.2 uses parallel builds by default. this would add -j6 as option to the command line. in order to disable this, i configure project specific settings in the build behaviour tab:

custom build behaviour

custom build behaviour

step 2: batch file

to separate the lint files from the rest of my build and project, i create a lint sub-folder inside my project root with a do_lint.bat batch file:

do_lint batch file

do_lint batch file

the do_lint.bat has following content:

@rem the arguments for this batch file: 
@rem %1: the path to the project folder
@rem %2: the path to the codewarrior installation folder
@rem ------------------------------------------------------
@rem path to my project folder
set proj_path=%1
@rem path to codewarrior installation folder (which is e.g. "c:\freescale\cw mcu v10.2\eclipse\..\mcu")
set cw_path=%2
@rem path to lint-nt.exe
set lint_exe=c:\lint\lint-nt.exe
@rem path to my lint configuration files
set local_lnt_files=c:\freescale\pc-lint\fsl_lnt
@rem path to my local lint folder inside the project
set proj_lint_path=%proj_path%\lint
@rem lint configuration files and includes
set lnt_includes=-i"%local_lnt_files%" "%local_lnt_files%\co-mwhc08.lnt" -i%local_lnt_files%
@rem --------------- run pc-lint ---------------------------
%lint_exe% %lnt_includes% %proj_lint_path%\proj_options.lnt %proj_lint_path%\proj_files.lnt -vf

the batch file is called from eclipse with two arguments (%1 and %2): with the path to the project folder and the path to the codewarrior installation folder. i assign them to local variables (proj_path and cw_path) so i can use them inside the .lnt files. to know where my lint compiler is, i use lint_exe. i store my lint configuration files outside of the pc-lint installation folder, that’s why i have defined a path variable for this: local_lint_files. proj_lint_path contains the project sub-folder with all my batch and lint files for the project. in lnt_includes i specify my compiler lint configuration file, plus where lint shall search for my lint configuration files. finally it calls the lint executable with the lint include files, plus two files: the project options (proj_options.lnt) and the project files (proj_files.lnt) . i explain these files in step 4.

step 3: list of files

i have created a file proj_files.lnt file inside my project:

file listing the files to lint

file listing the files to lint

this file has all my source files listed. and because i have defined environment variables like proj_path, i can use it here:

%proj_path%\sources\main.c 
%proj_path%\sources\events.c

step 4: passing the options

what is missing are the project specific options: i add them to the proj_options.lnt file:

project options file

project options file

in this file i add with the -i pc-lint option all the paths where it can find my files:

// include paths used
-i%proj_path%
-i%proj_path%\sources
-i%proj_path%\generated_code
-i%cw_path%\lib\hc08c\include

additionally i specify all the global options, e.g. to inhibit messages:

// inhibit messages for processor expert libraries
-elib(19, 10)
-e766
+libh(events.h, cpu.h)

step 5: defining the message format

last but not least: i need to tell pc-lint how to format the messages so they end up properly in the eclipse problems view. i add them as well to the proj_options.lnt:

// coerce messages for eclipse
-hf1
+ffn
// normally my format is defined as follows:
//-"format=%(\q%f\q %l %c%) %t %n: %m"
// for eclipse-usage, the gcc error format is necessary,
// since we have only the default eclipse error parser available.
-"format=%(%f:%l:%c:%) %t %n: %m"
// enable warning 831 if you are interested.
-frl
// do not break lines
-width(0) 
// and make sure no foreign includes change the format
+flm

step 5: linting in action

time to see how this works! as i have set up a separate build configuration to lint my files, i can run it like any other build configuration:

build my lint configuration

build my lint configuration

the example below shows several lint errors for main.c. the messages show up in the problems view, and are listed as well in the console view:

linting in action

linting in action

summary

the approach presented here does not need any other eclipse plugin. it is using a batch file, and uses a brute force approach: it will lint all files regardless if they have changed or not. this could be improved with a make file approach as outlined here . the approach presented here requires some setup, is pretty simple, and routes all lint messages to the problems view. if i want to use more of a plugin approach, then the linticator plugin is the alternative.

thanks to catherine for providing a lot of good ideas used in this article!

happy linting :-)

Lint (software) Build (game engine)

Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How to Build Real-Time BI Systems: Architecture, Code, and Best Practices
  • How To Build Resilient Microservices Using Circuit Breakers and Retries: A Developer’s Guide To Surviving
  • Accelerating Debugging in Integration Testing: An Efficient Search-Based Workflow for Impact Localization
  • MLOps: How to Build a Toolkit to Boost AI Project Performance

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!