summaryrefslogtreecommitdiff
path: root/scripts/xrepo.bat
blob: 44e74d83a35b8d490dc86b125d245d410145504c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
@set "XMAKE_ROOTDIR=%~dp0"
@if not defined XMAKE_PROGRAM_FILE (
    @set "XMAKE_PROGRAM_FILE=%XMAKE_ROOTDIR%xmake.exe"
)

@if [%1]==[env] (
    if [%2]==[quit] (
        if defined XMAKE_PROMPT_BACKUP (
            call %XMAKE_ENV_BACKUP%
            setlocal EnableDelayedExpansion
            if !errorlevel! neq 0 exit /B !errorlevel!
            endlocal
            set "PROMPT=%XMAKE_PROMPT_BACKUP%"
            set XMAKE_ENV_BACKUP=
            set XMAKE_PROMPT_BACKUP=
        )
        goto :ENDXREPO
    )
    if [%2]==[shell] (
        if defined XMAKE_PROMPT_BACKUP (
            call %XMAKE_ENV_BACKUP%
            setlocal EnableDelayedExpansion
            if !errorlevel! neq 0 exit /B !errorlevel!
            "%XMAKE_PROGRAM_FILE%" lua private.xrepo.action.env.info config
            if !errorlevel! neq 0 (
                exit /B !errorlevel!
            )
            @"%XMAKE_PROGRAM_FILE%" lua --quiet private.xrepo.action.env.info prompt 1>nul
            if !errorlevel! neq 0 (
                echo error: xmake.lua not found^^!
                exit /B !errorlevel!
            )
            endlocal
            set "PROMPT=%XMAKE_PROMPT_BACKUP%"
            set XMAKE_ENV_BACKUP=
            set XMAKE_PROMPT_BACKUP=
            echo Please rerun `xrepo env shell` to enter the environment.
            exit /B 1
        ) else (
            setlocal EnableDelayedExpansion
            "%XMAKE_PROGRAM_FILE%" lua private.xrepo.action.env.info config
            if !errorlevel! neq 0 (
                exit /B !errorlevel!
            )
            @"%XMAKE_PROGRAM_FILE%" lua --quiet private.xrepo.action.env | findstr . && (
                echo error: corrupt xmake.lua detected in the current directory^^!
                exit /B 1
            )
            @"%XMAKE_PROGRAM_FILE%" lua --quiet private.xrepo.action.env.info prompt 1>nul
            if !errorlevel! neq 0 (
                echo error: xmake.lua not found^^!
                exit /B !errorlevel!
            )
            endlocal
            for /f %%i in ('@"%XMAKE_PROGRAM_FILE%" lua --quiet private.xrepo.action.env.info prompt') do @(
                @set "PROMPT=%%i %PROMPT%"
            )
            @set "XMAKE_PROMPT_BACKUP=%PROMPT%"
        )
        for /f %%i in ('@"%XMAKE_PROGRAM_FILE%" lua private.xrepo.action.env.info envfile') do @(
            @set "XMAKE_ENV_BACKUP=%%i.bat"
            @"%XMAKE_PROGRAM_FILE%" lua private.xrepo.action.env.info backup.cmd 1>"%%i.bat"
        )
        for /f %%i in ('@"%XMAKE_PROGRAM_FILE%" lua private.xrepo.action.env.info envfile') do @(
            @"%XMAKE_PROGRAM_FILE%" lua private.xrepo.action.env.info script.cmd 1>"%%i.bat"
            call "%%i.bat"
        )
        goto :ENDXREPO
    )
    set XREPO_BIND_FLAG=
    if [%2]==[-b] if [%4]==[shell] (
        set XREPO_BIND_FLAG=1
    )
    if [%2]==[--bind] if [%4]==[shell] (
        set XREPO_BIND_FLAG=1
    )
    if defined XREPO_BIND_FLAG (
        set XREPO_BIND_FLAG=
        if defined XMAKE_PROMPT_BACKUP (
            call %XMAKE_ENV_BACKUP%
            setlocal EnableDelayedExpansion
            if !errorlevel! neq 0 exit /B !errorlevel!
            endlocal
            set "PROMPT=%XMAKE_PROMPT_BACKUP%"
            set XMAKE_ENV_BACKUP=
            set XMAKE_PROMPT_BACKUP=
            echo Please rerun `xrepo env %2 %3 shell` to enter the environment.
            exit /B 1
        ) else (
            pushd %XMAKE_ROOTDIR%
            setlocal EnableDelayedExpansion
            %XMAKE_PROGRAM_FILE% lua private.xrepo.action.env.info config %3
            if !errorlevel! neq 0 (
                popd
                exit /B !errorlevel!
            )
            @%XMAKE_PROGRAM_FILE% lua --quiet private.xrepo.action.env.info prompt %3 1>nul
            if !errorlevel! neq 0 (
                popd
                echo error: environment not found^^!
                exit /B !errorlevel!
            )
            endlocal
            for /f %%i in ('@%XMAKE_PROGRAM_FILE% lua --quiet private.xrepo.action.env.info prompt %3') do @(
                @set "PROMPT=%%i %PROMPT%"
            )
            @set "XMAKE_PROMPT_BACKUP=%PROMPT%"
        )
        for /f %%i in ('@%XMAKE_PROGRAM_FILE% lua private.xrepo.action.env.info envfile %3') do @(
            @set "XMAKE_ENV_BACKUP=%%i.bat"
            @"%XMAKE_PROGRAM_FILE%" lua --quiet private.xrepo.action.env.info backup.cmd %3 1>"%%i.bat"
        )
        for /f %%i in ('@%XMAKE_PROGRAM_FILE% lua private.xrepo.action.env.info envfile %3') do @(
            @"%XMAKE_PROGRAM_FILE%" lua --quiet private.xrepo.action.env.info script.cmd %3 1>"%%i.bat"
            call "%%i.bat"
        )
        popd
        goto :ENDXREPO
    )
)

@call "%XMAKE_PROGRAM_FILE%" lua private.xrepo %*

:ENDXREPO