Skip to content

Instantly share code, notes, and snippets.

@seokbeomKim
Last active July 21, 2022 03:06
Show Gist options
  • Save seokbeomKim/04cf589c5364c0b43288956d7be9780d to your computer and use it in GitHub Desktop.
Save seokbeomKim/04cf589c5364c0b43288956d7be9780d to your computer and use it in GitHub Desktop.
vscode scripts
#!/bin/bash
# This is a script to generate a zip file containing changes in a git
# repository. Some customers require zip file of changes without any concerning
# about detail of it, looking into commit messages :(. To make it better, this
# script generates both customer's want and normaal patches.
echo 'Generate a zip-version patch ...'
GIT_ROOT=$(git rev-parse --show-toplevel)
PATCH_ROOT=./before_after_patch
cd $GIT_ROOT
mkdir -p $PATCH_ROOT/{before,after}
git diff --name-only >> $PATCH_ROOT/filelist
git diff --cached --name-only >> $PATCH_ROOT/filelist
for f in $(cat $PATCH_ROOT/filelist); do cp --parent $f $PATCH_ROOT/after; done
git stash
for f in $(cat $PATCH_ROOT/filelist); do cp --parent $f $PATCH_ROOT/before; done
FILE_NAME=$(date '+%Y%m%d_%H%M')_$(basename $(pwd)).zip
zip -9 $FILE_NAME $PATCH_ROOT/ -r
rm -rf $PATCH_ROOT/
git stash pop
echo "before-after patch is generated: $FILE_NAME"
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/include",
"${workspaceFolder}/arch/arm/include",
"${workspaceFolder}/arch/arm/include/generated",
"${workspaceFolder}/arch/arm64/include",
"${workspaceFolder}/arch/arm64/include/generated",
],
"forcedInclude": [
"${workspaceFolder}/include/generated/autoconf.h"
],
"defines": [
"__KERNEL__"
],
"cStandard": "c11",
"intelliSenseMode": "gcc-x64",
"compileCommands": "${workspaceFolder}/compile_commands.json"
}
],
"version": 4
}
from __future__ import print_function, division
import fnmatch
import json
import math
import multiprocessing
import os
import re
import sys
CMD_VAR_RE = re.compile(r'^\s*cmd_(\S+)\s*:=\s*(.+)\s*$', re.MULTILINE)
SOURCE_VAR_RE = re.compile(r'^\s*source_(\S+)\s*:=\s*(.+)\s*$', re.MULTILINE)
directory = os.path.abspath(os.getcwd())
def print_progress_bar(progress):
progress_bar = '[' + '|' * \
int(50 * progress) + '-' * int(50 * (1.0 - progress)) + ']'
print('\r', progress_bar, "{0:.1%}".format(
progress), end='\r', file=sys.stderr)
def parse_cmd_file(cmdfile_path):
with open(cmdfile_path, 'r') as cmdfile:
cmdfile_content = cmdfile.read()
commands = {match.group(1): match.group(2)
for match in CMD_VAR_RE.finditer(cmdfile_content)}
sources = {match.group(1): match.group(2)
for match in SOURCE_VAR_RE.finditer(cmdfile_content)}
return [{
'directory': directory,
'command': commands[o_file_name],
'file': source,
'output': o_file_name
} for o_file_name, source in sources.items()]
def main():
print("Building *.o.cmd file list...", file=sys.stderr)
cmd_files = []
for cur_dir, subdir, files in os.walk(directory):
cmd_files.extend(os.path.join(cur_dir, cmdfile_name)
for cmdfile_name in fnmatch.filter(files, '*.o.cmd'))
print("Parsing *.o.cmd files...", file=sys.stderr)
n_processed = 0
print_progress_bar(0)
compdb = []
pool = multiprocessing.Pool()
try:
for compdb_chunk in pool.imap_unordered(parse_cmd_file, cmd_files, chunksize=int(math.sqrt(len(cmd_files)))):
compdb.extend(compdb_chunk)
n_processed += 1
print_progress_bar(n_processed / len(cmd_files))
finally:
pool.terminate()
pool.join()
print(file=sys.stderr)
print("Writing compile_commands.json...", file=sys.stderr)
with open('compile_commands.json', 'w') as compdb_file:
json.dump(compdb, compdb_file, indent=1)
if __name__ == '__main__':
main()
#!/bin/bash
# This is a script to prepare tagging information for vscode. To configure
# correctly, kernel project must be compiled before running this script
echo "Create .vscode"
mkdir -p .vscode
cd .vscode
wget https://gist.githubusercontent.com/seokbeomKim/04cf589c5364c0b43288956d7be9780d/raw/24354aa356f9736ca49cc8e745b2b3267035f998/c_cpp_properties.json
# from amezin/vscode-linux-kernel
wget https://gist.githubusercontent.com/seokbeomKim/04cf589c5364c0b43288956d7be9780d/raw/5869725e63ac463bac5b922514059522ee607975/generate_compdb.py
wget https://gist.githubusercontent.com/seokbeomKim/04cf589c5364c0b43288956d7be9780d/raw/28ccc87fbe8b044f864ada7c00db81caa649f72e/launch.json
wget https://gist.githubusercontent.com/seokbeomKim/04cf589c5364c0b43288956d7be9780d/raw/6481fce04d97b4a95697919eba72645c99d105e8/tasks.json
cd ..
if [ -z "$(which python3)" ]; then
echo "python3 is not installed"
exit 1
fi
# python3 .vscode/generate_compdb.py
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) linux",
"type": "cppdbg",
"request": "launch",
"preLaunchTask": "vm",
"program": "${workspaceRoot}/vmlinux",
"miDebuggerServerAddress": "localhost:1234",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerArgs": "-n",
"targetArchitecture": "x64",
"setupCommands": [
{
"text": "set arch i386:x86-64:intel",
"ignoreFailures": false
},
{
"text": "dir .",
"ignoreFailures": false
},
{
"text": "add-auto-load-safe-path ./",
"ignoreFailures": false
},
{
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "vm",
"type": "shell",
"command": "virsh start Example --console --autodestroy --paused",
"presentation": {
"echo": false,
"clear": true,
"group": "vm"
},
"isBackground": true,
"problemMatcher": [
{
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": ".",
"endsPattern": ".",
}
}
]
},
{
"label": "build",
"type": "shell",
"command": "make",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": false,
"group": "build"
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment