<commit_before>package luxe;

import haxe.macro.Expr;
import haxe.macro.Context;

import haxe.io.Bytes;
import haxe.io.Path;


#if macro
import sys.io.File;
import sys.FileSystem;
#end

class BuildVersion {

		//This is always called from Luxe.hx in the root folder,
		//which contains the .git repo, and build file directly
	macro public static function latest() {

		var location : String = Context.getPosInfos(Context.currentPos()).file;
		var root : String = Path.addTrailingSlash(Path.directory(location));
		var out : String = Path.join([root,'build']);

		var build : String = try_git( root );

		if(build != '') {
				//the + is for semantic versioning
			build = '+' + build.substr(0,10);
			File.saveContent(out, build);
			Context.addResource('build', Bytes.ofString(build));
		}

		return Context.makeExpr(build, Context.currentPos());

	} //latest

	static function try_git(root:String) {

		#if macro
			var git_path : String = Path.join([root,'.git/']);
				git_path = Path.normalize(git_path);
		
			if(FileSystem.exists(git_path) && FileSystem.isDirectory(git_path)) {
				var ref_file = Path.normalize(Path.join([git_path,'refs/heads/master']));
				return File.getContent(ref_file);
			}
		#end

		return '';

	} //try_git
	
} //BuildVersion<commit_msg>making build version more resilient<commit_after>package luxe;

import haxe.macro.Expr;
import haxe.macro.Context;

import haxe.io.Bytes;
import haxe.io.Path;


#if macro
import sys.io.File;
import sys.FileSystem;
#end

class BuildVersion {

        //This is always called from Luxe.hx in the root folder,
        //which contains the .git repo, and build file directly
    macro public static function latest() {

        var location : String = Context.getPosInfos(Context.currentPos()).file;
        var root : String = Path.addTrailingSlash(Path.directory(location));
        var out : String = Path.join([root,'build']);

        var build : String = try_git( root );

        if(build != '') {
                //the + is for semantic versioning
            build = '+' + build.substr(0,10);
            File.saveContent(out, build);
            Context.addResource('build', Bytes.ofString(build));
        }

        return Context.makeExpr(build, Context.currentPos());

    } //latest

    static function try_git(root:String) {

        #if macro
            var git_path : String = Path.join([root,'.git/']);
                git_path = Path.normalize(git_path);

            if(FileSystem.exists(git_path) && FileSystem.isDirectory(git_path)) {
                var ref_file = Path.normalize(Path.join([git_path,'refs/heads/snow']));
                if(FileSystem.exists(ref_file)) {
                    return File.getContent(ref_file);
                } else {
                    return '';
                }
            }
        #end

        return '';

    } //try_git

} //BuildVersion
{'fraction_non_alphanumeric': 0.13008695652173913, 'fraction_numerical': 0.0020869565217391303, 'mean_word_length': 2.6636942675159236, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6096118', 'n_tokens_mistral': 952, 'n_tokens_neox': 860, 'n_words': 202}