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

[Incremental-building-units] Implement an incremental building strategy #33

Open
pavly-gerges opened this issue Feb 12, 2023 · 0 comments
Labels
build-script Concerning build script enhancement New feature or request question Further information is requested

Comments

@pavly-gerges
Copy link
Member

The current native build system isn't incremental.

Here is a simple strategy to implement an incremental building system:

  • Use this code first and compile each source C file into a static object file:
└──╼ $gcc -c  test-source.c -o test-static-object.o
  • Each file in the unix system has a LDM (last-date-of-modification) including the source C files and the object code files.
  • In the subsequent build, comparing these metadata (the last date of modification) of both the source code and the static object output will determine if the build will execute or not, here is a simple low-level similar approach:
#!/bin/bash
echo "Test ldm (Last Date of Modification) for incremental building units"
source="./source.c"
function getFormatedFileLdm() {
    local target=$1
    local format=$2
    stat ${target} --format=${format}
    local ldm=$?
    return $ldm
}
function getFileLdm0() {
    local target=$1
    getFormatedFileLdm ${target} %Y
    local ldm=$?
    return $ldm
}
function saveFileLdm() {
    local target="${1}-ldm.txt"
    local ldm=$2
    echo "${ldm}" > "${target}"
    return $?
}
function loadFileLdm() {
    local target="${1}-ldm.txt"
    cat $target
    return $?
}
function isModified() {
    local ldm0=$1
    local ldm1=$2
    let elapsed_ldm=$ldm1-$ldm0   
    if (( $elapsed_ldm > 0 )); then
        echo "Compiling now ...."
        gcc $source --debug -o "${source}.o"
    elif (( $elapsed_ldm == 0 )); then
        echo "File not changed, leaving now ...."
    else 
        echo "State undefined ...."
    fi
}
# prepare LDMs (Last-Dates-Of-Modifications)
current_ldm=`getFileLdm0 $source`
last_ldm=`loadFileLdm $source`
# test if the file is modified 
isModified $last_ldm $current_ldm
# update the file ldm with current new ldm
saveFileLdm $source $current_ldm
  • The compilation should end by a shared position-independent shared object file:
└──╼ $gcc -shared -fPIC test-static-object.o -o test-shared-object.so
@pavly-gerges pavly-gerges added enhancement New feature or request build-script Concerning build script labels Feb 12, 2023
@pavly-gerges pavly-gerges added this to the API-Building-Model milestone Feb 12, 2023
@pavly-gerges pavly-gerges added the question Further information is requested label Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build-script Concerning build script enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant