Friday, September 30, 2022

Visual Studio: Disable Map Mode

In the blog post, Visual Studio Code: Disabling the Minimap, it was demonstrated how to disable the minimap feature in Visual; Studio Code. Minimap consumes screen real estate that could be used for viewing code. Microsoft chose to add the minimap feature to Visual Studio (starting with Visual Studio 2019) and called it Map Mode. This post demonstrates how to disable Map Mode in Visual Studio.

Below is an example of the traditional, Visual Studio, vertical scrollbar being replaced with a Map Mode vertical scrollbar:



To disable Map Mode, open Visual Studio and navigate to: 
    Tools | Options | Text Editor | All Languages | Scroll Bars

Navigating as described above will display the following:


Note above that the radio button, "Use map mode for vertical scroll bar" is selected, and "Use bar mode for vertical scroll bar" is not selected. To disable Map Mode, simply select "Use bar mode for vertical scroll bar" (see below) which deselects "Use map mode for vertical scroll bar":


Click on Ok in the previous dialog to finalize the disabling of Map Mode in Visual Studio.

Once Map Mode is disabled, the standard coding windows in Visual Studio appear as follows with a traditional scroll bar:


Microsoft's Justification for Map Mode

Microsoft's Visual Studio documentation, How to: Customize the scroll bar, includes a justification for the use of Map Mode. The following snippet is part of the aforementioned documentation and demonstrates a use of Map Mode namely how to identify find and replace locations throughout an entire source file:


Eight percent of males are color blind (1 in 12) and Microsoft has added a useful feature, Map Mode, the relies on the colors red and green. Map Mode reduces the amount of code visible in Visual Studio and is biased against a large number of developers with a rather well-documented disability.

The other blog posts that are addressed being color blind include:
I would much rather spend time developing code than working around "features" that demonstrate a bias against those who are color blind.


Sunday, September 11, 2022

C#: xUnit Testing Constructor Exceptions

xUnit's Assert class implements the following methods that test whether or not a method throws an exception:


 

The Throws method signatures that take a parameter of type Action are used to test methods that return no value (void). The Throws method signatures that take a parameter of type Func are used to test methods that return a value. In order to test a constructor that throws an exception, a lambda expression is required such as:

Assert.Throws<ArgumentException>(
    () => new AnyClass());

Assert.Throws<ArgumentException>(
    () => new AnyClass("some paramter", 123, DateTime.Now));

The lambda expressions above return no values, so the Throws method that takes an Action parameter is invoked by the above code (public static T Throws<T>(Action testCode) where T : Exception).






 




Friday, September 9, 2022

Git: Get Submodules from an already Cloned Repo

A git repo that contains a submodule or modules is cloned using the --recurse-submodules command-line option such as the following:

git clone --recurse-submodules -j8 git://github.com/foo/bar.git

At one time or another, every developer has performed a git clone and forgotten the --recurse-submodules command-line option. The following git command will remedy this problem but updating the submodules for a git repo ever in the case where the git clone was performed without specifying --recurse-submodules:

git submodule update --init --recursive


Sunday, September 4, 2022

cmake: ExternalProject_Add Ignore the INSTALL_COMMAND

The cmake function ExternalProject_Add  is documented at ExternalProject. There are circumstances when ExternalProject_Add's install command needs to be disabled.  The simplest way to disable the install command is to set the parameter to an empty string as follows: 

ExternalProject_Add(example_package
  SOURCE_DIR ${example_package_CMAKE}
  BUILD_COMMAND "cmake"
  INSTALL_COMMAND ""
)

A better solution is to write a message to the build output indicating that the install command has been disabled:

ExternalProject_Add(example_package
  SOURCE_DIR ${example_package_CMAKE}
  BUILD_COMMAND "cmake"
  INSTALL_COMMAND cmake -E echo "example_package: temporarily skipping install step."
)

Docker/Ubuntu: Installing the latest cmake on Docker Image

This post demonstrates how to install the latest version of cmake during docker build targetting an Ubuntu 20.04 image. The Dockerfile for such an image starts with:

FROM ubuntu:20.04

A previous post, Ubuntu: Upgrade to the latest cmake, demonstrated the bash commands that could be used to install the latest version of cmake on an Ubuntu 20.04.4 LTS image. Fundamentally these are the same commands that could be used to install cmake on a Docker image during build. From the previously demonstrated script, the sudo commands were removed a few additional apt-get commands are required.

A sample Dockerfile that installs the latest cmake (currently 3.24.1) on an Ubuntu 20.04 image is follows:

FROM ubuntu:20.04


# Put your own Dockfile commands here

RUN apt-get update \
  && apt-get -y install build-essential \
  && apt-get install -y wget \
  && rm -rf /var/lib/apt/lists/* \
  && wget https://github.com/Kitware/CMake/releases/download/v3.24.1/cmake-3.24.1-Linux-x86_64.sh \
      -q -O /tmp/cmake-install.sh \
      && chmod u+x /tmp/cmake-install.sh \
      && mkdir /opt/cmake-3.24.1 \
      && /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-3.24.1 \
      && rm /tmp/cmake-install.sh \
      && ln -s /opt/cmake-3.24.1/bin/* /usr/local/bin


# Put your own Dockfile commands here

Ubuntu/Azure: Upgrade an Ubuntu 20.04.4 LTS VM to the latest cmake

This post demonstrates how to install the latest version of cmake on an Azure Ubuntu 20.04.4 LTS virtual machine (VM).

In the post, Ubuntu: Upgrade to the latest cmake, the steps required to install the latest version of cmake on Ubuntu 20.04.4 LTS were presented. These aforementioned steps apply to environments like running Ubuntu under WSL where the native Ubuntu image was used to create the virtual machine or image. Multiple bash commands were required to install cmake and similarly, the uninstall required multiple bash commands.

Azures Ubuntu 20.04.4 LTS VMs contain additional packages to that of a stock Ubuntu image. These packages include Snap, a popular package manager. Using Snap the latest version of cmake can be installed as follows:

sudo snap install cmake --classic

The output from the above install steps is shown below where the version of cmake (3.24.1) is displayed during installation:


Be warned:

Using apt-get to install cmake will get Ubuntu's version of cmake which is not the latest version of cmake. This means that features like DOWNLOAD_NO_EXTRACT will not be available to cmake.

The steps to uninstall cmake using the snap command are as follows:

sudo snap remove cmake

Appendix A: Snap

For those new to snap (see Snap (software)):







Friday, September 2, 2022

Ubuntu: Upgrade to the latest cmake

Ubuntu 20.04.4 LTS allows cmake to be installed as follows using -y to suppress the prompt:

sudo apt-get update && sudo apt-get install -y cmake

The cmake installed is not the latest version as can be seen using cmake --version:


To install the latest version of cmake, first uninstall cmake (if it is already installed and that it was installed using apt-get):

sudo apt-get remove -y cmake


Latest cmake Install

The cmake releases can be found at:

https://github.com/Kitware/CMake/releases

The following script downloads and installs a specific version of cmake (version 3.24.1):

wget https://github.com/Kitware/CMake/releases/download/v3.24.1/cmake-3.24.1-Linux-x86_64.sh \
  -q -O /tmp/cmake-install.sh \
&& chmod u+x /tmp/cmake-install.sh \
&& sudo mkdir /opt/cmake-3.24.1 \
&& sudo /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-3.24.1 \
&& rm /tmp/cmake-install.sh \
&& sudo ln -s /opt/cmake-3.24.1/bin/* /usr/local/bin

To verify the correct version of cmake is installed invoke cmake --version:


cmake Uninstall

Obviously "sudo apt-get remove -y cmake" cannot be used to uninstall cmake installed via cmake-install.sh.

The following steps uninstall cmake, be versing the steps used to install cmake above which used cmake-install.sh to install cmake:

pushd . \
&& cd /usr/local/bin \
&& ls /opt/cmake-3.24.1/bin | \
  sudo xargs rm \
&& sudo rm -rf /opt/cmake-3.24.1 \
&& popd