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

Adjust sed arguments for compatibility with BSD sed #177

Merged
merged 1 commit into from
Jul 4, 2023

Conversation

bacam
Copy link
Collaborator

@bacam bacam commented Aug 17, 2022

We don't need the generated backup files, but it appears to be the only
way to be compatible with both GNU and BSD sed.

Makefile Outdated
@@ -276,7 +276,7 @@ rvfi_preserve_fns=-c_preserve rvfi_set_instr_packet \
generated_definitions/c/riscv_rvfi_model_$(ARCH).c: $(SAIL_RVFI_SRCS) model/main.sail Makefile
mkdir -p generated_definitions/c
$(SAIL) $(rvfi_preserve_fns) $(SAIL_FLAGS) -O -Oconstant_fold -memo_z3 -c -c_include riscv_prelude.h -c_include riscv_platform.h -c_no_main $(SAIL_RVFI_SRCS) model/main.sail -o $(basename $@)
sed -i -e '/^[[:space:]]*$$/d' $@
sed -i.bak -e '/^[[:space:]]*$$/d' $@
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sed -i.bak -e '/^[[:space:]]*$$/d' $@
sed -i '' -e '/^[[:space:]]*$$/d' $@

If a zero-length extension is given, no backup will be saved.

Copy link
Collaborator

@Alasdair Alasdair Aug 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would double check if -i '' works with GNU sed, I think it may not. -i'' would without the space I think

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're mutually incompatible, unfortunately.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you could use perl to do the same thing? I guess most systems will have it and it might be more portable?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sed -e '/^[[:space:]]*$$/d' $@ > $@.new
mv $@.new $@

is a common portable way to get around the -i importability

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thoughts using sed and having the backups is probably best.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrtc27 's method is the only true POSIX way... in any case, this discussion has convinced me that a comment is necessary to avoid future pain.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

@github-actions
Copy link

github-actions bot commented Aug 17, 2022

Unit Test Results

712 tests  ±0   712 ✔️ ±0   0s ⏱️ ±0s
    6 suites ±0       0 💤 ±0 
    1 files   ±0       0 ±0 

Results for commit 4a33b45. ± Comparison against base commit 5c12d94.

♻️ This comment has been updated with latest results.

@scottj97
Copy link
Contributor

scottj97 commented Aug 17, 2022

If you don't need the generated backup files, why not just remove the -i completely?

@abukharmeh
Copy link
Contributor

If you don't need the generated backup files, why not just remove the -i completely?

image

@scottj97
Copy link
Contributor

Right, sorry. Brain fart.

@ptomsich
Copy link
Collaborator

While it looks good to me, we have 5 reviewers already assigned ... anyone willing to approve?

@ptomsich ptomsich self-requested a review May 24, 2023 21:33
Copy link
Collaborator

@ptomsich ptomsich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please implement Jessica's (completely POSIX-compliant) suggestion.

@bacam
Copy link
Collaborator Author

bacam commented May 25, 2023

I've redone it in the redirect and move style, on top of the current HEAD.

@bacam
Copy link
Collaborator Author

bacam commented May 25, 2023

It would be useful if someone with a BSDish system could test it.

@ptomsich
Copy link
Collaborator

@jrtc27 Could you test on one of your BSD systems?

@ptomsich ptomsich added the tgmm-agenda Tagged for the next Golden Model meeting agenda. label May 29, 2023
@ptomsich ptomsich removed the tgmm-agenda Tagged for the next Golden Model meeting agenda. label Jun 1, 2023
Allows for (e.g.) BSD sed, which uses -i differently.
@bacam
Copy link
Collaborator Author

bacam commented Jul 4, 2023

Rebased because the last one became messed up somehow (maybe I did it against the wrong branch?). Also tested it on a CheriBSD machine.

@ptomsich ptomsich merged commit ae905fb into riscv:master Jul 4, 2023
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.

9 participants