Skip to content

Commit

Permalink
add helper script for confing vscode + cmake to use a host config (#691)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrush committed Feb 4, 2021
1 parent c038ef3 commit 0a2b6a4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ conduit.docker.src.tar
conduit.docker.src.tar.gz
Testing/
.idea
.vscode/settings.json
4 changes: 4 additions & 0 deletions .vscode/settings_common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cmake.configureOnOpen": true,
"cmake.sourceDirectory": "${workspaceFolder}/src"
}
56 changes: 56 additions & 0 deletions scripts/config_vscode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (c) Lawrence Livermore National Security, LLC and other Conduit
# Project developers. See top-level LICENSE AND COPYRIGHT files for dates and
# other details. No copyright assignment is required to contribute to Conduit.

import sys
import json
import os

from optparse import OptionParser

def parse_args():
"Parses args from command line"
parser = OptionParser()
parser.add_option("--args",
dest="cmake_args",
default=None,
help="cmake arguments")
parser.add_option("--host-config",
dest="host_config",
default=None,
help="path to host config file")
opts, extras = parser.parse_args()
# we want a dict b/c
opts = vars(opts)
return opts, extras


def write_vscode_settings(settings):
settings_file = os.path.abspath(".vscode/settings.json")
print("[creating: {0}]".format(settings_file))
print("[contents]")
print(json.dumps(settings, indent=2))
open(settings_file, "w").write(json.dumps(settings, indent=2))

def gen_vscode_settings(opts):
settings_comm_file = os.path.abspath(".vscode/settings_common.json")
res = {}
if os.path.isfile(settings_comm_file):
res = json.load(open(settings_comm_file))
else:
print("[warning: {0} not found]".format(settings_comm_file))

if not opts["cmake_args"] is None:
res["cmake.configureArgs"] = [opts["cmake_args"]]
if not opts["host_config"] is None:
res["cmake.cacheInit"] = [opts["host_config"]]

return res

def main():
opts, extras = parse_args()
settings = gen_vscode_settings(opts)
write_vscode_settings(settings)

if __name__ == "__main__":
main()

0 comments on commit 0a2b6a4

Please sign in to comment.