Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile save function sets the PROJ variable in the Makefile to the actual name the project was saved with. #260

Closed
wants to merge 8 commits into from

Conversation

elmbeech
Copy link
Contributor

@elmbeech elmbeech commented Jun 9, 2024

This pull request is written on top of pull request #244 and addresses issue #222 .
What the pull request solves:

The Makefile save function now sets the PROJ variable in the Makefile to the actual name the project was saved with.

Before when e.g. a project was saved with

make save PROJ=abc

the save project had his PROJ variable still set to

PROJ := my_project

or whatever the PROJ variable was set before.
Now the saved project will have set the PROJ variable correctely to

PROJ := abc

as it should be.

This is a crucial change because it will prevent users from down the road overwriting accidentally the original project from which the newly saved project was derived from.

@rheiland, because this changes use a sed command, cloud you, please check if this works on the Windows bash shell and on MacOSX zsh shell? That would be very helpful!

…project config and custom_modules with a folder structure.
…ith the config and custome_modules deep folder structure.
…ble with the config and custome_modules deep folder structure.
…gs.xml-default instead of config/PhysiCell_settings-backup.xml to restore initial condition.
@elmbeech elmbeech changed the title Patch proj name Makefile save function sets the PROJ variable in the Makefile to the actual name the project was saved with. Jun 9, 2024
@rheiland
Copy link
Collaborator

The sed command does indeed seem to work on my Windows machine. But I'm still a bit confused. When I did make save PROJ=foo, it updates the Makefile in the foo user_project, but wouldn't you also want to update the root's Makefile so that one could then just do make save and have it update the foo user_project?

@drbergman
Copy link
Contributor

Looks like a very thorough set of changes and a nifty way to make it easier to use make save. I see you're also including make clean inside make reset. Did I miss the conclusion of #212?

@elmbeech
Copy link
Contributor Author

elmbeech commented Jun 11, 2024

@rheiland, that is a good point. I can do the change to the Makefiles before I copy to the users_project folder.

@drbergman , there was no "conclusion" you just expressed your opinion.
if you do a reset, to work on a new PhysiCell project, it could simply cause errors if you have binaries or compiled libraries lying around from a project you worked before. or can you name me a PhysiCell project you work on, you still want to have the binaries and libraries around after a reset? since I had to rewrite the whole function, I attempted to write a reset function as clean as possible. and as I wrote in #212, it will not break your habits. you can do make clean, as much as you want, make clean reset as much as you want, and you can make rest as much as you want.

@rheiland
Copy link
Collaborator

On my Mac, the native sed fails:

M1P~/dev/PhysiCell-patch_proj_name$ make save PROJ=foo
echo "Saving project as foo ... "
Saving project as foo ... 
mkdir -p ./user_projects
mkdir -p ./user_projects/foo
mkdir -p ./user_projects/foo/custom_modules
mkdir -p ./user_projects/foo/config 
cp main.cpp ./user_projects/foo
cp Makefile ./user_projects/foo
sed -i "0,/PROJ := /{s/PROJ := .*/PROJ := foo/}" ./user_projects/foo/Makefile
sed: 1: "./user_projects/foo/Mak ...": invalid command code .
make: *** [save] Error 1

I remember now that for a past project, I had to brew install the gnu sed to do what I wanted.

So this sed-related PR, as is, should not be merged.

@elmbeech
Copy link
Contributor Author

elmbeech commented Jun 11, 2024

yes @rheiland, this is the exact same error we had last time.
I wonder if it is related to zsh. will track this down.
thank you for the report!

I think we should not have the user to install a specific sed.
I hope to find a way to get this running with both sed flavors.

@elmbeech
Copy link
Contributor Author

reading up on the subject, this might work on the native Mac, but does not work on linux, and maybe as well not on a Mac with gnu-sed installed ...

sed -i '' -e "0,/PROJ := /{s/PROJ := .*/PROJ := def/}" ./user_projects/def/Makefile

I will search further.

@elmbeech
Copy link
Contributor Author

well, we would have to figure out if the GNU sed or the BSD sed is installed.
this is getting awkward - so I will to try to find a way to achive the same with awk, hoping the GNU and the BSD awk will behave the same, and hoping that awk is installed on Windows.

@elmbeech
Copy link
Contributor Author

elmbeech commented Jun 11, 2024

this awk line should do the same:

awk -i inplace '{gsub("^PROJ :=.*$$", "PROJ := $(PROJ)", $$0); print $$0}' Makefile

I will update the code with the changes discussed, let you know when it is done, and would be happy if you then can check again.

…instead of sed, to be hopefully compatible with all supported platforms and unix flavors.
@elmbeech
Copy link
Contributor Author

@rheiland i just pushed the changes.
could you please give another try?

@rheiland
Copy link
Collaborator

On my Mac, native awk fails:

(base) M1P~/git/elmar_patch_proj_name$ make save PROJ=hetero
echo "Saving project as hetero ... "
Saving project as hetero ... 
mkdir -p ./user_projects
mkdir -p ./user_projects/hetero
mkdir -p ./user_projects/hetero/custom_modules
mkdir -p ./user_projects/hetero/config 
cp main.cpp ./user_projects/hetero
awk -i inplace '{gsub("^PROJ :=.*$", "PROJ := hetero", $0); print $0}' Makefile
awk: unknown option -i ignored

awk: can't open file {gsub("^PROJ :=.*$", "PROJ := hetero", $0); print $0}
 source line number 1
make: *** [save] Error 2
(base) M1P~/git/elmar_patch_proj_name$ which awk
/usr/bin/awk
(base) M1P~/git/elmar_patch_proj_name$ awk --version
awk version 20200816

@elmbeech
Copy link
Contributor Author

why the heck Berkeley Software Distribution?

@elmbeech
Copy link
Contributor Author

at least on Windows it seems to work.
Will try to work on a workaround that works on all OSes.

@MathCancer
Copy link
Owner

MathCancer commented Jun 23, 2024

I don't understand the purpose of this PR and change.

I think it's a bad idea to overwrite the Makefile.

PROJ defaults to my_project unless you use a command-line argument. The command line argument always works. What problem are we trying to solve here?

Right now, the design and default behavior is to default to my_project unless specified at command line. Yes, this has to be specified every time you save.

In that sense, the original PR is incorrect, because you are in fact not fixing a bug. It is functioning exactly as intended.

Is your intention that once a user sets PROJ that subsequent saves always save to the same project, until the user sets a new project name? You haven't actually stated a design rationale for this PR.

Please give a design goal/justification for the complex change you are trying to work through.

Please also consider simpler workarounds (with more cross-platform robustness) than writing to the Makefile (e.g., writing to a text file __PROJECT_NAME__ in the root directory. If that file exists, we use that. If that file does not, we use PROJ := my_project. You could consider a new makefile rule set project_name PROJ=abc to create this file, and unset project_name to remove it, for example.

@elmbeech
Copy link
Contributor Author

ok. I think you understood what my intention was.

i always understood a

  • make save PROJ=abc as save as
  • make save as save
    obviously, this is not how you want to run things.

(look in now over the whole Makefile, i wonder why we actually have two variables PROGRAM_NAME and PROJ. Would it not simplify things, if this was one single variable?)

anyhow, I will drop this pull request but keep the #244 pull request alive, which solves the deep folder structure.

thank you, Elmar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants