Skip to content

Commit

Permalink
Fix #60, Entry point file name default
Browse files Browse the repository at this point in the history
Signed-off-by: paulober <[email protected]>
  • Loading branch information
paulober committed Sep 10, 2024
1 parent 198c6ec commit 47965ac
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
20 changes: 11 additions & 9 deletions scripts/pico_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ def ParseCommandLine():
parser.add_argument("-g", "--gui", action='store_true', help="Run a GUI version of the project generator")
parser.add_argument("-p", "--project", action='append', help="Generate projects files for IDE. Options are: vscode")
parser.add_argument("-r", "--runFromRAM", action='store_true', help="Run the program from RAM rather than flash")
parser.add_argument("-e", "--entryProjName", action='store_true', help="Use project name as entry point file name")
parser.add_argument("-uart", "--uart", action='store_true', default=1, help="Console output to UART (default)")
parser.add_argument("-nouart", "--nouart", action='store_true', default=0, help="Disable console output to UART")
parser.add_argument("-usb", "--usb", action='store_true', help="Console output to USB (disables other USB functionality")
Expand All @@ -471,12 +472,13 @@ def ParseCommandLine():
return parser.parse_args()


def GenerateMain(folder, projectName, features, cpp):
def GenerateMain(folder, projectName, features, cpp, wantEntryProjName):

executableName = projectName if wantEntryProjName else "main"
if cpp:
filename = Path(folder) / (projectName + '.cpp')
filename = Path(folder) / (executableName + '.cpp')
else:
filename = Path(folder) / (projectName + '.c')
filename = Path(folder) / (executableName + '.c')

file = open(filename, 'w')

Expand Down Expand Up @@ -669,15 +671,14 @@ def GenerateCMake(folder, params):
file.write(f'add_compile_definitions({c} = {v})\n')
file.write('\n')

# No GUI/command line to set a different executable name at this stage
executableName = projectName
entry_point_file_name = projectName if params['wantEntryProjName'] else "main"

if params['wantCPP']:
file.write(f'add_executable({projectName} {projectName}.cpp )\n\n')
file.write(f'add_executable({projectName} {entry_point_file_name}.cpp )\n\n')
else:
file.write(f'add_executable({projectName} {projectName}.c )\n\n')
file.write(f'add_executable({projectName} {entry_point_file_name}.c )\n\n')

file.write(f'pico_set_program_name({projectName} "{executableName}")\n')
file.write(f'pico_set_program_name({projectName} "{projectName}")\n')
file.write(f'pico_set_program_version({projectName} "0.1")\n\n')

if params['wantRunFromRAM']:
Expand Down Expand Up @@ -1142,7 +1143,7 @@ def DoEverything(parent, params):
features_and_examples = list(stdlib_examples_list.keys()) + features_and_examples

if not (params['wantConvert']):
GenerateMain(projectPath, params['projectName'], features_and_examples, params['wantCPP'])
GenerateMain(projectPath, params['projectName'], features_and_examples, params['wantCPP'], params['wantEntryProjName'])

# If we have any ancilliary files, copy them to our project folder
# Currently only the picow with lwIP support needs an extra file, so just check that list
Expand Down Expand Up @@ -1323,6 +1324,7 @@ def DoEverything(parent, params):
'projects' : args.project,
'configs' : (),
'wantRunFromRAM': args.runFromRAM,
'wantEntryProjName': args.entryProjName,
'wantExamples' : args.examples,
'wantUART' : args.uart,
'wantUSB' : args.usb,
Expand Down
13 changes: 13 additions & 0 deletions src/webview/newProjectPanel.mts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ interface SubmitMessageValue extends ImportProjectMessageValue {
// code generation options
addExamples: boolean;
runFromRAM: boolean;
entryPointProjectName: boolean;
cpp: boolean;
cppRtti: boolean;
cppExceptions: boolean;
Expand Down Expand Up @@ -156,6 +157,7 @@ enum PicoWirelessOption {
enum CodeOption {
addExamples = "Add examples from Pico library",
runFromRAM = "Run the program from RAM rather than flash",
entryPointProjectName = "Use project name as entry point file name",
cpp = "Generate C++ code",
cppRtti = "Enable C++ RTTI (Uses more memory)",
cppExceptions = "Enable C++ exceptions (Uses more memory)",
Expand Down Expand Up @@ -235,6 +237,8 @@ function enumToParam(
return "-x";
case CodeOption.runFromRAM:
return "-r";
case CodeOption.entryPointProjectName:
return "-e";
case CodeOption.cpp:
return "-cpp";
case CodeOption.cppRtti:
Expand Down Expand Up @@ -1090,6 +1094,9 @@ export class NewProjectPanel {
codeOptions: [
theData.addExamples ? CodeOption.addExamples : null,
theData.runFromRAM ? CodeOption.runFromRAM : null,
theData.entryPointProjectName
? CodeOption.entryPointProjectName
: null,
theData.cpp ? CodeOption.cpp : null,
theData.cppRtti ? CodeOption.cppRtti : null,
theData.cppExceptions ? CodeOption.cppExceptions : null,
Expand Down Expand Up @@ -1931,6 +1938,12 @@ export class NewProjectPanel {
<label for="run-from-ram-code-gen-cblist" class="w-full py-3 ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">Run the program from RAM rather than flash</label>
</div>
</li>
<li class="w-full border-b border-gray-200 sm:border-b-0 sm:border-r dark:border-gray-600">
<div class="flex items-center pl-3">
<input id="entry-project-name-code-gen-cblist" type="checkbox" value="" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-700 dark:focus:ring-offset-gray-700 focus:ring-2 dark:bg-gray-600 dark:border-gray-500" checked>
<label for="entry-project-name-code-gen-cblist" class="w-full py-3 ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">Use project name as entry point file name</label>
</div>
</li>
</ul>
<ul class="items-center w-full text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-lg sm:flex dark:bg-gray-700 dark:border-gray-600 dark:text-white">
<li class="w-full border-b border-gray-200 sm:border-b-0 sm:border-r dark:border-gray-600">
Expand Down
2 changes: 2 additions & 0 deletions web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ var exampleSupportedBoards = [];
// code-gen options
const addExamplesCodeGen = document.getElementById('add-examples-code-gen-cblist').checked;
const runFromRamCodeGen = document.getElementById('run-from-ram-code-gen-cblist').checked;
const nameEntryPointProjectName = document.getElementById('entry-project-name-code-gen-cblist').checked;
const cppCodeGen = document.getElementById('cpp-code-gen-cblist').checked;
const cppRttiCodeGen = document.getElementById('cpp-rtti-code-gen-cblist').checked;
const cppExceptionsCodeGen = document.getElementById('cpp-exceptions-code-gen-cblist').checked;
Expand Down Expand Up @@ -403,6 +404,7 @@ var exampleSupportedBoards = [];
// code-gen options
addExamples: addExamplesCodeGen,
runFromRam: runFromRamCodeGen,
entryPointProjectName: nameEntryPointProjectName,
cpp: cppCodeGen,
cppRtti: cppRttiCodeGen,
cppExceptions: cppExceptionsCodeGen,
Expand Down
8 changes: 8 additions & 0 deletions web/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class State {
picoWirelessSelection;
addExamplesCodeGen;
runFromRamCodeGen;
entryProjectNameCodeGen;
cppCodeGen;
cppRttiCodeGen;
cppExceptionsCodeGen;
Expand Down Expand Up @@ -138,6 +139,10 @@ function restoreState(state) {
document.getElementById('run-from-ram-code-gen-cblist').checked = state.runFromRamCodeGen;
}

if (state.entryProjectNameCodeGen !== undefined) {
document.getElementById('entry-project-name-code-gen-cblist').checked = state.entryProjectNameCodeGen;
}

if (state.cppCodeGen !== undefined) {
document.getElementById('cpp-code-gen-cblist').checked = state.cppCodeGen;
}
Expand Down Expand Up @@ -432,6 +437,9 @@ function setupStateSystem(vscode) {
case "run-from-ram-code-gen-cblist":
state.runFromRamCodeGen = checkbox.checked;
break;
case "entry-project-name-code-gen-cblist":
state.entryProjectNameCodeGen = checkbox.checked;
break;
case "cpp-code-gen-cblist":
state.cppCodeGen = checkbox.checked;
break;
Expand Down

0 comments on commit 47965ac

Please sign in to comment.