File: msvc.diff.R

package info (click to toggle)
plr 1%3A8.4.7-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,128 kB
  • sloc: ansic: 4,742; sql: 628; sh: 357; makefile: 77; perl: 20
file content (211 lines) | stat: -rw-r--r-- 7,438 bytes parent folder | download | duplicates (3)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211

# derived from msvc.diff (PostgreSQL Release 13.2)

###############################################################################################
# This R script dynamically edits Mkvcbuild.pm and vcregress.pl
###############################################################################################

# Required: get the environment variable - postgresrcroot
#
# e.g. set postgresrcroot=C:\projects\postgresql
#
postgresrcroot <- Sys.getenv("postgresrcroot")
postgresrcroot <- normalizePath(postgresrcroot, winslash="/", mustWork = T)


MkvcbuildPathFile <- paste0(postgresrcroot, "/src/tools/msvc/Mkvcbuild.pm")
Mkvcbuild.pm.Lines <- readLines(MkvcbuildPathFile)

insContribExcludesArray <- function(lines) {

  # lines
  LineOnlyBeginPos <- which(grepl("@contrib_excludes\\s+=\\s+\\(", x = lines, perl = TRUE))
  LineAllHaveRightParensPos <- which(grepl("\\)", x = lines, perl = TRUE))
  # after BeginPos, first-found line that has a right paren
  LineOnlyEndPos <- LineAllHaveRightParensPos[head(which(LineOnlyBeginPos <= LineAllHaveRightParensPos),1)]

  ModifyLineWorking <- lines[LineOnlyEndPos]

  # within that line
  # find the right-most paren
  LastParenPos <- tail(gregexpr("\\)", text = ModifyLineWorking, perl = TRUE)[[1L]],1L)
  # insert into that line
  ModifyLineWorking <- paste0(append(strsplit(ModifyLineWorking, split = "")[[1L]], ", 'plr'", after = LastParenPos - 1L), collapse = "")

  lines[LineOnlyEndPos] <- ModifyLineWorking

  writeLines("")
  writeLines("BEGIN insContribExcludesArray ")
  writeLines("")
  writeLines(lines[LineOnlyBeginPos:LineOnlyEndPos])
  writeLines("")
  writeLines("END   insContribExcludesArray ")
  writeLines("")

  return(lines)

}

# 1 - add 'plr' to @contrib_excludes array
Mkvcbuild.pm.Lines <- insContribExcludesArray(Mkvcbuild.pm.Lines)



addProjectCode  <- function(lines) {

  plrProjectText <-
"\tmy $plr = $solution->AddProject('plr','dll','plr','contrib/plr');
\t$plr->AddFiles(
\t\t'contrib\\plr','plr.c','pg_conversion.c','pg_backend_support.c','pg_userfuncs.c','pg_rsupport.c'
\t);
\t$plr->AddReference($postgres);
\t$plr->AddLibrary('contrib/plr/R$(PlatformTarget).lib');
\t$plr->AddIncludeDir('$(R_HOME)\\include');
\tmy $mfplr = Project::read_file('contrib/plr/Makefile');
\tGenerateContribSqlFiles('plr', $mfplr);

"

  LineOnlyBeginPos    <- which(grepl("sub\\s+mkvcbuild", x = lines, perl = TRUE))

  # if pgcrypto code exists, then use it to do positioning
  if(any(grepl("GenerateContribSqlFiles\\s*\\(\\s*'pgcrypto'", x = lines , perl = TRUE))) {

    LineLastPgCryptoPos <- which(grepl("GenerateContribSqlFiles\\s*\\(\\s*'pgcrypto'", x = lines , perl = TRUE))
    # after BeginPos, first-found line
    LineOnlyPos <- LineLastPgCryptoPos[head(which(LineOnlyBeginPos < LineLastPgCryptoPos),1)]

  # insert into the file after(below) the positition
  lines <- append(lines, strsplit(plrProjectText, split = "\n")[[1L]], after =  LineOnlyPos + 1L)

  # otherwise, use something else to do positioning
  #
  # pgcrypto: Remove non-OpenSSL support
  # petere committed on Nov 5 2021
  # https://github.com/postgres/postgres/commit/db7d1a7b0530e8cbd045744e1c75b0e63fb6916f#diff-fd3a59b81739e0c9f354d679334926ecfc23defb2b3d477f9d22f182adb19afe
  #
  # Fix the pgcrypto position error in the Windows build that uses pg master #127
  # https://github.com/postgres-plr/plr/issues/127
  #
  } else {

    FirstLineIterSrcTestModules <- which(grepl("foreach\\s+my\\s+\\$subdir\\s*\\(\\s*'contrib'\\s*,\\s*'src/test/modules", x = lines , perl = TRUE))
    # before BeginPos, first-found line
    LineOnlyPos <- FirstLineIterSrcTestModules[head(which(LineOnlyBeginPos < FirstLineIterSrcTestModules),1)]

  # insert into the file before(above) the position
  lines <- append(lines, strsplit(plrProjectText, split = "\n")[[1L]], after =  LineOnlyPos - 1L)

  }

  writeLines("")
  writeLines("BEGIN AddProjectCode")
  writeLines("")
  writeLines(lines[LineOnlyPos:(LineOnlyPos + 10L)])
  writeLines("")
  writeLines("END   AddProjectCode")
  writeLines("")

  return(lines)

}

# 2 - part of "sub mkvcbuild" - add 'plr' project
Mkvcbuild.pm.Lines <- addProjectCode(Mkvcbuild.pm.Lines)



addGenerateContribSqlFilesCode <- function(lines) {

  # lines
  LineOnlyBeginPos   <- which(grepl("sub\\s+GenerateContribSqlFiles", x = lines, perl = TRUE))

  # pg 11 and later has "return;"
  LineAllHaveReturnsPos <- which(grepl("\\breturn\\s*;", x = lines, perl = TRUE))
  if(length(LineAllHaveReturnsPos)) {
    # after BeginPos, first-found line
    LineOfContribReturnPos <- LineAllHaveReturnsPos[head(which(LineOnlyBeginPos < LineAllHaveReturnsPos),1L)]
  } else {
    # earlier than pg 11
    # just find the function closing end-left-facing-brace
    LineAllHaveReturnsPos <- which(grepl("^}$", x = lines, perl = TRUE))
    LineOfContribReturnPos <- LineAllHaveReturnsPos[head(which(LineOnlyBeginPos < LineAllHaveReturnsPos),1L)]
  }
  plrGenerateContribSqlFilesText <-
"\telse
\t{
\t\tprint \"GenerateContribSqlFiles skipping $n\\n\";
\t\tif ($n eq 'plr')
\t\t{
\t\t\tprint \"mf: $mf\\n\";
\t\t}
\t}
"
  # insert into the file to the position "just above", the "return" statement, xor, "function closing function closing end-left-facing-brace"
  lines <- append(lines, strsplit(plrGenerateContribSqlFilesText, split = "\n")[[1L]], after =  LineOfContribReturnPos -1L)

  writeLines("")
  writeLines("BEGIN addGenerateContribSqlFilesCode")
  writeLines("")
  writeLines(lines[LineOnlyBeginPos:(LineOfContribReturnPos + 7L + 1L + 1L)])
  writeLines("")
  writeLines("END   addGenerateContribSqlFilesCode")
  writeLines("")

  return(lines)

}

# 3 - part of "sub GenerateContribSqlFiles" - add - else 'plr'
Mkvcbuild.pm.Lines <- addGenerateContribSqlFilesCode(Mkvcbuild.pm.Lines)



cat(file = MkvcbuildPathFile, Mkvcbuild.pm.Lines, sep = "\n")


vcregressPathFile <- paste0(postgresrcroot, "/src/tools/msvc/vcregress.pl")
vcregress.pl.Lines <- readLines(vcregressPathFile)

modifySubContribCheck <- function(lines) {

  # lines
  LineOnlyBeginPos   <- which(grepl("sub\\s+contribcheck", x = lines, perl = TRUE))
  LineAllHaveGlobPos <- which(grepl("foreach\\s+my\\s+[$]module\\s+\\(glob\\(", x = lines, perl = TRUE))
  # after BeginPos, first-found line
  LineOfGlobPos <- LineAllHaveGlobPos[head(which(LineOnlyBeginPos < LineAllHaveGlobPos),1L)]

  ModifyLineWorking <- lines[LineOfGlobPos]

  # within that line
  LastAsteriskPos <- tail(gregexpr("[*]", text = ModifyLineWorking, perl = TRUE)[[1L]],1L)

  ModifyLineWorking <- strsplit(ModifyLineWorking, split = "")[[1L]]
  # remove that asterisk
  ModifyLineWorking <- as.list(ModifyLineWorking)
  ModifyLineWorking[LastAsteriskPos] <- NULL
  ModifyLineWorking <- unlist(ModifyLineWorking)
  ModifyLineWorking <- paste0(ModifyLineWorking, collapse = "")

  # insert into the line at the old-asterisk position
  ModifyLineWorking <- paste0(append(strsplit(ModifyLineWorking, split = "")[[1L]], "plr", after = LastAsteriskPos - 1L), collapse = "")
  lines[LineOfGlobPos] <- ModifyLineWorking

  writeLines("")
  writeLines("BEGIN modifySubContribCheck ")
  writeLines("")
  writeLines(lines[LineOnlyBeginPos:LineOfGlobPos])
  writeLines("")
  writeLines("END   modifySubContribCheck ")
  writeLines("")

  return(lines)

}

# 4 - part of sub contribcheck - reduce concern to only 'plr'
vcregress.pl.Lines <- modifySubContribCheck(vcregress.pl.Lines)


cat(file = vcregressPathFile, vcregress.pl.Lines, sep = "\n")