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

Feat/old template #69

Merged
merged 11 commits into from
Nov 29, 2024
Merged

Feat/old template #69

merged 11 commits into from
Nov 29, 2024

Conversation

sivertjoe
Copy link
Collaborator

@sivertjoe sivertjoe commented Nov 28, 2024

Un-reviewable PR? 😄
fix #68

setup, run, tally, and bench needed to be updated.

Very simple script aoc-migration that seems to work okay:

#!/bin/bash

TARGET=$1

mv $TARGET tmp
mkdir $TARGET
mv tmp/src/* $TARGET

for file in $TARGET/*; do
    cp tmp/Cargo.toml $file/Cargo.toml
    cp tmp/Cargo.lock $file/Cargo.lock
    mkdir -p $file/src
    mv $file/main.rs $file/src/main.rs
done

rm -rf tmp

Run with:
aoc-migration <target>

@sivertjoe sivertjoe added the enhancement New feature or request label Nov 28, 2024
Copy link
Owner

@seblyng seblyng left a comment

Choose a reason for hiding this comment

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

Seems easier👍 will this make it impossible to run earlier years without manually converting to this new setup?

@sivertjoe
Copy link
Collaborator Author

sivertjoe commented Nov 28, 2024 via email

@seblyng
Copy link
Owner

seblyng commented Nov 28, 2024

:( I guess it should be pretty simple to create a script to convert it?

@sivertjoe
Copy link
Collaborator Author

sivertjoe commented Nov 28, 2024 via email

@seblyng
Copy link
Owner

seblyng commented Nov 28, 2024

Makes sense👍 fine by me, I'll just create a script to convert if I ever need it

It makes the code here a bit easier it seems like, so let's just do it

src/setup.rs Outdated
format!("{dir}/main.rs"),
)
.await?;
tokio::fs::copy(format!("{template_dir}/template.rs"), format!("{year}/{day}/main.rs")).await?;
Copy link
Owner

@seblyng seblyng Nov 28, 2024

Choose a reason for hiding this comment

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

Should probably be tokio::fs::copy(format!("{template_dir}/template.rs"), format!("{year}/{day}/src/main.rs")).await?;

Notice the src before main.rs. Because, now it looks like this:

image

Where the main.rs contains this:

fn main() {
    println!("Hello, world!");
}

Also; what do you feel about formatting the template file as well according to how we have formatted the rest of this codebase?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can do that

@seblyng
Copy link
Owner

seblyng commented Nov 28, 2024

I took my freedom to just update the PR description with a very simple and naive script to help with migration

@sivertjoe
Copy link
Collaborator Author

Idk if I used it incorrectly but ./script 2023 did not work for me 🤪. What do you think of this script

#!/bin/bash

TARGET=$1

cd $TARGET
deps=($(cargo tree -e normal --depth 1 -q | grep -E '├──|└──' | awk '{print $2}'))
for folder in ./*; do
    if [[ $(basename "$folder") == day_* ]]; then
                found=()
                main="${folder}/main.rs"
                for dep in "${deps[@]}"; do
                        if grep -q "$dep" "$main"; then
                                found+=("$dep")
                        fi
                done
                mv $folder temp
                cargo new $folder -q
                cp temp/main.rs "${folder}/src/main.rs"
                cd $folder
                for dep in "${found[@]}"; do
                        cargo add $dep -q
                done
                cd ..
                rm -r temp
        fi
done
rm Cargo.*

@seblyng
Copy link
Owner

seblyng commented Nov 29, 2024

Didn't try it myself yet, but it looks great😎

@sivertjoe
Copy link
Collaborator Author

sivertjoe commented Nov 29, 2024 via email

@sivertjoe sivertjoe merged commit feeb905 into master Nov 29, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use old template setup
2 participants