Reporting Issues
Bug 2986 - EccCheck should not revert staged and local changes
Summary: EccCheck should not revert staged and local changes
Status: RESOLVED FIXED
Alias: None
Product: EDK2
Classification: Unclassified
Component: Test (show other bugs)
Version: Current
Hardware: All All
: High major
Assignee: Michael Kinney
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-24 15:54 UTC by Bret Barkelew
Modified: 2022-01-14 20:31 UTC (History)
4 users (show)

See Also:
EDK II Code First industry standard specifications: ---
Branch URL:
Release(s) the issue is observed: EDK II Master
The OS the target platform is running: ---
Package: N/A
Release(s) the issues must be fixed: EDK II Master
Tianocore documents:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bret Barkelew 2020-09-24 15:54:19 UTC
Right now EccCheck is destructive when it calculates a diff. EccCheck should either not be destructive, or fail to run in a dirty environment. Its current behavior may destroy work also makes it difficult to incrementally solve ECC errors.

Ideally, the "what files have changed since X" would be generalized and added to Edk2ToolLib or Edk2ToolExt, since a number of CI and PR gate checks implement their own versions of this functionality.
Comment 1 gaoliming 2020-09-29 21:44:05 UTC
Agree this issue. Bret: have you any proposal to fix this issue?
Comment 2 Bret Barkelew 2020-09-30 00:19:06 UTC
I suppose my first question would be:
Why does it do that now? Is it a bug, or intentional?
Comment 3 Matthew Carlson 2020-09-30 00:35:51 UTC
I can definitely agree that this is a pretty painful experience as a local developer. I ran CI to validate my changes and had all my changes wiped out.
Comment 4 gaoliming 2020-09-30 02:07:21 UTC
This is the implementation limitation. In open CI, ECC supports to skip some source files or directories to be scanned. Current implementation checkouts the code, then remove the skipped source files and directories, next run ECC checker to get ECC scan result, last type "git reset --hard" to restore all files. To avoid the issue to run open CI in the local environment, the developer needs to do the local commit message, then run open CI.
Comment 5 Michael Kinney 2021-11-22 17:00:14 UTC
Assign to owner
Comment 6 Michael Kinney 2021-11-22 19:10:11 UTC
There are a number of functional and performance issues with EccCheck

1) For the git state corruption issue, a design change is required.
   Instead of modifying the local git source tree to implement
   the IgnoredFiles feature, the package that will be checked with
   ECC should be copied to a temporary directory and the IgnoredFiles
   should be removed from the temporary directory.

   a) Python supports a tempfile module that can return a temporary
      directory.  This module works well when used locally, but does
      not seem to work when used with azure pipelines windows agents.
      This may be related to the use of drive letters and the drive
      letter for the sources are D: and the temporary directory
      created is on C:
   b) Instead of using python tempfile module, create a temporary
      directory in the Build output directory called ecctemp.

2) The ECC configuration file called exception.xml in 
   BaseTools/Source/Python/Ecc is updated in place with additional
   exceptions from the EccCheck tool and from the IgnoreErrors
   section of the package YAML file.  This shows up as a modified
   file by git.  Instead, make a copy of exception.xml into the
   temporary directory and update that copy with the additional
   exceptions leaving the BaseTools directory unmodified.

3) Performance issues and log size issues running the git diff
   commands.

   The git diff command is used to determine the set of modified
   directories in a package and the set of modified lines to 
   include in the scan results.  The current implementation
   redirects the git diff output to stdout, which for large
   patch sets is slow and generates a large build log file.

   The recommended solution is to use the --output of git diff
   to generate the git diff output into a file in the temporary
   directory.

4) When the ECC command line tool is run, it creates some temporary
   output files in the current working directory.  If the current 
   working directory is in one of the git repo local directories
   these temp files will show up as untracked files.

   In order to prevent the creation of untracked files, the 
   working directory when ECC is run should be set to the ecctemp
   directory in the Build output directory.  The Build output
   directory is already ignored by .gitignore.

5) Managing the temporary directory
   a) If Build/ecctemp is present when EccCheck is started, then
      remove the existing temporary directory
   b) When EccCheck exits, always remove the temporary directory.
   c) Add try/except to RunPlugin to guarantee that normal exits,
      exceptions from Keyboard Interrupt, and all unexpected exceptions
      are caught and the temp directory is removed.

6) Remove duplicate scans of same folders in GetModifyDir().
   If a lib/module has multiple directory levels and there are
   source file changes al multiple levels, then ECC will be
   invoked multiple times and will scan the same source files
   more than once.  Update GetModifyDir() to filter out these
   the redundant set of modified directories.