From a2d7ab5fdcac6e3a3a3f6e8d4474b975cbba2858 Mon Sep 17 00:00:00 2001 From: Nils Dijk Date: Tue, 1 Aug 2023 14:59:27 +0000 Subject: [PATCH] generate c_cpp_properties based on installed postgres versions --- .devcontainer/.vscode/Pipfile | 12 +++ .devcontainer/.vscode/Pipfile.lock | 28 +++++++ .../.vscode/generate_c_cpp_properties-json.py | 80 +++++++++++++++++++ .devcontainer/Dockerfile | 3 +- .devcontainer/Makefile | 2 +- .devcontainer/devcontainer.json | 1 + 6 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 .devcontainer/.vscode/Pipfile create mode 100644 .devcontainer/.vscode/Pipfile.lock create mode 100755 .devcontainer/.vscode/generate_c_cpp_properties-json.py diff --git a/.devcontainer/.vscode/Pipfile b/.devcontainer/.vscode/Pipfile new file mode 100644 index 000000000..d59a36a41 --- /dev/null +++ b/.devcontainer/.vscode/Pipfile @@ -0,0 +1,12 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +docopt = "*" + +[dev-packages] + +[requires] +python_version = "3.10" diff --git a/.devcontainer/.vscode/Pipfile.lock b/.devcontainer/.vscode/Pipfile.lock new file mode 100644 index 000000000..26eb15ece --- /dev/null +++ b/.devcontainer/.vscode/Pipfile.lock @@ -0,0 +1,28 @@ +{ + "_meta": { + "hash": { + "sha256": "5906b8027becd04da3d9bb9747c503339361f5ab52d8f83078f6abbde6a37440" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.10" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "docopt": { + "hashes": [ + "sha256:49b3a825280bd66b3aa83585ef59c4a8c82f2c8a522dbe754a8bc8d08c85c491" + ], + "index": "pypi", + "version": "==0.6.2" + } + }, + "develop": {} +} diff --git a/.devcontainer/.vscode/generate_c_cpp_properties-json.py b/.devcontainer/.vscode/generate_c_cpp_properties-json.py new file mode 100755 index 000000000..a1816d711 --- /dev/null +++ b/.devcontainer/.vscode/generate_c_cpp_properties-json.py @@ -0,0 +1,80 @@ +#! /usr/bin/env pipenv-shebang +"""Generate C/C++ properties file for VSCode. + +Uses pgenv to iterate postgres versions and generate +a C/C++ properties file for VSCode containing the +include paths for the postgres headers. + +Usage: + generate_c_cpp_properties-json.py + generate_c_cpp_properties-json.py (-h | --help) + generate_c_cpp_properties-json.py --version + +Options: + -h --help Show this screen. + --version Show version. + +""" +from docopt import docopt +import subprocess +import json + +def main(args): + target_path = args[''] + + output = subprocess.check_output(['pgenv', 'versions']) + # typical output is: + # 14.8 pgsql-14.8 + # * 15.3 pgsql-15.3 + # 16beta2 pgsql-16beta2 + # where the line marked with a * is the currently active version + # + # we are only interested in the first word of each line, which is the version number + # thus we strip the whitespace and the * from the line and split it into words + # and take the first word + versions = [line.strip('* ').split()[0] for line in output.decode('utf-8').splitlines()] + + # create the list of configurations per version + configurations = [] + for version in versions: + configurations.append(generate_configuration(version)) + + # create the json file + c_cpp_properties = { + "configurations": configurations, + "version": 4 + } + + # write the c_cpp_properties.json file + with open(target_path, 'w') as f: + json.dump(c_cpp_properties, f, indent=4) + +def generate_configuration(version): + """Returns a configuration for the given postgres version. + + >>> generate_configuration('14.8') + { + "name": "Citus Development Configuration - Postgres 14.8", + "includePath": [ + "/usr/local/include", + "/home/citus/.pgenv/src/postgresql-14.8/src/**", + "${workspaceFolder}/**", + "${workspaceFolder}/src/include/", + ], + "configurationProvider": "ms-vscode.makefile-tools" + } + """ + return { + "name": f"Citus Development Configuration - Postgres {version}", + "includePath": [ + "/usr/local/include", + f"/home/citus/.pgenv/src/postgresql-{version}/src/**", + "${workspaceFolder}/**", + "${workspaceFolder}/src/include/", + ], + "configurationProvider": "ms-vscode.makefile-tools" + } + +if __name__ == '__main__': + arguments = docopt(__doc__, version='0.1.0') + main(arguments) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 7d93a53cc..d0b321787 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -104,8 +104,9 @@ RUN sudo pip3 install pipenv WORKDIR /workspaces/citus/ COPY src/ src/ -RUN ls -al +COPY .vscode/Pipfile .vscode/Pipfile.lock .devcontainer/.vscode/ RUN ( cd src/test/regress && pipenv install ) +RUN ( cd .devcontainer/.vscode && pipenv install ) # assemble the final container by copying over the artifacts from separately build containers FROM base AS devcontainer diff --git a/.devcontainer/Makefile b/.devcontainer/Makefile index b105d9172..afe57fea1 100644 --- a/.devcontainer/Makefile +++ b/.devcontainer/Makefile @@ -8,4 +8,4 @@ init: ../.vscode/c_cpp_properties.json ../.vscode/launch.json cp .vscode/launch.json ../.vscode/launch.json ../.vscode/c_cpp_properties.json: ../.vscode - cp .vscode/c_cpp_properties.json ../.vscode/c_cpp_properties.json + ./.vscode/generate_c_cpp_properties-json.py ../.vscode/c_cpp_properties.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ab01f7787..e81f35428 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -10,6 +10,7 @@ "vscode": { "extensions": [ "eamodio.gitlens", + "GitHub.copilot", "github.vscode-pull-request-github", "ms-vscode.cpptools-extension-pack", "ms-vsliveshare.vsliveshare",