diff --git a/.github/workflows/scaffold.yml b/.github/workflows/scaffold.yml new file mode 100644 index 0000000..414990e --- /dev/null +++ b/.github/workflows/scaffold.yml @@ -0,0 +1,49 @@ +name: Build scaffold + +on: + workflow_dispatch: + inputs: + projects: + description: 'Projects to generate, separated by spaces' + required: true + default: 'kernel memoria cpu filesystem' + static: + description: 'Static lib to generate' + required: true + default: 'utils' + external: + description: 'External libs to include, separated by spaces' + required: true + default: 'commons pthread readline m' + branch: + description: 'Branch to push the generated files' + required: true + default: 'scaffold' + +jobs: + generate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + + - name: Generate scaffold files + run: | + bun ./scripts/scaffold.js \ + --projects "${{ github.event.inputs.projects }}" \ + --staticLib "${{ github.event.inputs.static }}" \ + --externalLibs "${{ github.event.inputs.external }}" + + - name: Push to scaffold branch + run: | + git switch --orphan ${{ github.event.inputs.branch }} + mv dist/{.gitignore,*} . + git add . + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git commit -m "Generate tp-scaffold files" + git push -f origin ${{ github.event.inputs.branch }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/vitepress.yml b/.github/workflows/vitepress.yml index f27b77f..309648a 100644 --- a/.github/workflows/vitepress.yml +++ b/.github/workflows/vitepress.yml @@ -1,6 +1,5 @@ name: Deploy to GitHub Pages on: - workflow_dispatch: {} push: branches: - main diff --git a/.gitignore b/.gitignore index bf5a1de..16d27d5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules .temp *cache dist/ +.vscode/ diff --git a/README.md b/README.md index 7dfe3bd..0fcd1b4 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,14 @@ Templates para facilitar la creación de proyectos en Lenguaje C. mkdir mi-nuevo-proyecto && cd mi-nuevo-proyecto # descargar el template -wget -qO- https://github.com/RaniAgus/so-project-template/releases/download/v4.0.3/project-v4.0.3.tar.gz \ +wget -qO- https://github.com/RaniAgus/so-project-template/releases/download/v5.0.0/project-v5.0.0.tar.gz \ | tar -xzvf - --strip-components 1 # compilar con make make # ejecutar -./bin/mi-nuevo-proyecto.out +./bin/mi-nuevo-proyecto ``` Para agregar bibliotecas, compartir código entre proyectos, importar en diff --git a/docs/.vitepress/configs/sidebar.ts b/docs/.vitepress/configs/sidebar.ts index ffc35a8..840b7d2 100644 --- a/docs/.vitepress/configs/sidebar.ts +++ b/docs/.vitepress/configs/sidebar.ts @@ -58,10 +58,6 @@ export const sidebar = { // text: 'Shared Libraries', // link: '/guia/avanzado/shared-libraries' // }, - { - text: 'Escuchar cambios en el código', - link: '/guia/avanzado/escuchar-cambios' - }, ], }, ], diff --git a/docs/guia/args.md b/docs/guia/args.md index 10bbbb8..e302dfd 100644 --- a/docs/guia/args.md +++ b/docs/guia/args.md @@ -11,7 +11,7 @@ Es probable que para el TP requieran pasar argumentos a `main()` para, por ejemplo, parametrizar el archivo config que se va a utilizar: ```bash -./bin/ejemplo.out ejemplo.config +./bin/ejemplo ejemplo.config ``` Y recibir el path hacia el archivo config en la función `config_create()`: diff --git a/docs/guia/avanzado/code.md b/docs/guia/avanzado/code.md index 7bc068c..b6c907f 100644 --- a/docs/guia/avanzado/code.md +++ b/docs/guia/avanzado/code.md @@ -19,7 +19,7 @@ El mismo cuenta con una task especificando lo siguiente: ::: code-group -<<< @/../src/project/.vscode/tasks.json#build{json:line-numbers} +<<< @/../src/configs/vscode/tasks.json{4-13 json:line-numbers} ::: @@ -46,7 +46,7 @@ el cual se indica, entre otras cosas: ::: code-group -<<< @/../src/project/.vscode/launch.json#run{json:line-numbers} +<<< @/../src/configs/vscode/launch.json{json:line-numbers} ::: @@ -88,7 +88,7 @@ posibles bugs. Veamos cómo está conformado `c_cpp_properties.json`: ::: code-group -<<< @/../src/project/.vscode/c_cpp_properties.json{7-10 json:line-numbers} +<<< @/../src/configs/vscode/c_cpp_properties.json{5-7 json:line-numbers} ::: diff --git a/docs/guia/avanzado/escuchar-cambios.md b/docs/guia/avanzado/escuchar-cambios.md deleted file mode 100644 index 4c626df..0000000 --- a/docs/guia/avanzado/escuchar-cambios.md +++ /dev/null @@ -1,45 +0,0 @@ -# Escuchar cambios en el código - -En otras tecnologías es muy común contar con herramientas que nos permitan -escuchar cambios en nuestros archivos fuente y disparar comandos que de otra -forma deberíamos ejecutar manualmente. - -Para poder hacerlo en nuestro proyecto, debemos tener instalado -el paquete [`entr`](http://eradman.com/entrproject/). Se puede instalar -utilizando el gestor de paquetes de Debian, `apt`: - -```bash -sudo apt install entr -``` - -## Watch - -En otras tecnologías se conoce como -[`watch`](https://www.geeksforgeeks.org/node-js-fs-watch-method/) a una opción -que nos permite observar cambios en el código para inmediatamente buscar errores -de sintaxis o semántica. - -En nuestro caso, lo usaremos para compilar con `make` cada vez que ocurra un -cambio en cualquier archivo que se encuentre en `./src`. Para esto, -ejecutaremos: - -```bash -make watch -``` - -## Daemon - -Un [daemon](https://www.npmjs.com/package/nodemon) es una herramienta que nos -permite reiniciar la aplicación cada vez que se guarden cambios en el código. - -En nuestro caso, lo utilizaremos para recompilar y ejecutar el proyecto con -`make start` cada vez que ocurra un cambio. Para lograr esto, ejecutaremos: - -```bash -make daemon -``` -::: tip - -Podés forzar un reinicio con `q` o finalizar el proceso con `Ctrl` + `C`. - -::: diff --git a/docs/guia/avanzado/tests.md b/docs/guia/avanzado/tests.md index c2fec57..852a932 100644 --- a/docs/guia/avanzado/tests.md +++ b/docs/guia/avanzado/tests.md @@ -52,8 +52,8 @@ archivos. ::: tip En general es una buena práctica que el archivo fuente que contiene la función -`main()` tenga muy poco código con la lógica más _core_ de la aplicación, -delegando cada tarea a otras funciones de otros archivos fuente que sí son más +`main()` tenga muy poco código con la lógica más _core_ de la aplicación, +delegando cada tarea a otras funciones de otros archivos fuente que sí son más acordes para ser testeadas de forma unitaria. ::: @@ -141,12 +141,47 @@ para poder identificar bien qué parte del código cubre cada suite: ## Ejecutar el proyecto -- Desde Visual Studio Code: ya contamos con la configuración necesaria para -ejecutarlo, simplemente elegimos la alternativa `test` entre las opciones. - - Desde Eclipse: hacemos click derecho sobre el ejecutable y seleccionamos `Run As...` > `Local C/C++ Application`. +- Desde Visual Studio Code: debemos agregar la siguiente configuración a nuestro +archivo `launch.json` y luego simplemente elegimos la alternativa `test` entre +las opciones: + +::: code-group + +```json [launch.json] +{ + // See https://go.microsoft.com/fwlink/?linkid=830387 + // for the documentation about the launch.json format + "version": "0.2.0", + "configurations": [ + { // [!code focus] + "name": "test", // [!code focus] + "type": "cppdbg", // [!code focus] + "request": "launch", // [!code focus] + "program": "${workspaceFolder}/bin/${workspaceFolderBasename}_tests.out", // [!code focus] + "args": [], // [!code focus] + "stopAtEntry": false, // [!code focus] + "cwd": "${workspaceFolder}", // [!code focus] + "environment": [], // [!code focus] + "externalConsole": false, // [!code focus] + "MIMode": "gdb", // [!code focus] + "setupCommands": [ // [!code focus] + { // [!code focus] + "description": "Enable pretty-printing for gdb", // [!code focus] + "text": "-enable-pretty-printing", // [!code focus] + "ignoreFailures": true // [!code focus] + } // [!code focus] + ], // [!code focus] + "preLaunchTask": "build" // [!code focus] + } // [!code focus] + ] +} +``` + +::: + ## Valgrind Para utilizar Valgrind, desde la consola podemos ejecutar: diff --git a/docs/guia/index.md b/docs/guia/index.md index e3b4325..8fc1cb4 100644 --- a/docs/guia/index.md +++ b/docs/guia/index.md @@ -57,7 +57,7 @@ tree bin obj ``` . ├── bin -│ └── {nombre-del-proyecto}.out +│ └── {nombre-del-proyecto} └── obj └── main.o ``` @@ -84,14 +84,14 @@ $ ls -l bin src bin: total 20 --rwxrwxr-x 1 utnso utnso 17256 Mar 12 11:43 ejemplo.out +-rwxrwxr-x 1 utnso utnso 17256 Mar 12 11:43 ejemplo src: total 4 -rw-rw-r-- 1 utnso utnso 118 Mar 12 11:22 main.c ``` -En este caso, se da cuenta que `ejemplo.out` fue modificado después que +En este caso, se da cuenta que `ejemplo` fue modificado después que `main.c`, por lo que no hace falta recompilar. ::: @@ -99,10 +99,10 @@ En este caso, se da cuenta que `ejemplo.out` fue modificado después que ## Ejecución Por último, para ejecutar el archivo compilado podemos ingresar -`./bin/{nombre-del-proyecto}.out`: +`./bin/{nombre-del-proyecto}`: ```bash -./bin/ejemplo.out +./bin/ejemplo ``` El cual nos mostrará el mensaje `Hello world!!`. diff --git a/docs/guia/linkear-bibliotecas.md b/docs/guia/linkear-bibliotecas.md index db29f88..0eb37e5 100644 --- a/docs/guia/linkear-bibliotecas.md +++ b/docs/guia/linkear-bibliotecas.md @@ -40,7 +40,7 @@ biblioteca que queremos usar al momento de la compilación con `gcc`. Al ejecutar `make` veremos algo como: ```bash -gcc -o bin/ejemplo.out src/main.c -lcommons +gcc -o bin/ejemplo src/main.c -lcommons ``` Ese `-lcommons` es lo que agregamos al editar `LIBS`. diff --git a/docs/guia/static-libraries.md b/docs/guia/static-libraries.md index 50ac71e..2291501 100644 --- a/docs/guia/static-libraries.md +++ b/docs/guia/static-libraries.md @@ -194,7 +194,7 @@ Una vez compilemos con `make` veremos que se agregó el flag `-L{path}/bin` a `gcc`: ```bash -gcc src/main.c -o "bin/ejemplo.out" -I../utils/src -L../utils/bin -lutils +gcc src/main.c -o "bin/ejemplo" -I../utils/src -L../utils/bin -lutils ``` ### Incluir en el código diff --git a/docs/snippets/guia/args/launch.json b/docs/snippets/guia/args/launch.json index 0f9c1ef..c9f97bb 100644 --- a/docs/snippets/guia/args/launch.json +++ b/docs/snippets/guia/args/launch.json @@ -8,7 +8,7 @@ "name": "run", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/bin/${workspaceFolderBasename}.out", + "program": "${workspaceFolder}/bin/${workspaceFolderBasename}", "args": [ // [!code focus:4] // TODO: Agregar los argumentos que se necesiten // [!code --] "ejemplo.config" // [!code ++] diff --git a/package.json b/package.json index 59fa05c..23d75bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "so-project-template", - "version": "4.0.3", + "version": "5.0.0", "description": "Templates para facilitar la creación de proyectos en Lenguaje C.", "main": "index.js", "type": "module", diff --git a/scripts/release.js b/scripts/release.js index 7d45c6e..2b633c1 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -1,13 +1,12 @@ import { $ } from 'bun'; -import { dirname } from 'path'; import { parseArgs } from 'util'; +import { Templates, exportTemplate } from './utils'; const { values } = parseArgs({ args: Bun.argv, options: { tag: { type: 'string', - default: 'SNAPSHOT' }, src: { type: 'string', @@ -17,54 +16,36 @@ const { values } = parseArgs({ type: 'string', default: 'dist' }, - templates: { - type: 'string', - default: 'project,static,shared' - }, }, allowPositionals: true, }); -const main = async ({ tag, src, dest, templates }) => { - console.log(`cleaning up ${dest}...\n\n`); - - await $`rm -rfv ${dest}`; - await $`mkdir -p ${dest}`; +const main = async ({ tag, src, dest }) => { + await cleanupDir(dest); console.log(`\n\nparsing templates from ${src}...`); - for (const template of templates.split(',')) { - console.log(`\n\nparsing ${template}...\n\n`); - - await $`rsync -r --exclude-from=${src}/${template}/.gitignore ${src}/${template} ${dest}`; - await $`rsync -r ${src}/${template}/.vscode ${dest}/${template}` + for (const template of Object.values(Templates)) { + await exportTemplate(src, dest, template); - const makefile = await parseMakefile(`${src}/${template}/makefile`); - await $`echo ${makefile} | tee makefile`.cwd(`${dest}/${template}`); + if (!tag) { + continue; + } console.log(`packing ${template} with tag ${tag}...\n\n`); - await $`tar -czvf ${template}-${tag}.tar.gz ${template}`.cwd(dest) - await $`md5sum ${template}-${tag}.tar.gz > ${template}-${tag}.tar.gz.md5`.cwd(dest); - await $`sha1sum ${template}-${tag}.tar.gz > ${template}-${tag}.tar.gz.sha1`.cwd(dest); + await compressAndGenerateChecksums(tag, `${dest}/${template}`); console.log(`\n\ncleaning up ${template}...\n\n`); - await $`rm -rfv ${template}`.cwd(dest) + await $`rm -rfv ${template}`.cwd(dest); } }; -const parseMakefile = async (file) => { - const lines = [] - for await(const line of $`cat ${file}`.lines()) { - lines.push(await parseMakefileLine(file, line)); - } - return lines.join('\n'); -} - -const parseMakefileLine = async (file, line) => { - const [_, include] = line.split('include ../'); - return include ? $`cat ${dirname(file)}/../${include}`.text() : line; +const compressAndGenerateChecksums = async (tag, dir) => { + await $`tar -czvf ${dir}-${tag}.tar.gz ${dir}` + await $`md5sum ${dir}-${tag}.tar.gz > ${dir}-${tag}.tar.gz.md5`; + await $`sha1sum ${dir}-${tag}.tar.gz > ${dir}-${tag}.tar.gz.sha1`; } await main(values); diff --git a/scripts/scaffold.js b/scripts/scaffold.js new file mode 100644 index 0000000..048b0ea --- /dev/null +++ b/scripts/scaffold.js @@ -0,0 +1,96 @@ +import { $ } from 'bun'; +import { parseArgs } from 'util'; +import { Templates, cleanupDir, replaceInterpolation, replaceConfig, exportTemplate, readJSON, writeJSON } from './utils'; + +const { values } = parseArgs({ + args: Bun.argv, + options: { + src: { + type: 'string', + default: 'src', + }, + dest: { + type: 'string', + default: 'dist', + }, + projects: { + type: 'string', + default: 'kernel memoria cpu filesystem', + }, + staticLib: { + type: 'string', + default: 'utils', + }, + externalLibs: { + type: 'string', + default: 'commons pthread readline m', + }, + }, + allowPositionals: true, +}); + +const main = async ({ src, dest, projects, staticLib, externalLibs }) => { + const projectsList = projects.split(' '); + + await cleanupDir(dest); + + console.log(`\n\nparsing static libs from ${src}...\n\n`); + + await exportTemplate(src, dest, Templates.STATIC); + await $`mv -v ${dest}/${Templates.STATIC} ${dest}/${staticLib}`; + + await replaceConfig(`${dest}/${staticLib}/settings.mk`, { + LIBS: externalLibs, + }); + + console.log(`\n\nparsing projects from ${src}...\n\n`); + + for (const project of projectsList) { + await exportTemplate(src, dest, Templates.PROJECT); + await $`mv -v ${dest}/${Templates.PROJECT} ${dest}/${project}`; + + await $`cp ${src}/configs/main/main.c ${dest}/${project}/src/main.c`; + await replaceInterpolation(`${dest}/${project}/src/main.c`, { project }); + + await configureCCppProperties(`${dest}/${project}`, staticLib); + await replaceConfig(`${dest}/${project}/settings.mk`, { + LIBS: `${staticLib} ${externalLibs}`, + STATIC_LIBPATHS: `../${staticLib}`, + }); + } + + console.log(`\n\ncreating workspace folder...\n\n`); + + await createWorkspaceFolder(src, dest, [...projectsList, staticLib]); + + console.log(`\n\ncopying root directory files...\n\n`); + + await $`cp -av ${src}/configs/scaffold/. ${dest}`; + + console.log(`\n\nadding deploy flags to README...\n\n`); + + await replaceInterpolation(`${dest}/README.md`, { + deployFlags: projectsList.map(p => `-p=${p}`).join(' '), + }); + + console.log(`\n\nscaffolding complete!\n\n`); +} + +const configureCCppProperties = async (projectDir, staticLib) => { + const properties = await readJSON(`${projectDir}/.vscode/c_cpp_properties.json`); + + for (const config of properties.configurations) { + config.includePath.push(`\${workspaceFolder}/../${staticLib}/include`); + } + + await writeJSON(`${projectDir}/.vscode/c_cpp_properties.json`, properties); +} + +const createWorkspaceFolder = async (src, dest, folders) => { + await writeJSON(`${dest}/tp.code-workspace`, { + folders: folders.map((folder) => ({ name: folder, path: folder })), + settings: await readJSON(`${src}/configs/vscode/settings.json`), + }); +} + +await main(values); diff --git a/scripts/utils.js b/scripts/utils.js new file mode 100644 index 0000000..da064ce --- /dev/null +++ b/scripts/utils.js @@ -0,0 +1,76 @@ +import { $ } from 'bun'; +import { dirname } from 'path'; + +export const Templates = { + PROJECT: 'project', + STATIC: 'static', + SHARED: 'shared', +}; + +export const cleanupDir = async (dir) => { + console.log(`cleaning up ${dir}...\n\n`); + + await $`rm -rfv ${dir}`; + await $`mkdir -p ${dir}`; +} + +export const exportTemplate = async (src, dest, template) => { + console.log(`copying ${template} files...\n\n`); + + await copyTrackedFiles(`${src}/templates/${template}`, dest); + + await $`cp -rv ${src}/configs/vscode ${dest}/${template}/.vscode`; + if (template !== Templates.PROJECT) { + await $`rm -fv ${dest}/${template}/.vscode/launch.json`; + } + + console.log(`\n\nexporting ${template} Makefile...\n\n`); + + await exportMakefile(`${src}/templates/${template}`, `${dest}/${template}`); + await exportMakefile(`${src}/templates/${template}`, `${dest}/${template}`, 'settings.mk'); +} + +const copyTrackedFiles = async (src, dest) => { + await $`rsync -rv --exclude-from=${src}/.gitignore ${src} ${dest}`; +} + +const exportMakefile = async (src, dest, name = 'Makefile') => { + await $`echo ${await parseMakefile(`${src}/${name}`)} | tee ${name}`.cwd(dest); +} + +const parseMakefile = async (file) => { + const lines = [] + for await(const line of $`cat ${file}`.lines()) { + lines.push(await parseMakefileLine(file, line)); + } + return lines.join('\n'); +} + +const parseMakefileLine = async (file, line) => { + const [_, include] = line.split('include ../'); + return include ? $`cat ${dirname(file)}/../${include}`.text() : line; +} + +export const replaceConfig = async (file, settings) => { + for (const [key, value] of Object.entries(settings)) { + await replace(file, `${key}=.*`, `${key}=${value}`); + } +} + +export const replaceInterpolation = async (file, data) => { + for (const [key, value] of Object.entries(data)) { + await replace(file, `{{ ${key} }}`, value); + } +} + +const replace = async (file, text, replacement) => { + await $`sed -i 's@'${text}'@'${replacement}'@' ${file}`; +} + +export const readJSON = async (file) => { + return JSON.parse(await $`cat ${file}`.text()); +} + +export const writeJSON = async (file, data) => { + await $`echo ${JSON.stringify(data, null, 2)} > ${file}`; +} diff --git a/src/configs/main/main.c b/src/configs/main/main.c new file mode 100644 index 0000000..53a72ed --- /dev/null +++ b/src/configs/main/main.c @@ -0,0 +1,6 @@ +#include + +int main(int argc, char* argv[]) { + saludar("{{ project }}"); + return 0; +} diff --git a/src/.gitignore b/src/configs/scaffold/.gitignore similarity index 100% rename from src/.gitignore rename to src/configs/scaffold/.gitignore diff --git a/src/configs/scaffold/README.md b/src/configs/scaffold/README.md new file mode 100644 index 0000000..863f98b --- /dev/null +++ b/src/configs/scaffold/README.md @@ -0,0 +1,76 @@ +# tp-scaffold + +Esta es una plantilla de proyecto diseñada para generar un TP de Sistemas +Operativos de la UTN FRBA. + +## Dependencias + +Para poder compilar y ejecutar el proyecto, es necesario tener instalada la +biblioteca [so-commons-library] de la cátedra: + +```bash +git clone https://github.com/sisoputnfrba/so-commons-library +cd so-commons-library +make debug +make install +``` + +## Compilación + +Cada módulo del proyecto se compila de forma independiente a través de un +archivo `makefile`. Para compilar un módulo, es necesario ejecutar el comando +`make` desde la carpeta correspondiente. + +El ejecutable resultante se guardará en la carpeta `bin` del módulo. + +## Importar desde Visual Studio Code + +Para importar el workspace, debemos abrir el archivo `tp.code-workspace` desde +la interfaz o ejecutando el siguiente comando desde la carpeta raíz del +repositorio: + +```bash +code tp.code-workspace +``` + +## Checkpoint + +Para cada checkpoint de control obligatorio, se debe crear un tag en el +repositorio con el siguiente formato: + +``` +checkpoint-{número} +``` + +Donde `{número}` es el número del checkpoint. + +Para crear un tag y subirlo al repositorio, podemos utilizar los siguientes +comandos: + +```bash +git tag -a checkpoint-{número} -m "Checkpoint {número}" +git push origin checkpoint-{número} +``` + +Asegúrense de que el código compila y cumple con los requisitos del checkpoint +antes de subir el tag. + +## Entrega + +Para desplegar el proyecto en una máquina Ubuntu Server, podemos utilizar el +script [so-deploy] de la cátedra: + +```bash +git clone https://github.com/sisoputnfrba/so-deploy.git +cd so-deploy +./deploy.sh -r=release {{ deployFlags }} "tp-{año}-{cuatri}-{grupo}" +``` + +El mismo se encargará de instalar las Commons, clonar el repositorio del grupo +y compilar el proyecto en la máquina remota. + +Ante cualquier duda, podés consultar la documentación en el repositorio de +[so-deploy], o utilizar el comando `./deploy.sh -h`. + +[so-commons-library]: https://github.com/sisoputnfrba/so-commons-library +[so-deploy]: https://github.com/sisoputnfrba/so-deploy diff --git a/src/static/.vscode/c_cpp_properties.json b/src/configs/vscode/c_cpp_properties.json similarity index 58% rename from src/static/.vscode/c_cpp_properties.json rename to src/configs/vscode/c_cpp_properties.json index 4d66d3c..d994656 100644 --- a/src/static/.vscode/c_cpp_properties.json +++ b/src/configs/vscode/c_cpp_properties.json @@ -1,12 +1,9 @@ { - // See https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference - // for the documentation about the c_cpp_properties.json format "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/src" - // TODO: Agregar los directorios de las bibliotecas a utilizar ], "defines": [], "compilerPath": "/usr/bin/gcc", diff --git a/src/shared/.vscode/launch.json b/src/configs/vscode/launch.json similarity index 78% rename from src/shared/.vscode/launch.json rename to src/configs/vscode/launch.json index 7413287..93f6388 100644 --- a/src/shared/.vscode/launch.json +++ b/src/configs/vscode/launch.json @@ -1,13 +1,11 @@ { - // See https://go.microsoft.com/fwlink/?linkid=830387 - // for the documentation about the launch.json format "version": "0.2.0", "configurations": [ { - "name": "test", + "name": "run", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/bin/${workspaceFolderBasename}_tests.out", + "program": "${workspaceFolder}/bin/${workspaceFolderBasename}", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", diff --git a/src/configs/vscode/settings.json b/src/configs/vscode/settings.json new file mode 100644 index 0000000..1d13367 --- /dev/null +++ b/src/configs/vscode/settings.json @@ -0,0 +1,7 @@ +{ + "debug.onTaskErrors": "abort", + "files.associations": { + "*.h": "c" + }, + "C_Cpp.errorSquiggles": "disabled" +} diff --git a/src/static/.vscode/tasks.json b/src/configs/vscode/tasks.json similarity index 78% rename from src/static/.vscode/tasks.json rename to src/configs/vscode/tasks.json index 29022c7..5bd6b53 100644 --- a/src/static/.vscode/tasks.json +++ b/src/configs/vscode/tasks.json @@ -1,6 +1,4 @@ { - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { diff --git a/src/project/.vscode/c_cpp_properties.json b/src/project/.vscode/c_cpp_properties.json deleted file mode 100644 index 4d66d3c..0000000 --- a/src/project/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - // See https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference - // for the documentation about the c_cpp_properties.json format - "configurations": [ - { - "name": "Linux", - "includePath": [ - "${workspaceFolder}/src" - // TODO: Agregar los directorios de las bibliotecas a utilizar - ], - "defines": [], - "compilerPath": "/usr/bin/gcc", - "cStandard": "gnu17", - "cppStandard": "gnu++17", - "intelliSenseMode": "linux-gcc-x64" - } - ], - "version": 4 -} diff --git a/src/project/.vscode/launch.json b/src/project/.vscode/launch.json deleted file mode 100644 index 5b8d368..0000000 --- a/src/project/.vscode/launch.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?linkid=830387 - // for the documentation about the launch.json format - "version": "0.2.0", - "configurations": [ - // #region run - { - "name": "run", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceFolder}/bin/${workspaceFolderBasename}.out", - "args": [ - // TODO: Agregar los argumentos que se necesiten - ], - "stopAtEntry": false, - "cwd": "${workspaceFolder}", - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ], - "preLaunchTask": "build" - }, - // #endregion run - { - "name": "test", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceFolder}/bin/${workspaceFolderBasename}_tests.out", - "args": [], - "stopAtEntry": false, - "cwd": "${workspaceFolder}", - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ], - "preLaunchTask": "build" - } - ] -} diff --git a/src/project/.vscode/tasks.json b/src/project/.vscode/tasks.json deleted file mode 100644 index 86bcb7a..0000000 --- a/src/project/.vscode/tasks.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "2.0.0", - "tasks": [ - // #region build - { - "label": "build", - "command": "make all", - "type": "shell", - "group": { - "kind": "build", - "isDefault": true - }, - "problemMatcher": ["$gcc"] - }, - // #endregion build - { - "label": "clean", - "command": "make clean", - "type": "shell", - "group": { - "kind": "none" - }, - "problemMatcher": [] - } - ] -} diff --git a/src/project/settings.mk b/src/project/settings.mk deleted file mode 100644 index 668f9c5..0000000 --- a/src/project/settings.mk +++ /dev/null @@ -1,20 +0,0 @@ -# Libraries -LIBS= - -# Custom libraries' paths -SHARED_LIBPATHS= -STATIC_LIBPATHS= - -# Compiler flags -CDEBUG=-g -Wall -DDEBUG -fdiagnostics-color=always -CRELEASE=-O3 -Wall -DNDEBUG -fcommon - -# Arguments when executing with start, memcheck or helgrind -ARGS= - -# Valgrind flags -MEMCHECK_FLAGS=--track-origins=yes -HELGRIND_FLAGS= - -# Source files (*.c) to be excluded from tests compilation -TEST_EXCLUDE=src/main.c diff --git a/src/shared/.vscode/c_cpp_properties.json b/src/shared/.vscode/c_cpp_properties.json deleted file mode 100644 index 4d66d3c..0000000 --- a/src/shared/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - // See https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference - // for the documentation about the c_cpp_properties.json format - "configurations": [ - { - "name": "Linux", - "includePath": [ - "${workspaceFolder}/src" - // TODO: Agregar los directorios de las bibliotecas a utilizar - ], - "defines": [], - "compilerPath": "/usr/bin/gcc", - "cStandard": "gnu17", - "cppStandard": "gnu++17", - "intelliSenseMode": "linux-gcc-x64" - } - ], - "version": 4 -} diff --git a/src/shared/.vscode/tasks.json b/src/shared/.vscode/tasks.json deleted file mode 100644 index 29022c7..0000000 --- a/src/shared/.vscode/tasks.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "2.0.0", - "tasks": [ - { - "label": "build", - "command": "make all", - "type": "shell", - "group": { - "kind": "build", - "isDefault": true - }, - "problemMatcher": ["$gcc"] - }, - { - "label": "clean", - "command": "make clean", - "type": "shell", - "group": { - "kind": "none" - }, - "problemMatcher": [] - } - ] -} diff --git a/src/shared/settings.mk b/src/shared/settings.mk deleted file mode 100644 index c0c4c1d..0000000 --- a/src/shared/settings.mk +++ /dev/null @@ -1,13 +0,0 @@ -# Libraries -LIBS= - -# Custom libraries' paths -SHARED_LIBPATHS= -STATIC_LIBPATHS= - -# Compiler flags -CDEBUG=-g -Wall -DDEBUG -fdiagnostics-color=always -CRELEASE=-O3 -Wall -DNDEBUG -fcommon - -# Source files (*.c) to be excluded from tests compilation -TEST_EXCLUDE= diff --git a/src/static/.vscode/launch.json b/src/static/.vscode/launch.json deleted file mode 100644 index 7413287..0000000 --- a/src/static/.vscode/launch.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?linkid=830387 - // for the documentation about the launch.json format - "version": "0.2.0", - "configurations": [ - { - "name": "test", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceFolder}/bin/${workspaceFolderBasename}_tests.out", - "args": [], - "stopAtEntry": false, - "cwd": "${workspaceFolder}", - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ], - "preLaunchTask": "build" - } - ] -} diff --git a/src/static/src/utils/hello.c b/src/static/src/utils/hello.c deleted file mode 100644 index 7168232..0000000 --- a/src/static/src/utils/hello.c +++ /dev/null @@ -1,5 +0,0 @@ -#include - -void say_hello(char* who) { - printf("Hello %s!!\n", who); -} diff --git a/src/compilation.mk b/src/templates/compilation.mk similarity index 91% rename from src/compilation.mk rename to src/templates/compilation.mk index 8269464..493f47c 100644 --- a/src/compilation.mk +++ b/src/templates/compilation.mk @@ -42,7 +42,7 @@ BIN = bin/$(call filename,$(shell cd . && pwd | xargs basename)) # Set test binary targets ifeq ($(TESTS_ENABLED),1) -TEST = bin/$(shell cd . && pwd | xargs basename)_tests.out +TEST = bin/$(shell cd . && pwd | xargs basename)_tests endif .PHONY: all @@ -60,13 +60,6 @@ release: $(BIN) clean: -rm -rfv obj bin -.PHONY: watch -watch: - @test $(shell which entr) || entr - while sleep 0.1; do \ - find src/ | entr -d make all --no-print-directory; \ - done - $(BIN): $(OBJS) | $(dir $(BIN)) $(call compile_bin) diff --git a/src/execution.mk b/src/templates/execution.mk similarity index 64% rename from src/execution.mk rename to src/templates/execution.mk index c146881..ee3a542 100644 --- a/src/execution.mk +++ b/src/templates/execution.mk @@ -2,13 +2,6 @@ start: debug valgrind --tool=none ./$(BIN) $(ARGS) -.PHONY: daemon -daemon: - @test $(shell which entr) || entr - while sleep 0.1; do \ - find src/ | entr -d make start --no-print-directory; \ - done - .PHONY: memcheck memcheck: debug valgrind --leak-check=full $(MEMCHECK_FLAGS) ./$(BIN) $(ARGS) diff --git a/src/installation.mk b/src/templates/installation.mk similarity index 85% rename from src/installation.mk rename to src/templates/installation.mk index 96ab668..bf5a83a 100644 --- a/src/installation.mk +++ b/src/templates/installation.mk @@ -1,6 +1,3 @@ -PATH_TO_LIB=/usr/lib -PATH_TO_INCLUDE=/usr/include - .PHONY: install install: release test sudo cp -uv $(BIN) $(PATH_TO_LIB) diff --git a/src/static/.gitignore b/src/templates/project/.gitignore similarity index 91% rename from src/static/.gitignore rename to src/templates/project/.gitignore index dbdf056..5eac7e8 100644 --- a/src/static/.gitignore +++ b/src/templates/project/.gitignore @@ -17,4 +17,5 @@ RemoteSystemsTempFiles/ .vscode/* !.vscode/c_cpp_properties.json !.vscode/launch.json +!.vscode/settings.json !.vscode/tasks.json diff --git a/src/project/makefile b/src/templates/project/Makefile similarity index 71% rename from src/project/makefile rename to src/templates/project/Makefile index f8022d4..4b197b8 100644 --- a/src/project/makefile +++ b/src/templates/project/Makefile @@ -2,7 +2,7 @@ include settings.mk ################################################################################ -filename = $(1).out +filename = $(1) define compile_bin $(CC) $(CFLAGS) -o "$@" $^ $(IDIRS:%=-I%) $(LIBDIRS:%=-L%) $(RUNDIRS:%=-Wl,-rpath,%) $(LIBS:%=-l%) @@ -15,11 +15,5 @@ endef ################################################################################ include ../compilation.mk - -################################################################################ - include ../execution.mk - -################################################################################ - include ../testing.mk diff --git a/src/templates/project/settings.mk b/src/templates/project/settings.mk new file mode 100644 index 0000000..825804a --- /dev/null +++ b/src/templates/project/settings.mk @@ -0,0 +1,2 @@ +include ../settings-build.mk +include ../settings-exec.mk diff --git a/src/project/src/main.c b/src/templates/project/src/main.c similarity index 83% rename from src/project/src/main.c rename to src/templates/project/src/main.c index 48c8ded..2106582 100644 --- a/src/project/src/main.c +++ b/src/templates/project/src/main.c @@ -1,4 +1,3 @@ -#include #include int main(int argc, char* argv[]) { diff --git a/src/static/settings.mk b/src/templates/settings-build.mk similarity index 71% rename from src/static/settings.mk rename to src/templates/settings-build.mk index c0c4c1d..75e2351 100644 --- a/src/static/settings.mk +++ b/src/templates/settings-build.mk @@ -8,6 +8,3 @@ STATIC_LIBPATHS= # Compiler flags CDEBUG=-g -Wall -DDEBUG -fdiagnostics-color=always CRELEASE=-O3 -Wall -DNDEBUG -fcommon - -# Source files (*.c) to be excluded from tests compilation -TEST_EXCLUDE= diff --git a/src/templates/settings-exec.mk b/src/templates/settings-exec.mk new file mode 100644 index 0000000..9004a3c --- /dev/null +++ b/src/templates/settings-exec.mk @@ -0,0 +1,6 @@ +# Arguments when executing with start, memcheck or helgrind +ARGS= + +# Valgrind flags +MEMCHECK_FLAGS=--track-origins=yes +HELGRIND_FLAGS= diff --git a/src/templates/settings-install.mk b/src/templates/settings-install.mk new file mode 100644 index 0000000..0620aef --- /dev/null +++ b/src/templates/settings-install.mk @@ -0,0 +1,3 @@ +# Path to the installation directories +PATH_TO_LIB=/usr/lib +PATH_TO_INCLUDE=/usr/include diff --git a/src/templates/settings-test.mk b/src/templates/settings-test.mk new file mode 100644 index 0000000..716ad6e --- /dev/null +++ b/src/templates/settings-test.mk @@ -0,0 +1,2 @@ +# Source files (*.c) to be excluded from tests compilation +TEST_EXCLUDE= diff --git a/src/project/.gitignore b/src/templates/shared/.gitignore similarity index 90% rename from src/project/.gitignore rename to src/templates/shared/.gitignore index dbdf056..5f7ea77 100644 --- a/src/project/.gitignore +++ b/src/templates/shared/.gitignore @@ -4,7 +4,6 @@ obj/ *.log # Eclipse files -RemoteSystemsTempFiles/ .metadata/ .settings/ .cproject @@ -17,4 +16,5 @@ RemoteSystemsTempFiles/ .vscode/* !.vscode/c_cpp_properties.json !.vscode/launch.json +!.vscode/settings.json !.vscode/tasks.json diff --git a/src/shared/makefile b/src/templates/shared/Makefile similarity index 61% rename from src/shared/makefile rename to src/templates/shared/Makefile index 89d357b..b198015 100644 --- a/src/shared/makefile +++ b/src/templates/shared/Makefile @@ -1,7 +1,5 @@ include settings.mk -################################################################################ - filename = lib$(1).so define compile_bin @@ -15,11 +13,5 @@ endef ################################################################################ include ../compilation.mk - -################################################################################ - include ../testing.mk - -################################################################################ - include ../installation.mk diff --git a/src/templates/shared/settings.mk b/src/templates/shared/settings.mk new file mode 100644 index 0000000..627e7f8 --- /dev/null +++ b/src/templates/shared/settings.mk @@ -0,0 +1,2 @@ +include ../settings-build.mk +include ../settings-install.mk diff --git a/src/shared/src/shared/hello.c b/src/templates/shared/src/shared/hello.c similarity index 100% rename from src/shared/src/shared/hello.c rename to src/templates/shared/src/shared/hello.c diff --git a/src/shared/src/shared/hello.h b/src/templates/shared/src/shared/hello.h similarity index 100% rename from src/shared/src/shared/hello.h rename to src/templates/shared/src/shared/hello.h diff --git a/src/shared/.gitignore b/src/templates/static/.gitignore similarity index 90% rename from src/shared/.gitignore rename to src/templates/static/.gitignore index dbdf056..5f7ea77 100644 --- a/src/shared/.gitignore +++ b/src/templates/static/.gitignore @@ -4,7 +4,6 @@ obj/ *.log # Eclipse files -RemoteSystemsTempFiles/ .metadata/ .settings/ .cproject @@ -17,4 +16,5 @@ RemoteSystemsTempFiles/ .vscode/* !.vscode/c_cpp_properties.json !.vscode/launch.json +!.vscode/settings.json !.vscode/tasks.json diff --git a/src/static/makefile b/src/templates/static/Makefile similarity index 82% rename from src/static/makefile rename to src/templates/static/Makefile index 1917632..3ae224a 100644 --- a/src/static/makefile +++ b/src/templates/static/Makefile @@ -15,7 +15,4 @@ endef ################################################################################ include ../compilation.mk - -################################################################################ - include ../testing.mk diff --git a/src/templates/static/settings.mk b/src/templates/static/settings.mk new file mode 100644 index 0000000..6fb4ee8 --- /dev/null +++ b/src/templates/static/settings.mk @@ -0,0 +1 @@ +include ../settings-build.mk diff --git a/src/templates/static/src/utils/hello.c b/src/templates/static/src/utils/hello.c new file mode 100644 index 0000000..a0fdd8a --- /dev/null +++ b/src/templates/static/src/utils/hello.c @@ -0,0 +1,5 @@ +#include + +void saludar(char* quien) { + printf("Hola desde %s!!\n", quien); +} diff --git a/src/static/src/utils/hello.h b/src/templates/static/src/utils/hello.h similarity index 78% rename from src/static/src/utils/hello.h rename to src/templates/static/src/utils/hello.h index 84c89cd..6b74420 100644 --- a/src/static/src/utils/hello.h +++ b/src/templates/static/src/utils/hello.h @@ -5,9 +5,9 @@ #include /** - * @NAME: say_hello + * @NAME: saludar * @DESC: Imprime un saludo al nombre que se pase por parámetro por consola. */ - void say_hello(char* who); + void saludar(char* who); #endif diff --git a/src/testing.mk b/src/templates/testing.mk similarity index 64% rename from src/testing.mk rename to src/templates/testing.mk index 8af8151..9dd5227 100644 --- a/src/testing.mk +++ b/src/templates/testing.mk @@ -3,13 +3,6 @@ ifeq ($(TESTS_ENABLED),1) test: $(TEST) valgrind --tool=none ./$(TEST) -.PHONY: test-daemon -test-daemon: - @test $(shell which entr) || entr - while sleep 0.1; do \ - find tests/ src/ | entr -d make test --no-print-directory; \ - done - .PHONY: test-memcheck test-memcheck: $(TEST) valgrind --leak-check=full $(MEMCHECK_FLAGS) ./$(TEST) diff --git a/src/workspace.code-workspace b/src/templates/workspace.code-workspace similarity index 100% rename from src/workspace.code-workspace rename to src/templates/workspace.code-workspace